小编Ans*_*kur的帖子

使用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
查看次数

解析XML文件以获取所需数据并将其存储在Python中的mongodb数据库中

我有一个XML文件,如下所示:

XML文件

我想从这个文件中获取所有事件的以下信息:

在类别活动下:

  • 开始日期
  • 结束日期
  • 标题

在类别场地下:

  • 地址
  • 地址2/
  • 纬度
  • 经度
  • 名称
  • 邮政编码

然后将此信息存储在mongodb数据库中.我在解析方面没有太多经验.有人可以帮我这个!谢谢 !

python xml mongodb xml-parsing pymongo

3
推荐指数
1
解决办法
5530
查看次数