Spaces:
Configuration error
Configuration error
| import requests | |
| def corpus_score(entity: str) -> int: | |
| """ | |
| 1. Attempt to fetch a Wikipedia page: | |
| URL = https://en.wikipedia.org/wiki/{entity.replace(' ', '_')} | |
| If status_code == 200, count occurrences of 'entity' on that page. | |
| Score = min(hits * 10, 100). | |
| 2. Otherwise (404 or exception), fallback heuristic: | |
| score = min(len(entity) * 2, 100). | |
| """ | |
| wiki_url = f"https://en.wikipedia.org/wiki/{entity.replace(' ', '_')}" | |
| try: | |
| resp = requests.get(wiki_url, timeout=5) | |
| if resp.status_code == 200: | |
| text = resp.text.lower() | |
| hits = text.count(entity.lower()) | |
| return min(hits * 10, 100) | |
| except Exception: | |
| pass | |
| return min(len(entity) * 2, 100) | |
| def corpus_recommendation(entity: str, score: int) -> str: | |
| if score < 50: | |
| return ( | |
| "No dedicated Wikipedia page found or low mention count. " | |
| "Consider creating a Wikipedia page or getting mentions on authoritative .edu/.gov sites." | |
| ) | |
| return "Corpus presence is good. Consider maintaining and expanding authoritative mentions." | |