from nltk.chunk.util import tagstr2tree
from nltk import word_tokenize, pos_tag
text = "John Rose Center is very beautiful place and i want to go there with Barbara Palvin. Also there are stores like Adidas ,Nike ,Reebok Center."
tagged_text = pos_tag(text.split())
grammar = "NP:{<NNP>+}"
cp = nltk.RegexpParser(grammar)
result = cp.parse(tagged_text)
print(result)
산출:
(S
(NP John/NNP Rose/NNP Center/NNP)
is/VBZ
very/RB
beautiful/JJ
place/NN
and/CC
i/NN
want/VBP
to/TO
go/VB
there/RB
with/IN
(NP Barbara/NNP Palvin./NNP)
Also/RB
there/EX
are/VBP
stores/NNS
like/IN
(NP Adidas/NNP ,Nike/NNP ,Reebok/NNP Center./NNP))
청킹에 사용하는 문법은 nnp 태그에서만 작동하지만 단어가 쉼표로 순차적 인 경우에도 동일한 줄에 표시됩니다.
(S
(NP John/NNP Rose/NNP Center/NNP)
is/VBZ
very/RB
beautiful/JJ
place/NN
and/CC
i/NN
want/VBP
to/TO
go/VB
there/RB
with/IN
(NP Barbara/NNP Palvin./NNP)
Also/RB
there/EX
are/VBP
stores/NNS
like/IN
(NP Adidas,/NNP)
(NP Nike,/NNP)
(NP Reebok/NNP Center./NNP))
"grammar ="에 무엇을 써야합니까? 아니면 위에서 쓴 것처럼 출력을 편집 할 수 있습니까? 당신이 볼 수 있듯이 명명 된 엔터티 프로젝트에 대한 고유 명사 만 구문 분석 할 수 있습니다.
word_tokenize(string)
대신 사용 string.split()
:
>>> import nltk
>>> from nltk.chunk.util import tagstr2tree
>>> from nltk import word_tokenize, pos_tag
>>> text = "John Rose Center is very beautiful place and i want to go there with Barbara Palvin. Also there are stores like Adidas ,Nike ,Reebok Center."
>>> tagged_text = pos_tag(word_tokenize(text))
>>>
>>> grammar = "NP:{<NNP>+}"
>>>
>>> cp = nltk.RegexpParser(grammar)
>>> result = cp.parse(tagged_text)
>>>
>>> print(result)
(S
(NP John/NNP Rose/NNP Center/NNP)
is/VBZ
very/RB
beautiful/JJ
place/NN
and/CC
i/NN
want/VBP
to/TO
go/VB
there/RB
with/IN
(NP Barbara/NNP Palvin/NNP)
./.
Also/RB
there/EX
are/VBP
stores/NNS
like/IN
(NP Adidas/NNP)
,/,
(NP Nike/NNP)
,/,
(NP Reebok/NNP Center/NNP)
./.)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다