LinkLinkWu commited on
Commit
e12e190
Β·
verified Β·
1 Parent(s): 8314677

Update func.py

Browse files
Files changed (1) hide show
  1. func.py +8 -9
func.py CHANGED
@@ -1,4 +1,3 @@
1
- ----------
2
  """
3
  * **Single** `analyze_sentiment` implementation – no more duplicates.
4
  * Returns **label string by default**, optional probability via `return_prob`.
@@ -73,9 +72,9 @@ def analyze_sentiment(
73
  text : str
74
  Input sentence (e.g. news headline).
75
  pipe : transformers.Pipeline, optional
76
- Custom sentiment pipeline; defaults to module‑level singleton.
77
  threshold : float, default 0.50
78
- Positive‑probability cut‑off.
79
  return_prob : bool, default False
80
  If *True*, returns ``(label, positive_probability)`` tuple;
81
  otherwise returns just the label string.
@@ -103,7 +102,7 @@ def analyze_sentiment(
103
 
104
 
105
  # ---------------------------------------------------------------------------
106
- # Web‑scraping helper (Finviz)
107
  # ---------------------------------------------------------------------------
108
 
109
  def fetch_news(ticker: str, max_items: int = 30) -> List[dict]:
@@ -146,13 +145,13 @@ def fetch_news(ticker: str, max_items: int = 30) -> List[dict]:
146
 
147
 
148
  # ---------------------------------------------------------------------------
149
- # Named‑entity extraction helper
150
  # ---------------------------------------------------------------------------
151
 
152
  def extract_org_entities(text: str, pipe=None, max_entities: int = 5) -> List[str]:
153
- """Extract *ORG* tokens (upper‑cased) from *text*.
154
 
155
- Returns at most *max_entities* unique ticker‑like strings suitable
156
  for Finviz / Yahoo queries.
157
  """
158
  try:
@@ -176,10 +175,10 @@ def extract_org_entities(text: str, pipe=None, max_entities: int = 5) -> List[st
176
  # ---------------------------------------------------------------------------
177
 
178
  def get_sentiment_pipeline():
179
- """Return the module‑level sentiment pipeline singleton."""
180
  return sentiment_pipeline
181
 
182
 
183
  def get_ner_pipeline():
184
- """Return the module‑level NER pipeline singleton."""
185
  return ner_pipeline
 
 
1
  """
2
  * **Single** `analyze_sentiment` implementation – no more duplicates.
3
  * Returns **label string by default**, optional probability via `return_prob`.
 
72
  text : str
73
  Input sentence (e.g. news headline).
74
  pipe : transformers.Pipeline, optional
75
+ Custom sentiment pipeline; defaults to module-level singleton.
76
  threshold : float, default 0.50
77
+ Positive-probability cut-off.
78
  return_prob : bool, default False
79
  If *True*, returns ``(label, positive_probability)`` tuple;
80
  otherwise returns just the label string.
 
102
 
103
 
104
  # ---------------------------------------------------------------------------
105
+ # Web-scraping helper (Finviz)
106
  # ---------------------------------------------------------------------------
107
 
108
  def fetch_news(ticker: str, max_items: int = 30) -> List[dict]:
 
145
 
146
 
147
  # ---------------------------------------------------------------------------
148
+ # Named-entity extraction helper
149
  # ---------------------------------------------------------------------------
150
 
151
  def extract_org_entities(text: str, pipe=None, max_entities: int = 5) -> List[str]:
152
+ """Extract *ORG* tokens (upper-cased) from *text*.
153
 
154
+ Returns at most *max_entities* unique ticker-like strings suitable
155
  for Finviz / Yahoo queries.
156
  """
157
  try:
 
175
  # ---------------------------------------------------------------------------
176
 
177
  def get_sentiment_pipeline():
178
+ """Return the module-level sentiment pipeline singleton."""
179
  return sentiment_pipeline
180
 
181
 
182
  def get_ner_pipeline():
183
+ """Return the module-level NER pipeline singleton."""
184
  return ner_pipeline