是否可以在NLTK中使用Stanford Parser?(我不是在谈论斯坦福POS.)
我正在使用斯坦福命名实体识别器http://nlp.stanford.edu/software/CRF-NER.shtml,它工作正常.这是
List<List<CoreLabel>> out = classifier.classify(text);
for (List<CoreLabel> sentence : out) {
for (CoreLabel word : sentence) {
if (!StringUtils.equals(word.get(AnswerAnnotation.class), "O")) {
namedEntities.add(word.word().trim());
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,我发现的问题是识别姓名和姓氏.如果识别器遇到"Joe Smith",它将分别返回"Joe"和"Smith".我真的希望将"乔·史密斯"作为一个词来回归.
这可以通过识别器通过配置来实现吗?到目前为止,我在javadoc中找不到任何东西.
谢谢!
我一直在玩NLTK工具包.我经常遇到这个问题并在网上寻找解决方案,但我无处可寻.所以我在这里提出我的问题.
很多时候,NER不会将连续的NNP标记为一个NE.我认为编辑NER以使用RegexpTagger也可以提高NER.
例:
输入:
巴拉克奥巴马是一个伟大的人.
输出:
树('S',[树('PERSON',[('Barack','NNP')]),树('组织',[('奥巴马','NNP')]),('是', 'VBZ'),('a','DT'),('great','JJ'),('person','NN'),('.','.')])
在哪里
输入:
前副总统迪克·切尼告诉保守派电台主持人劳拉·英格拉汉姆,他"很荣幸"在任期间与达斯维德相提并论.
输出:
树('S',[('前','JJ'),('副','NNP'),('总统','NNP'),树('NE',[('Dick',' NNP'),('切尼','NNP')]),('告诉','VBD'),('保守','JJ'),('收音机','NN'),('主持人' ,'NN'),树('NE',[('Laura','NNP'),('Ingraham','NNP')]),('that','IN'),('他', 'PRP'),('
', ''),('是','VBD'),('荣幸','VBN'),('''',''''),('to','''' ),('be','VB'),('比较','VBN'),('到','TO'),树('NE',[('Darth','NNP'),( 'Vader','NNP')]),('while','IN'),('in','IN'),('office','NN'),('.','.') ])
在这里,副总统/ NNP,总统/ NNP(迪克/ NNP,切尼/ NNP)被正确提取.
所以我认为如果首先使用nltk.ne_chunk然后如果两个连续的树是NNP,那么两者都很有可能引用一个实体.
任何建议都将非常感激.我正在寻找我的方法中的缺陷.
谢谢.
给出一个输入句子,它有BIO块标签:
[('什么','B-NP'),('是','B-VP'),(''','B-NP'),(''airspeed','I-NP'),( 'of','B-PP'),('an','B-NP'),('unladen','I-NP'),('swallow','I-NP'),('? ','O')]
我需要提取出相关的短语,例如,如果我想提取'NP',我需要提取包含B-NP和的元组的片段I-NP.
[OUT]:
[('What', '0'), ('the airspeed', '2-3'), ('an unladen swallow', '5-6-7')]
Run Code Online (Sandbox Code Playgroud)
(注意:提取元组中的数字代表令牌索引.)
我尝试使用以下代码解压缩它:
def extract_chunks(tagged_sent, chunk_type):
current_chunk = []
current_chunk_position = []
for idx, word_pos in enumerate(tagged_sent):
word, pos = word_pos
if '-'+chunk_type in pos: # Append the word to the current_chunk.
current_chunk.append((word))
current_chunk_position.append((idx))
else:
if current_chunk: # Flush the full chunk when out of an NP.
_chunk_str = ' '.join(current_chunk)
_chunk_pos_str = '-'.join(map(str, current_chunk_position))
yield _chunk_str, _chunk_pos_str …Run Code Online (Sandbox Code Playgroud) 我有一句话,我需要单独识别人名:
例如:
sentence = "Larry Page is an American business magnate and computer scientist who is the co-founder of Google, alongside Sergey Brin"
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码来识别NER.
from nltk import word_tokenize, pos_tag, ne_chunk
print(ne_chunk(pos_tag(word_tokenize(sentence))))
Run Code Online (Sandbox Code Playgroud)
我收到的输出是:
(S
(PERSON Larry/NNP)
(ORGANIZATION Page/NNP)
is/VBZ
an/DT
(GPE American/JJ)
business/NN
magnate/NN
and/CC
computer/NN
scientist/NN
who/WP
is/VBZ
the/DT
co-founder/NN
of/IN
(GPE Google/NNP)
,/,
alongside/RB
(PERSON Sergey/NNP Brin/NNP))
Run Code Online (Sandbox Code Playgroud)
我想提取所有人名,例如
Larry Page
Sergey Brin
Run Code Online (Sandbox Code Playgroud)
为了达到这个目的,我对此链接进行了审核并尝试了这一点.
from nltk.tag.stanford import StanfordNERTagger
st = StanfordNERTagger('/usr/share/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz','/usr/share/stanford-ner/stanford-ner.jar')
Run Code Online (Sandbox Code Playgroud)
但是我继续得到这个错误:
LookupError: Could not find stanford-ner.jar jar …Run Code Online (Sandbox Code Playgroud)