-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameTagging.py
More file actions
46 lines (30 loc) · 1.19 KB
/
Copy pathNameTagging.py
File metadata and controls
46 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
from pprint import pprint
from imdb import IMDb
from difflib import SequenceMatcher
# Util file for named entity recognition purposes
# Gets all named entities of type PER in the given review text
def name_tagging(review_text):
# Make request to ELISA information extraction API
request = "http://blender02.cs.rpi.edu:3300/elisa_ie/entity_discovery_and_linking/en?input_format=plain%20text&output_format=KnowledgeGraph"
r = requests.post(request, data = review_text)
# print(r.url)
# pprint(r.json())
name_tagger = r.json()
entity_id_PER = set()
for entity in name_tagger["entity"]:
if entity["entity_type"] == "PER":
entity_id_PER.add(entity["entity_id"])
named_entities = set()
for entity in name_tagger["entity_mention"]:
if entity["mention_id"] not in entity_id_PER:
named_entities.add(entity["mention_head"])
return named_entities
# Uses IMDbPy to determine whether an entity name is actually an actor
def is_actor(entity_name):
# TODO: could compile all top results, compute coherence between results
ia = IMDb()
for person in ia.search_person(entity_name):
if SequenceMatcher(None, person['name'], entity_name).ratio() >= 0.8:
return True
return False