prof-freakenstein commited on
Commit
de21c1d
·
verified ·
1 Parent(s): 7f39da3

Upload folder using huggingface_hub

Browse files
SIH_Problem_Statements.json ADDED
The diff for this file is too large to render. See raw diff
 
SIH_Problem_Statements_structured.json ADDED
The diff for this file is too large to render. See raw diff
 
converter.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import re
4
+
5
+ def parse_description(description_text):
6
+ """
7
+ Parses the description text into a structured dictionary.
8
+ """
9
+ # Headers to look for in the description text.
10
+ # The order is important for splitting.
11
+ headers = [
12
+ "Background",
13
+ "Problem Description",
14
+ "Description",
15
+ "Impact / Why this problem needs to be solved",
16
+ "Impact",
17
+ "Expected Solution",
18
+ "Expected Outcomes",
19
+ "Relevant Stakeholders / Beneficiaries",
20
+ "Supporting Data",
21
+ "Objective",
22
+ "Technical Scope",
23
+ "Data Acquisition & Sampling",
24
+ "Data Processing & Analysis",
25
+ "Output & Storage",
26
+ "Key Performance Parameters",
27
+ "Eligibility",
28
+ "Evaluation Criteria",
29
+ "Deliverables",
30
+ "Conclusion",
31
+ "Innovative Features",
32
+ "Key Features",
33
+ "Additional Features",
34
+ "Digital Tourist ID Generation Platform",
35
+ "Mobile Application for Tourists",
36
+ "AI-Based Anomaly Detection",
37
+ "Tourism Department & Police Dashboard",
38
+ "IoT Integration (Optional)",
39
+ "Multilingual Support",
40
+ "Data Privacy & Security"
41
+ ]
42
+
43
+ # Create a regex pattern to split the text by the headers.
44
+ # The pattern looks for a header at the beginning of a line.
45
+ pattern = r'^\s*(' + '|'.join(re.escape(h) for h in headers) + r')\s*$'
46
+
47
+ # Split the text by the headers
48
+ parts = re.split(pattern, description_text, flags=re.MULTILINE)
49
+
50
+ details = {}
51
+ # The first part is the introduction if it's not a header
52
+ if parts[0].strip():
53
+ details['introduction'] = parts[0].strip()
54
+
55
+ # The rest of the parts are pairs of (header, content)
56
+ it = iter(parts[1:])
57
+ for header in it:
58
+ content = next(it, "").strip()
59
+ if header and content:
60
+ # Normalize header to be used as a json key
61
+ key = header.strip().lower().replace(' ', '_').replace('/', '_').replace('(', '').replace(')', '')
62
+ details[key] = content
63
+
64
+ # If details is empty, it means no headers were found.
65
+ # In this case, the whole text is the description.
66
+ if not details:
67
+ return {'full_text': description_text.strip()}
68
+
69
+ return details
70
+
71
+ def convert_csv_to_json(csv_file_path, json_file_path):
72
+ """
73
+ Converts a CSV file to a structured JSON file.
74
+ """
75
+ problems = []
76
+ with open(csv_file_path, mode='r', encoding='utf-8') as csv_file:
77
+ # Use DictReader to read CSV rows as dictionaries
78
+ csv_reader = csv.DictReader(csv_file)
79
+
80
+ for row in csv_reader:
81
+ # Clean up keys from the CSV header
82
+ cleaned_row = {key.strip().replace(' ', '_').replace('.', ''): value for key, value in row.items()}
83
+
84
+ problem_data = {
85
+ 's_no': int(cleaned_row.get('SNo', 0)),
86
+ 'organization': cleaned_row.get('Organization', ''),
87
+ 'title': cleaned_row.get('Problem_Statement_Title', ''),
88
+ 'category': cleaned_row.get('Category', ''),
89
+ 'ps_number': cleaned_row.get('PS_Number', ''),
90
+ 'submitted_ideas_count': int(cleaned_row.get('Submitted_Ideas_Count', 0)),
91
+ 'theme': cleaned_row.get('Theme', ''),
92
+ 'details': parse_description(cleaned_row.get('Problem_Description', ''))
93
+ }
94
+ problems.append(problem_data)
95
+
96
+ with open(json_file_path, mode='w', encoding='utf-8') as json_file:
97
+ json.dump({"problems": problems}, json_file, indent=2)
98
+
99
+ if __name__ == '__main__':
100
+ csv_input_file = 'SIH_Problem_Statements.csv'
101
+ json_output_file = 'SIH_Problem_Statements_structured.json'
102
+
103
+ convert_csv_to_json(csv_input_file, json_output_file)
104
+
105
+ print(f"Successfully converted '{csv_input_file}' to '{json_output_file}'")
simple_converter.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+
4
+ def convert_csv_to_json_simple(csv_file_path, json_file_path):
5
+ """
6
+ Converts a CSV file to a JSON file, keeping the problem description as a single text block.
7
+ """
8
+ problems = []
9
+ with open(csv_file_path, mode='r', encoding='utf-8') as csv_file:
10
+ csv_reader = csv.DictReader(csv_file)
11
+
12
+ for row in csv_reader:
13
+ # Clean up keys from the CSV header
14
+ cleaned_row = {key.strip().replace(' ', '_').replace('.', ''): value for key, value in row.items()}
15
+
16
+ problem_data = {
17
+ 's_no': int(cleaned_row.get('SNo', 0)),
18
+ 'organization': cleaned_row.get('Organization', ''),
19
+ 'title': cleaned_row.get('Problem_Statement_Title', ''),
20
+ 'category': cleaned_row.get('Category', ''),
21
+ 'ps_number': cleaned_row.get('PS_Number', ''),
22
+ 'submitted_ideas_count': int(cleaned_row.get('Submitted_Ideas_Count', 0)),
23
+ 'theme': cleaned_row.get('Theme', ''),
24
+ 'problem_description': cleaned_row.get('Problem_Description', '').strip()
25
+ }
26
+ problems.append(problem_data)
27
+
28
+ with open(json_file_path, mode='w', encoding='utf-8') as json_file:
29
+ json.dump({"problems": problems}, json_file, indent=4)
30
+
31
+ if __name__ == '__main__':
32
+ csv_input_file = 'SIH_Problem_Statements.csv'
33
+ json_output_file = 'SIH_Problem_Statements.json'
34
+
35
+ convert_csv_to_json_simple(csv_input_file, json_output_file)
36
+
37
+ print(f"Successfully converted '{csv_input_file}' to '{json_output_file}'")