diff --git a/ner-tagger/v1/astroTagger/find-astro.py b/ner-tagger/v1/astroTagger/find-astro.py index 539ecc7..f63c249 100644 --- a/ner-tagger/v1/astroTagger/find-astro.py +++ b/ner-tagger/v1/astroTagger/find-astro.py @@ -37,61 +37,15 @@ sentS = sent.split(".") sentences = [Sentence(sentS[i]+".") for i in range(len(sentS))] tagger.predict(sentences) - for sentence in sentences: + label_lists = {"PL": PL,"TNQ": TNQ,"SNAT": SNAT,"OA": OA,"SSO": SSO,"EB": EB,"ET": ET,"NRA": NRA,"CST": CST,"GAL": GAL,"AST": AST,"ST": ST,"AS": AS,"SN": SN,"XPL": XPL,"SR": SR} + for sentence in sentences: for entity in sentence.get_spans('ner'): - if (entity.labels[0].value == "PL"): - if entity.text not in PL: - PL.append(entity.text) - if (entity.labels[0].value == "TNQ"): - if entity.text not in TNQ: - TNQ.append(entity.text) - if (entity.labels[0].value == "SNAT"): - if entity.text not in SNAT: - SNAT.append(entity.text) - if (entity.labels[0].value == "OA"): - if entity.text not in OA: - OA.append(entity.text) - if (entity.labels[0].value == "SSO"): - if entity.text not in SSO: - SSO.append(entity.text) - if (entity.labels[0].value == "EB"): - if entity.text not in EB: - EB.append(entity.text) - if (entity.labels[0].value == "ET"): - if entity.text not in ET: - ET.append(entity.text) - if (entity.labels[0].value == "NRA"): - if entity.text not in NRA: - NRA.append(entity.text) - if (entity.labels[0].value == "CST"): - if entity.text not in CST: - CST.append(entity.text) - if (entity.labels[0].value == "GAL"): - if entity.text not in GAL: - GAL.append(entity.text) - if (entity.labels[0].value == "AST"): - if entity.text not in AST: - AST.append(entity.text) - if (entity.labels[0].value == "ST"): - if entity.text not in ST: - ST.append(entity.text) - if (entity.labels[0].value == "AS"): - if entity.text not in AS: - AS.append(entity.text) - if (entity.labels[0].value == "SN"): - if entity.text not in SN: - SN.append(entity.text) - if (entity.labels[0].value == "XPL"): - if entity.text not in XPL: - XPL.append(entity.text) - if (entity.labels[0].value == "SR"): - if entity.text not in SR: - SR.append(entity.text) - - - + label_value = entity.labels[0].value + if entity.text not in label_lists.get(label_value, []): + label_lists[label_value].append(entity.text) + returnDic = {unidecode('Planète'):PL,unidecode('Trou noirs, quasars et apparentés'):TNQ,'Satellite naturel':SNAT,'Objets artificiels':OA,unidecode('Système solaire') :SSO,unidecode('Étoiles binaires (et pulsars)'):EB,unidecode('Étoiles'):ET,unidecode('Nébuleuse et région apparentés'):NRA,'Constellations':CST,'Galaxies et amas de galaxie':GAL,unidecode('Astèroïdes'):AST,unidecode('Satue hypotétique'):ST,'amas stellaires':AS,'supernovas':SN,unidecode('exoplanètes'):XPL,'sursaut radio, source radio, autres sursauts':SR} # ajouter unidecode - data['value'] = returnDic + data['value'] = {id:value for id, value in returnDic.items() if value != []} sys.stdout.write(json.dumps(data)) sys.stdout.write('\n') \ No newline at end of file