-
Notifications
You must be signed in to change notification settings - Fork 3
/
findlocation.py
39 lines (28 loc) · 960 Bytes
/
findlocation.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
#!/usr/bin/python
from nltk.tag.stanford import StanfordNERTagger
import operator
import re
fileList = open("fileList.txt", "r")
fileName = fileList.readlines()
fileList.close()
outfile = open("country.txt", "w")
english_nertagger = StanfordNERTagger('/Users/stellamberv/Documents/stanford-ner-2014-08-27/classifiers/english.muc.7class.distsim.crf.ser.gz','/Users/stellamberv/Documents/stanford-ner-2014-08-27/stanford-ner.jar')
for i in range(len(fileName)):
oneFile = open(fileName[i].rstrip(), "r")
oneFileContent = oneFile.read()
oneFile.close()
str_split = english_nertagger.tag(oneFileContent.split())
j = 0
country = ""
while j < len(str_split):
if str_split[j][1] == u'LOCATION':
country = country + " " + (str_split[j][0]).encode("utf-8")
j = j + 1
else:
j = j + 1
if len(country) == 0:
continue
else:
outfile.write(country + '\n')
country = ""
outfile.close()