Skip to content

Instantly share code, notes, and snippets.

@drzippie
Created May 24, 2019 08:47
Show Gist options
  • Save drzippie/af4993c476ee1430ca70f4180edb7c5e to your computer and use it in GitHub Desktop.
Save drzippie/af4993c476ee1430ca70f4180edb7c5e to your computer and use it in GitHub Desktop.
Basic NER Service using MITIE

curl -d @sample_request.txt -X POST https://ner.morcego.net/ner

response:

[{"tag": "ORGANIZATION", "score": 0.40190129560515164, "label": "Furnival Barristers"}, {"tag": "PERSON", "score": 1.0128972145423198, "label": "Edith Oliv\u00e9 Bocanegra"}, {"tag": "LOCATION", "score": 0.9171091771615874, "label": "Panam\u00e1"}, {"tag": "PERSON", "score": 0.3877786881212515, "label": "Mossack & Fonseca"}, {"tag": "LOCATION", "score": 1.0092007968591041, "label": "Espa\u00f1a"}]% ➜ ~

text=La+presidenta+formal+de+la+sociedad+instrumental+Furnival+Barristers+fue+desde+su+inicio+Edith+Oliv%C3%A9+Bocanegra%2C+una+fiduciaria+presente+en+el+caso+de+los+papeles+de+Panam%C3%A1%2C+documentaci%C3%B3n+proveniente+del+despacho+Mossack+%26+Fonseca%2C+uno+de+los+m%C3%A1s+importantes+del+mundo+especializados+en+ocultar+patrimonios+a+trav%C3%A9s+de+para%C3%ADsos+fiscales.+Entre+su+red+de+clientes+cont%C3%B3+con+numerosos+millonarios+afincados+en+Espa%C3%B1a+que+recurr%C3%ADan+a+sus+servicios+para+esconder+su+dinero+al+fisco+de+nuestro+pa%C3%ADs.%0A%0A%0A
#coding=utf-8
import subprocess
from bottle import run, post, request, response, get, route
import sys, os
# Make sure you put the mitielib folder into the python search path. There are
# a lot of ways to do this, here we do it programmatically with the following
# two statements:
parent = os.path.dirname(os.path.realpath(__file__))
sys.path.append(parent + '/MITIE/mitielib')
from mitie import *
from collections import defaultdict
print "loading NER model..."
ner = named_entity_extractor('MITIE/MITIE-models/spanish/ner_model.dat')
from json import dumps
@post('/ner')
def postner():
print "request"
text = request.forms.get('text')
print text
tokens = tokenize( text )
print dumps( tokens )
entities = ner.extract_entities(tokens)
response.content_type = 'application/json'
res = []
for e in entities:
range = e[0]
tag = e[1]
score = e[2]
res.append( {'tag': tag , 'score': score , 'label': " ".join(tokens[i] for i in range) })
print dumps(res)
return dumps(res)
run(host='localhost', port=8081, debug=True)
La presidenta formal de la sociedad instrumental Furnival Barristers fue desde su inicio Edith Olivé Bocanegra, una fiduciaria presente en el caso de los papeles de Panamá, documentación proveniente del despacho Mossack & Fonseca, uno de los más importantes del mundo especializados en ocultar patrimonios a través de paraísos fiscales. Entre su red de clientes contó con numerosos millonarios afincados en España que recurrían a sus servicios para esconder su dinero al fisco de nuestro país.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment