Created
July 9, 2017 14:06
-
-
Save ettorerizza/e6691986bce9f1d8d7b20929d05df11c to your computer and use it in GitHub Desktop.
Jython naive method to detect names of belgian municipalities in OpenRefine based on a gazeeter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.path.append(r'D:\jython2.7.0\Lib\site-packages') | |
from unidecode import unidecode | |
#TEST | |
value = "carette leuven" | |
with open(r"C:\Users\Boulot\Desktop\communes.tsv", 'r', encoding="utf8") as f: | |
lieux = [unidecode(name.strip().lower().replace("-", " ")) for name in f] | |
valeurs = "".join(unidecode(c.lower()) for c in value).strip().split(' ') | |
liste = [] | |
joint_locations = ["le", "la", "les", "lez", "saint", "s", "t"] | |
for i, tokens in enumerate(valeurs): | |
try: | |
if tokens in lieux: | |
liste.append(tokens) | |
elif tokens in joint_locations: | |
tokens = tokens + " " + valeurs[i+1] | |
elif valeurs[i+1] in joint_locations: | |
tokens = tokens + " " + valeurs[i+1] + " " + valeurs[i+2] | |
if tokens in lieux: | |
liste.append(tokens) | |
except IndexError: | |
pass | |
liste = set(liste) | |
print("||".join(liste)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment