简体   繁体   English

我可以使用 spacy 在字符串中识别“疑问词”(谁、如何、何时……)吗?

[英]Can i identify “Question words”(who, how, when…) in a string using spacy?

I have a string我有一个字符串

a = "Hello my name is Amar. How can I help you?"
doc = nlp(a)
for tok in doc: 
    print(tok.text, "-->",tok.dep_,"-->", tok.pos_)

This code is printing all text, dependency and pos of string.此代码正在打印字符串的所有文本、依赖项和位置。 I want to identify question word "How" in string.我想在字符串中识别问题词“How”。

If you mean to find a token(s) with tok.dep_ == 'advmod' and tok.pos_ == 'ADV' then use如果您的意思是使用tok.dep_ == 'advmod'tok.pos_ == 'ADV'查找令牌,请使用

[tok.text for tok in doc if tok.dep_ == 'advmod' and tok.pos_ == 'ADV']

This prints ['How'] .这将打印['How']

Wouldn't it be easier to stick to the basics for this?坚持这个基础不是更容易吗?

a = "Hello my name is Amar. How can I help you?"
Space = a.find(" ")
Q= a[:Space]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM