在自然语言处理 (NLP) 中解析句子
Parsing the sentence in natural language processing (NLP)
由于我是机器学习的初学者,我对解析给定的句子感到困惑。
"I am in the left side of river."
尝试了很多,但真的无法得到确切的解决方案。
可以使用不同的语言解析器,但这取决于您的要求。查看其中一些以开始使用
Googlesentence parser
,你会得到大名单
这是斯坦福解析器的结果:
NLP> I am in the left side of river.
Sentence #1 (9 tokens):
I am in the left side of river.
[Text=I CharacterOffsetBegin=0 CharacterOffsetEnd=1 PartOfSpeech=PRP Lemma=I NamedEntityTag=O] [Text=am CharacterOffsetBegin=2 CharacterOffsetEnd=4 PartOfSpeech=VBP Lemma=be NamedEntityTag=O] [Text=in CharacterOffsetBegin=5 CharacterOffsetEnd=7 PartOfSpeech=IN Lemma=in NamedEntityTag=O] [Text=the CharacterOffsetBegin=8 CharacterOffsetEnd=11 PartOfSpeech=DT Lemma=the NamedEntityTag=O] [Text=left CharacterOffsetBegin=12 CharacterOffsetEnd=16 PartOfSpeech=JJ Lemma=left NamedEntityTag=O] [Text=side CharacterOffsetBegin=17 CharacterOffsetEnd=21 PartOfSpeech=NN Lemma=side NamedEntityTag=O] [Text=of CharacterOffsetBegin=22 CharacterOffsetEnd=24 PartOfSpeech=IN Lemma=of NamedEntityTag=O] [Text=river CharacterOffsetBegin=25 CharacterOffsetEnd=30 PartOfSpeech=NN Lemma=river NamedEntityTag=O] [Text=. CharacterOffsetBegin=30 CharacterOffsetEnd=31 PartOfSpeech=. Lemma=. NamedEntityTag=O]
(ROOT
(S
(NP (PRP I))
(VP (VBP am)
(PP (IN in)
(NP
(NP (DT the) (JJ left) (NN side))
(PP (IN of)
(NP (NN river))))))
(. .)))
root(ROOT-0, am-2)
nsubj(am-2, I-1)
det(side-6, the-4)
amod(side-6, left-5)
prep_in(am-2, side-6)
prep_of(side-6, river-8)
nltk 解析器:
>>> nltk.parse.chart.demo(3, print_times=False, trace=0,
... sent='I saw John with a dog', numparses=2)
* Sentence:
I saw John with a dog
['I', 'saw', 'John', 'with', 'a', 'dog']
* Strategy: Bottom-up left-corner
Nr edges in chart: 36
(S
(NP I)
(VP (VP (Verb saw) (NP John)) (PP with (NP (Det a) (Noun dog)))))
(S
(NP I)
(VP (Verb saw) (NP (NP John) (PP with (NP (Det a) (Noun dog))))))
由于我是机器学习的初学者,我对解析给定的句子感到困惑。 "I am in the left side of river." 尝试了很多,但真的无法得到确切的解决方案。
可以使用不同的语言解析器,但这取决于您的要求。查看其中一些以开始使用
Googlesentence parser
,你会得到大名单
这是斯坦福解析器的结果:
NLP> I am in the left side of river.
Sentence #1 (9 tokens):
I am in the left side of river.
[Text=I CharacterOffsetBegin=0 CharacterOffsetEnd=1 PartOfSpeech=PRP Lemma=I NamedEntityTag=O] [Text=am CharacterOffsetBegin=2 CharacterOffsetEnd=4 PartOfSpeech=VBP Lemma=be NamedEntityTag=O] [Text=in CharacterOffsetBegin=5 CharacterOffsetEnd=7 PartOfSpeech=IN Lemma=in NamedEntityTag=O] [Text=the CharacterOffsetBegin=8 CharacterOffsetEnd=11 PartOfSpeech=DT Lemma=the NamedEntityTag=O] [Text=left CharacterOffsetBegin=12 CharacterOffsetEnd=16 PartOfSpeech=JJ Lemma=left NamedEntityTag=O] [Text=side CharacterOffsetBegin=17 CharacterOffsetEnd=21 PartOfSpeech=NN Lemma=side NamedEntityTag=O] [Text=of CharacterOffsetBegin=22 CharacterOffsetEnd=24 PartOfSpeech=IN Lemma=of NamedEntityTag=O] [Text=river CharacterOffsetBegin=25 CharacterOffsetEnd=30 PartOfSpeech=NN Lemma=river NamedEntityTag=O] [Text=. CharacterOffsetBegin=30 CharacterOffsetEnd=31 PartOfSpeech=. Lemma=. NamedEntityTag=O]
(ROOT
(S
(NP (PRP I))
(VP (VBP am)
(PP (IN in)
(NP
(NP (DT the) (JJ left) (NN side))
(PP (IN of)
(NP (NN river))))))
(. .)))
root(ROOT-0, am-2)
nsubj(am-2, I-1)
det(side-6, the-4)
amod(side-6, left-5)
prep_in(am-2, side-6)
prep_of(side-6, river-8)
nltk 解析器:
>>> nltk.parse.chart.demo(3, print_times=False, trace=0,
... sent='I saw John with a dog', numparses=2)
* Sentence:
I saw John with a dog
['I', 'saw', 'John', 'with', 'a', 'dog']
* Strategy: Bottom-up left-corner
Nr edges in chart: 36
(S
(NP I)
(VP (VP (Verb saw) (NP John)) (PP with (NP (Det a) (Noun dog)))))
(S
(NP I)
(VP (Verb saw) (NP (NP John) (PP with (NP (Det a) (Noun dog))))))