Spaces:
Runtime error
Runtime error
update
Browse files
src/similarity_model/similarity_engine.py
CHANGED
|
@@ -287,22 +287,38 @@ def find_similar_projects(
|
|
| 287 |
|
| 288 |
if len(existing_project) > 0:
|
| 289 |
|
| 290 |
-
|
| 291 |
|
| 292 |
-
|
|
|
|
| 293 |
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
final_features = merge_features(
|
| 299 |
-
title=title,
|
| 300 |
-
abstract=abstract,
|
| 301 |
-
description=description,
|
| 302 |
-
features=features,
|
| 303 |
-
auto_extract=auto_extract_features
|
| 304 |
-
)
|
| 305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
|
| 308 |
query_project = build_query_project(
|
|
@@ -384,6 +400,12 @@ def find_similar_projects(
|
|
| 384 |
ascending=False
|
| 385 |
).head(top_k).reset_index(drop=True)
|
| 386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
# add debug info
|
| 388 |
final_df["query_features_used"] = [
|
| 389 |
final_features
|
|
|
|
| 287 |
|
| 288 |
if len(existing_project) > 0:
|
| 289 |
|
| 290 |
+
logger.info("Exact title match found — returning originality = 0")
|
| 291 |
|
| 292 |
+
matched_row = existing_project.iloc[0]
|
| 293 |
+
stored_features = safe_feature_list(matched_row["features"])
|
| 294 |
|
| 295 |
+
return pd.DataFrame([{
|
| 296 |
+
"project_id": int(matched_row.name),
|
| 297 |
+
"project_title": matched_row["project_title"],
|
| 298 |
+
"semantic_score": 1.0,
|
| 299 |
+
"feature_score": 1.0,
|
| 300 |
+
"coverage": 1.0,
|
| 301 |
+
"hybrid_score": 1.0,
|
| 302 |
+
"originality_score": 0.0,
|
| 303 |
+
"confidence_score": 1.0,
|
| 304 |
+
"duplicate_risk": "Very High",
|
| 305 |
+
"shared_features_count": len(stored_features),
|
| 306 |
+
"matched_features": [{"feature_a": f, "feature_b": f, "score": 1.0} for f in stored_features],
|
| 307 |
+
"unique_query_features": [],
|
| 308 |
+
"unique_candidate_features": [],
|
| 309 |
+
"query_features_used": stored_features,
|
| 310 |
+
"query_clean_text": title
|
| 311 |
+
}])
|
| 312 |
|
| 313 |
+
logger.info("Extracting new features")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
+
final_features = merge_features(
|
| 316 |
+
title=title,
|
| 317 |
+
abstract=abstract,
|
| 318 |
+
description=description,
|
| 319 |
+
features=features,
|
| 320 |
+
auto_extract=auto_extract_features
|
| 321 |
+
)
|
| 322 |
|
| 323 |
|
| 324 |
query_project = build_query_project(
|
|
|
|
| 400 |
ascending=False
|
| 401 |
).head(top_k).reset_index(drop=True)
|
| 402 |
|
| 403 |
+
# Force originality = 0 for any near-duplicate (same content, different title)
|
| 404 |
+
final_df.loc[
|
| 405 |
+
final_df["hybrid_score"] >= 0.90,
|
| 406 |
+
"originality_score"
|
| 407 |
+
] = 0.0
|
| 408 |
+
|
| 409 |
# add debug info
|
| 410 |
final_df["query_features_used"] = [
|
| 411 |
final_features
|