这是我的问题.我有一个示例文本文件,我通过爬行各种html页面来存储文本数据.本文包含有关各种事件及其时间和地点的信息.我想获取这些位置的坐标.我不知道如何在python中做到这一点.我使用nltk来识别此示例文本中的命名实体.这是代码:
import nltk
with open('sample.txt', 'r') as f:
sample = f.read()
sentences = nltk.sent_tokenize(sample)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)
#print chunked_sentences
#print tokenized_sentences
#print tagged_sentences
def extract_entity_names(t):
entity_names = []
if hasattr(t, 'node') and t.node:
if t.node == 'NE':
entity_names.append(' '.join([child[0] for child in t]))
else:
for child in t:
entity_names.extend(extract_entity_names(child))
return entity_names
entity_names = []
for tree in chunked_sentences:
# Print results per sentence
# print …Run Code Online (Sandbox Code Playgroud) 我有一个XML文件,如下所示:
我想从这个文件中获取所有事件的以下信息:
在类别活动下:
在类别场地下:
然后将此信息存储在mongodb数据库中.我在解析方面没有太多经验.有人可以帮我这个!谢谢 !
python ×2
bing-maps ×1
coordinates ×1
google-maps ×1
mongodb ×1
nltk ×1
pymongo ×1
xml ×1
xml-parsing ×1