【发布时间】:2020-07-04 18:10:42
【问题描述】:
我是 python 新手,我正在尝试为给定单词之前的单词提取词性 (Stanford CoreNLP)。对于文本 = "انسان يحضر طعامه باستخدام الخبز الابيض وبجانبه قطة سوداء؟"
这是我的代码
for i in nouns:
pattren ="\w+(?=\s*"+i+"[^/])"
re1 = re.search(pattren , text)
if(re1):
for tag in tagger.tag(text.split()): #POS tag extractor
if re1[0] in tag[1]:
for specific in tag[1].split():
if re1[0] in specific:
print("The Noun " + i + ":-")
print(specific)
nouns 是一个数组,包含文本 ['انسان', 'طعام', 'استخدام', 'جانب', 'قطة'] 中的所有 NN 我尝试使用正则表达式提取之前的单词。
输出是:
The Noun طعام:-
يحضر/VBP
The Noun استخدام:-
ب/IN
The Noun استخدام:-
الخبز/DTNN
The Noun استخدام:-
الابيض/DTJJ
The Noun استخدام:-
ب/IN
The Noun استخدام:-
جانب/NN
The Noun جانب:-
ب/IN
The Noun جانب:-
الخبز/DTNN
The Noun جانب:-
الابيض/DTJJ
The Noun جانب:-
ب/IN
The Noun جانب:-
جانب/NN
The Noun قطة:-
ه/PRP$
The Noun قطة:-
ه/PRP$
有重复的词,我真的无法进行这个问题。
【问题讨论】:
标签: python stanford-nlp part-of-speech