-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbody2entities.py
33 lines (27 loc) · 918 Bytes
/
body2entities.py
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
#!/usr/bin/env python
import sys
"""
Initialize requirements for OpenCalais
"""
from calais import Calais
CALAIS_API_KEY = 'ed42bg3ku3g3k98kv9kee78s'
calais = Calais(CALAIS_API_KEY, submitter = "pagea1 tester")
def body2entities(body):
"""
Given an article (STRING body), use the Open Calais named entity recognizer to return
all entities therein.
"""
names, companies, orgs, terms = [], [], [], []
result = calais.analyze(body)
for entity in result.entities:
if (entity["_type"] == "Person"):
names.append(entity["name"])
if (entity["_type"] == "Company"):
companies.append(entity["name"])
if (entity["_type"] == "Organization"):
orgs.append(entity["name"])
if (entity["_type"] == "IndustryTerm"):
terms.append(entity["name"])
return names, companies, orgs, terms
if __name__ == '__main__':
pass