我正在解析包含此文本的表单
'1a。国家美国'
哪个没有被检测为 GPE
from nltk import pos_tag, ne_chunk
from nltk.tokenize import SpaceTokenizer
tokenizer = SpaceTokenizer()
toks = tokenizer.tokenize(cioms_)
pos = pos_tag(toks)
chunked_nes = ne_chunk(pos)
nes = [' '.join(map(lambda x: x[0], ne.leaves())) for ne in chunked_nes if isinstance(ne, nltk.tree.Tree)]
chunked_nes
Out[83]: Tree('S', [(u'1a.', 'CD'), Tree('ORGANIZATION', [(u'Country', 'NNP'), (u'United', 'NNP'), (u'States', 'NNPS')])])
Run Code Online (Sandbox Code Playgroud)
但是当我将其修剪为“美国国家”时,它会被检测到
Out[81]: Tree('S', [Tree('PERSON', [(u'Country', 'NNP')]), Tree('GPE', [(u'United', 'NNP'), (u'States', 'NNPS')])])
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我正在使用此代码,要求用户上传文件,我希望将其读入数据框。然后,该数据框应在页面上显示为输出。
为了达到目的,我应该在退货中写些什么?
from flask import Flask, request, jsonify
import flask_excel as excel
import pandas as pd
app=Flask(__name__)
@app.route("/upload", methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
return jsonify({"result": request.get_array(field_name='file')})
return '''
<!doctype html>
<title>Upload an excel file</title>
<h1>Excel file upload (csv, tsv, csvz, tsvz only)</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file><input type=submit value=Upload>
</form>
'''
@app.route("/export", methods=['GET'])
def export_records():
return
if __name__ == "__main__":
app.run()
Run Code Online (Sandbox Code Playgroud) 假设我有这个功能
>>>a=3
>>>def num(a):
a=5
return a
>>>num(a)
5
>>>a
3
Run Code Online (Sandbox Code Playgroud)
不变的价值.
现在考虑这段代码:
>>> index = [1]
>>> def change(a):
a.append(2)
return a
>>> change(index)
>>> index
>>> [1,2]
Run Code Online (Sandbox Code Playgroud)
在此代码中,索引的值会发生变化.有人可以解释这两个代码中发生的事情.根据第一个代码,索引的值不应该改变(即应该保持索引= [1]).
大家好我知道这段代码的作用:
1.]我的第一个问题
x = 4
y = x
Run Code Online (Sandbox Code Playgroud)
但是这个呢.为什么同样的地址甚至是这种情况?
x = 4
y = 4
id(x)
12345678
id(y)
12345678
Run Code Online (Sandbox Code Playgroud)
2.]我的第二个问题
x = 42
y = x
x = x + 1
print x # Prints 43
print y # Prints 42
x = [1, 2, 3]
y = x
x[0] = 4
print x # Prints [4, 2, 3]
print y # Prints [4, 2, 3]
Run Code Online (Sandbox Code Playgroud)
但为什么在名单的情况,都x与y得到了由命令突变在一起x[0] = 4.
在这样的行为中,列表有什么不同?
是什么让他们表现得像这样?
最重要的是,这种行为的好处是什么?
为什么不能列出,变量,元组具有彼此的所有属性?
所以我去了nltk并看到了这段代码
entities = nltk.chunk.ne_chunk(tagged)
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,你们如何知道何时使用哪种方法以及方法调用的顺序是什么?
我看到的另一个奇怪的代码是
nltk.corpus.words.words('en')
Run Code Online (Sandbox Code Playgroud)
现在怎么会一个人翻出来.words,然后.words?为什么我们在这里称之为字方法两次与我怎么知道什么时候我需要调用一个方法两次?
我刚刚完成了"Udacity - Intro.到CS(使用Python)",但这个"nltk"变得太混乱了.请帮助,几天以来一直在努力获得所有这些的逻辑.