相关疑难解决方法(0)

使用python中的bing或google API获取位置坐标

这是我的问题.我有一个示例文本文件,我通过爬行各种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)

python google-maps nltk coordinates bing-maps

3
推荐指数
2
解决办法
6806
查看次数

标签 统计

bing-maps ×1

coordinates ×1

google-maps ×1

nltk ×1

python ×1