reel-studio-2 / test_scoring.py
xvepkj's picture
Add footballia source
2980fd0
Raw
History Blame
1.07 kB
import json
import re
with open("goals.json") as f:
all_goals = json.load(f)
filters = ["2018 Champions League Quarter-final, Real Madrid vs Juventus, Allianz Stadium, April 3, 2018"]
scored_goals = []
for g in all_goals:
title_lower = g.get("title", "").lower()
desc_lower = g.get("description", "").lower()
score = 0
for filt in filters:
filt_words = [re.sub(r'[^\w]', '', w.lower()) for w in filt.split()]
filt_words = [w for w in filt_words if w and len(w) > 2] # ignore short words like 'vs' maybe? or keep them? Let's keep them.
filt_words = [re.sub(r'[^\w]', '', w.lower()) for w in filt.split()]
filt_words = [w for w in filt_words if w]
matches = sum(1 for w in filt_words if w in title_lower or w in desc_lower)
score += matches
if score > 0 or not filters:
scored_goals.append((score, g))
scored_goals.sort(key=lambda x: x[0], reverse=True)
for score, g in scored_goals[:5]:
print(f"Score {score}: {g['title']} | {g['description']}")