Fix bare except handlers in keyword_extractor.py #20
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple
|
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple
|
||||||
|
|
||||||
@@ -199,7 +202,8 @@ class KeywordExtractor:
|
|||||||
def _extract_yake_scores(self, text: str) -> Dict[str, float]:
|
def _extract_yake_scores(self, text: str) -> Dict[str, float]:
|
||||||
try:
|
try:
|
||||||
import yake
|
import yake
|
||||||
except Exception:
|
except ImportError:
|
||||||
|
logger.warning("yake not installed, skipping relevance scoring")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
text_token_count = len(text.split())
|
text_token_count = len(text.split())
|
||||||
@@ -208,7 +212,8 @@ class KeywordExtractor:
|
|||||||
try:
|
try:
|
||||||
extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.9, top=top_n)
|
extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.9, top=top_n)
|
||||||
phrase_scores = extractor.extract_keywords(text)
|
phrase_scores = extractor.extract_keywords(text)
|
||||||
except Exception:
|
except (ValueError, TypeError) as e:
|
||||||
|
logger.warning("YAKE extraction failed: %s", e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
token_scores: Dict[str, float] = {}
|
token_scores: Dict[str, float] = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user