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