This commit is contained in:
hsafaei
2025-02-15 13:23:43 +03:30
parent dabf86ba7d
commit 16538e618e
+14 -11
View File
@@ -30,7 +30,9 @@ def recerciveMatch(startIndex , i, tokens, dict, result) :
def find_organizations(text):
global result_dict
words = text.split()
text_normal = TextNormalizer()
#words = text.split()
words = text_normal.split_words()
results = []
i = 0
while i < len(words):
@@ -44,28 +46,28 @@ def find_organizations(text):
return results
def create_nested_dictionary(lines):
def create_nested_dictionary(lines, nested_dict={}):
text_normal = TextNormalizer()
nested_dict = {}
#nested_dict = {}
for line in lines:
line = text_normal.normalize_qanon(line)
parts = line.split("=")
#words = re.findall(r'\b\w+\b', parts[0])
words = text_normal.split_words(parts[0])
current_level = nested_dict
dict_current_level = nested_dict
for word in words:
if word not in current_level:
current_level[word] = {}
current_level = current_level[word]
if word not in dict_current_level:
dict_current_level[word] = {}
dict_current_level = dict_current_level[word]
tag = parts[1] if len(parts)> 1 else ''
if '=' in current_level :
if current_level['='] != tag :
if '=' in dict_current_level :
if dict_current_level['='] != tag :
# دو عنوان دقیقا مشابه هم با دو تگ مختلف
current_level['='] = current_level['='] + ',' + tag
dict_current_level['='] = dict_current_level['='] + ',' + tag
else:
current_level['='] = tag
dict_current_level['='] = tag
return nested_dict
@@ -80,6 +82,7 @@ except FileNotFoundError:
print("Error: ORG+.txt file not found.")
exit()
lines = text.strip().split('\n')
result_dict = create_nested_dictionary(lines)