Spaces:
Sleeping
Sleeping
Edvin Behdadijd
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,37 +62,43 @@ def compare_skills(skill_1, skill_2):
|
|
| 62 |
|
| 63 |
return score, common_skill
|
| 64 |
|
| 65 |
-
def extract_ner_info(text, nlp):
|
| 66 |
ner_results = nlp(text)
|
| 67 |
full_name = ''
|
| 68 |
loc = ''
|
| 69 |
age = None
|
| 70 |
-
# جمعآوری قطعات B-pers و I-pers برای تشکیل نام کامل
|
| 71 |
i = 0
|
| 72 |
while i < len(ner_results):
|
| 73 |
-
if ner_results[i]['entity'] == 'B-pers':
|
| 74 |
if full_name: # اگر قبلاً نامی پیدا کردهایم، فاصله اضافه کن
|
| 75 |
full_name += ' '
|
| 76 |
full_name += ner_results[i]['word']
|
|
|
|
|
|
|
| 77 |
for j in range(i + 1, len(ner_results)):
|
| 78 |
-
if ner_results[j]['entity']
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
else:
|
|
|
|
| 82 |
break
|
|
|
|
|
|
|
| 83 |
i += 1
|
| 84 |
# جمعآوری مکانها با امتیاز بالای ۸۰
|
| 85 |
for entity in ner_results:
|
| 86 |
-
if entity['entity']
|
| 87 |
if loc:
|
| 88 |
loc += ' '
|
| 89 |
loc += entity['word']
|
| 90 |
# استخراج سن از متن
|
| 91 |
age_match = re.search(r'سن\s*:\s*(\d+)', text)
|
| 92 |
-
if age_match:
|
| 93 |
-
age = int(age_match.group(1))
|
| 94 |
-
# استخراج سن از متن
|
| 95 |
-
age_match = re.search(r'سن\s*:\s*(\d+)', text)
|
| 96 |
if age_match:
|
| 97 |
age = int(age_match.group(1))
|
| 98 |
# بررسی امتیاز شباهت مکان
|
|
|
|
| 62 |
|
| 63 |
return score, common_skill
|
| 64 |
|
| 65 |
+
def extract_ner_info(text, nlp, fixed_loc):
|
| 66 |
ner_results = nlp(text)
|
| 67 |
full_name = ''
|
| 68 |
loc = ''
|
| 69 |
age = None
|
| 70 |
+
# جمعآوری قطعات B-pers و I-pers برای تشکیل نام کامل با شرط کاهش ۱۰ درصدی
|
| 71 |
i = 0
|
| 72 |
while i < len(ner_results):
|
| 73 |
+
if ner_results[i]['entity'] == 'B-pers' and ner_results[i]['score'] >= 0.80:
|
| 74 |
if full_name: # اگر قبلاً نامی پیدا کردهایم، فاصله اضافه کن
|
| 75 |
full_name += ' '
|
| 76 |
full_name += ner_results[i]['word']
|
| 77 |
+
current_score = ner_results[i]['score']
|
| 78 |
+
stop_adding = False # پرچم برای توقف بعد از اولین نام کامل
|
| 79 |
for j in range(i + 1, len(ner_results)):
|
| 80 |
+
if ner_results[j]['entity'] == 'I-pers' and ner_results[j]['score'] >= 0.80:
|
| 81 |
+
if ner_results[j]['score'] >= current_score * 0.90: # شرط کاهش ۱۰ درصدی
|
| 82 |
+
full_name += ner_results[j]['word'].replace('##', '')
|
| 83 |
+
current_score = ner_results[j]['score']
|
| 84 |
+
i = j # به موقعیت جدید برو
|
| 85 |
+
else:
|
| 86 |
+
stop_adding = True # توقف بعد از اولین نام کامل
|
| 87 |
+
break
|
| 88 |
else:
|
| 89 |
+
stop_adding = True # توقف بعد از اولین نام کامل
|
| 90 |
break
|
| 91 |
+
if stop_adding:
|
| 92 |
+
break # توقف بعد از اولین نام کامل
|
| 93 |
i += 1
|
| 94 |
# جمعآوری مکانها با امتیاز بالای ۸۰
|
| 95 |
for entity in ner_results:
|
| 96 |
+
if entity['entity'] in ['B-loc', 'I-loc'] and entity['score'] >= 0.80:
|
| 97 |
if loc:
|
| 98 |
loc += ' '
|
| 99 |
loc += entity['word']
|
| 100 |
# استخراج سن از متن
|
| 101 |
age_match = re.search(r'سن\s*:\s*(\d+)', text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
if age_match:
|
| 103 |
age = int(age_match.group(1))
|
| 104 |
# بررسی امتیاز شباهت مکان
|