rocky250 commited on
Commit
d869d6c
·
verified ·
1 Parent(s): 7f69713

Update analyzer.py

Browse files
Files changed (1) hide show
  1. analyzer.py +9 -9
analyzer.py CHANGED
@@ -303,7 +303,7 @@ def _load_svm(filename: str, stream_name: str) -> bool:
303
  # Validate
304
  if hasattr(obj, "predict") or hasattr(obj, "decision_function") or hasattr(obj, "predict_proba"):
305
  _svm_pipelines[stream_name] = obj
306
- logger.info(" SVM loaded: %s → %s", stream_name, type(obj).__name__)
307
  return True
308
 
309
  logger.warning("Object for %s has no sklearn API — type=%s", stream_name, type(obj).__name__)
@@ -666,7 +666,7 @@ def detect_misinformation(
666
  + (f" ({_load_error})" if _load_error else "")
667
  )
668
 
669
- label = " Potential Misinformation" if score >= 0.5 else "Appears Credible"
670
 
671
  # Strip internal 'source' key from modality dicts (not expected by charts)
672
  clean_modality = {
@@ -733,7 +733,7 @@ def analyze_sentiment_batch(
733
  vs = vader.polarity_scores(text)
734
  c = vs["compound"]
735
  results.append({
736
- "label": "POSITIVE" if c >= 0.05 else ("NEGATIVE" if c <= -0.05 else "NEUTRAL"),
737
  "score": abs(c),
738
  "compound": c,
739
  })
@@ -762,8 +762,8 @@ def _simple_lexicon_sentiment(texts: List[str]) -> List[Dict]:
762
  for text in texts:
763
  words = set(text.lower().split())
764
  p = len(words & pos); n = len(words & neg)
765
- if p > n: out.append({"label": "POSITIVE", "score": 0.7, "compound": 0.5})
766
- elif n > p: out.append({"label": "NEGATIVE", "score": 0.7, "compound": -0.5})
767
  else: out.append({"label": "NEUTRAL", "score": 0.5, "compound": 0.0})
768
  return out
769
 
@@ -776,8 +776,8 @@ def sentiment_summary(results: List[Dict]) -> Dict:
776
  total = len(results)
777
  avg = float(np.mean([r.get("compound", 0.0) for r in results]))
778
  return {
779
- "POSITIVE": counts.get("POSITIVE", 0),
780
- "NEGATIVE": counts.get("NEGATIVE", 0),
781
  "NEUTRAL": counts.get("NEUTRAL", 0),
782
  "total": total,
783
  "avg_compound": round(avg, 3),
@@ -822,6 +822,6 @@ def sentiment_weighted_keywords(
822
  for text, sent in zip(texts, sentiment_results):
823
  tokens = [t for t in re.findall(r"[a-zA-Z]{3,}", text.lower()) if t not in STOPWORDS]
824
  weight = sent.get("score", 0.5)
825
- if sent["label"] == "POSITIVE": pos_freq.update({t: weight for t in tokens})
826
- elif sent["label"] == "NEGATIVE": neg_freq.update({t: weight for t in tokens})
827
  return pos_freq.most_common(top_n), neg_freq.most_common(top_n)
 
303
  # Validate
304
  if hasattr(obj, "predict") or hasattr(obj, "decision_function") or hasattr(obj, "predict_proba"):
305
  _svm_pipelines[stream_name] = obj
306
+ logger.info(" SVM loaded: %s → %s", stream_name, type(obj).__name__)
307
  return True
308
 
309
  logger.warning("Object for %s has no sklearn API — type=%s", stream_name, type(obj).__name__)
 
666
  + (f" ({_load_error})" if _load_error else "")
667
  )
668
 
669
+ label = " Potential Misinformation" if score >= 0.5 else "Appears Credible"
670
 
671
  # Strip internal 'source' key from modality dicts (not expected by charts)
672
  clean_modality = {
 
733
  vs = vader.polarity_scores(text)
734
  c = vs["compound"]
735
  results.append({
736
+ "label": "POSITIVELY ENGAGEMENT" if c >= 0.05 else ("NEGATIVELY ENGAGEMENT" if c <= -0.05 else "NEUTRAL"),
737
  "score": abs(c),
738
  "compound": c,
739
  })
 
762
  for text in texts:
763
  words = set(text.lower().split())
764
  p = len(words & pos); n = len(words & neg)
765
+ if p > n: out.append({"label": "POSITIVELY ENGAGEMENT", "score": 0.7, "compound": 0.5})
766
+ elif n > p: out.append({"label": "NEGATIVE ENGAGEMENT", "score": 0.7, "compound": -0.5})
767
  else: out.append({"label": "NEUTRAL", "score": 0.5, "compound": 0.0})
768
  return out
769
 
 
776
  total = len(results)
777
  avg = float(np.mean([r.get("compound", 0.0) for r in results]))
778
  return {
779
+ "POSITIVELY ENGAGEMENT": counts.get("POSITIVE", 0),
780
+ "NEGATIVELY ENGAGEMENT": counts.get("NEGATIVE", 0),
781
  "NEUTRAL": counts.get("NEUTRAL", 0),
782
  "total": total,
783
  "avg_compound": round(avg, 3),
 
822
  for text, sent in zip(texts, sentiment_results):
823
  tokens = [t for t in re.findall(r"[a-zA-Z]{3,}", text.lower()) if t not in STOPWORDS]
824
  weight = sent.get("score", 0.5)
825
+ if sent["label"] == "POSITIVELY ENGAGEMENT": pos_freq.update({t: weight for t in tokens})
826
+ elif sent["label"] == "NEGATIVELY ENGAGEMENT": neg_freq.update({t: weight for t in tokens})
827
  return pos_freq.most_common(top_n), neg_freq.most_common(top_n)