Update func.py
Browse files
func.py
CHANGED
@@ -65,30 +65,29 @@ def analyze_sentiment(text):
|
|
65 |
except Exception:
|
66 |
return "Unknown"
|
67 |
|
68 |
-
def extract_org_entities(text):
|
|
|
|
|
|
|
|
|
69 |
try:
|
70 |
-
|
71 |
-
|
|
|
72 |
for ent in entities:
|
73 |
if ent["entity_group"] == "ORG":
|
74 |
-
|
75 |
-
if
|
76 |
-
|
77 |
-
if len(
|
78 |
break
|
79 |
-
return
|
80 |
except Exception:
|
81 |
return []
|
82 |
|
83 |
# ----------- Helper Functions for Imports -----------
|
84 |
def get_sentiment_pipeline():
|
85 |
-
"""
|
86 |
-
Return the pre-initialized sentiment-analysis pipeline.
|
87 |
-
"""
|
88 |
return sentiment_pipeline
|
89 |
|
90 |
def get_ner_pipeline():
|
91 |
-
"""
|
92 |
-
Return the pre-initialized NER pipeline.
|
93 |
-
"""
|
94 |
return ner_pipeline
|
|
|
65 |
except Exception:
|
66 |
return "Unknown"
|
67 |
|
68 |
+
def extract_org_entities(text, ner_pipe=None):
|
69 |
+
"""
|
70 |
+
- extract_org_entities(text)
|
71 |
+
- extract_org_entities(text, some_pipeline)
|
72 |
+
"""
|
73 |
try:
|
74 |
+
pipe = ner_pipe or ner_pipeline
|
75 |
+
entities = pipe(text)
|
76 |
+
orgs = []
|
77 |
for ent in entities:
|
78 |
if ent["entity_group"] == "ORG":
|
79 |
+
w = ent["word"].replace("##", "").strip().upper()
|
80 |
+
if w not in orgs:
|
81 |
+
orgs.append(w)
|
82 |
+
if len(orgs) >= 5:
|
83 |
break
|
84 |
+
return orgs
|
85 |
except Exception:
|
86 |
return []
|
87 |
|
88 |
# ----------- Helper Functions for Imports -----------
|
89 |
def get_sentiment_pipeline():
|
|
|
|
|
|
|
90 |
return sentiment_pipeline
|
91 |
|
92 |
def get_ner_pipeline():
|
|
|
|
|
|
|
93 |
return ner_pipeline
|