-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplotplaces.py
executable file
·48 lines (43 loc) · 1.34 KB
/
plotplaces.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
For a given MP:
download the text of their parliamentary statements from they work for you
extract entities using opencalais
plot them on a map
'''
import entities, parliament
import copy
def demo():
text = parliament.mptext()
places = entities.places_from_text(text)
placenames = [x['name'] for x in places]
print('places named by William Hague')
print('\n'.join(placenames))
def raw_placeinfo(mpid = '10251'):
mpcontext = {
'mp' : parliament.mpinfo(mpid)
}
speeches = parliament.mpspeeches(mpid)['rows'][2:6]
places = []
for speech in speeches:
speechcontext = copy.copy(mpcontext)
speechcontext['speech'] = speech
try:
return entities.places_from_text(speech['body'])
for place in newplaces:
placecontext = copy.copy(speechcontext)
placecontext.update(entities.placelocation(place))
places.append(placecontext)
except Exception:
raise
print('no entities')
'''
try:
for place in entities.places_from_text(speech['body']):
placecontext = copy.copy(speechcontext)
except RuntimeError: #Exception:
raise
print('no entities')
'''
return places
if __name__ == '__main__':
demo()