解析自然语言处理(NLP)中的句子

时间:2015-04-21 16:08:51

标签: machine-learning artificial-intelligence

由于我是机器学习的初学者,我很困惑地解析给定的句子。 “我在河的左边。” 尝试了很多,但真的无法得到确切的解决方案。

1 个答案:

答案 0 :(得分:2)

可以使用不同的语言解析器,但这取决于您的要求。看一下这个开始

  1. http://www.nltk.org/howto/parse.html
  2. http://nlp.stanford.edu/software/lex-parser.shtml
  3. Google sentence parser,您将获得大名单

    以下是stanford解析器的结果:

    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))))))