chore: collapse multi-line argument definitions into single lines across multiple modules
This commit is contained in:
@@ -169,9 +169,7 @@ class FactExtractor:
|
||||
sentence_count = len(re.split(r"[.!?]", text))
|
||||
|
||||
urls = re.findall(r"https?://[^\s]+", text)
|
||||
email_addresses = re.findall(
|
||||
r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b", text
|
||||
)
|
||||
email_addresses = re.findall(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b", text)
|
||||
dates = re.findall(
|
||||
r"\b\d{1,2}[-/]\d{1,2}[-/]\d{2,4}\b|\b\d{4}[-/]\d{1,2}[-/]\d{1,2}\b", text
|
||||
)
|
||||
|
||||
@@ -38,8 +38,7 @@ class SemanticIndex:
|
||||
self.idf_scores = {token: 1.0 for token in token_doc_count}
|
||||
else:
|
||||
self.idf_scores = {
|
||||
token: math.log(doc_count / count)
|
||||
for token, count in token_doc_count.items()
|
||||
token: math.log(doc_count / count) for token, count in token_doc_count.items()
|
||||
}
|
||||
|
||||
def add_document(self, doc_id: str, text: str):
|
||||
@@ -51,8 +50,7 @@ class SemanticIndex:
|
||||
|
||||
tf_scores = self._compute_tf(tokens)
|
||||
self.doc_vectors[doc_id] = {
|
||||
token: tf_scores.get(token, 0) * self.idf_scores.get(token, 0)
|
||||
for token in tokens
|
||||
token: tf_scores.get(token, 0) * self.idf_scores.get(token, 0) for token in tokens
|
||||
}
|
||||
|
||||
def remove_document(self, doc_id: str):
|
||||
@@ -67,8 +65,7 @@ class SemanticIndex:
|
||||
query_tf = self._compute_tf(query_tokens)
|
||||
|
||||
query_vector = {
|
||||
token: query_tf.get(token, 0) * self.idf_scores.get(token, 0)
|
||||
for token in query_tokens
|
||||
token: query_tf.get(token, 0) * self.idf_scores.get(token, 0) for token in query_tokens
|
||||
}
|
||||
|
||||
scores = []
|
||||
@@ -79,9 +76,7 @@ class SemanticIndex:
|
||||
scores.sort(key=lambda x: x[1], reverse=True)
|
||||
return scores[:top_k]
|
||||
|
||||
def _cosine_similarity(
|
||||
self, vec1: Dict[str, float], vec2: Dict[str, float]
|
||||
) -> float:
|
||||
def _cosine_similarity(self, vec1: Dict[str, float], vec2: Dict[str, float]) -> float:
|
||||
dot_product = sum(
|
||||
vec1.get(token, 0) * vec2.get(token, 0) for token in set(vec1) | set(vec2)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user