LinkLinkWu commited on
Commit
8d9b985
·
verified ·
1 Parent(s): dd3df57

Update func.py

Browse files
Files changed (1) hide show
  1. func.py +13 -14
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
- entities = ner_pipeline(text)
71
- org_entities = []
 
72
  for ent in entities:
73
  if ent["entity_group"] == "ORG":
74
- clean_word = ent["word"].replace("##", "").strip()
75
- if clean_word.upper() not in org_entities:
76
- org_entities.append(clean_word.upper())
77
- if len(org_entities) >= 5:
78
  break
79
- return org_entities
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