Named Entity Recognition for NLTK in Python. Identifying the NE

前端 未结 5 490
野趣味
野趣味 2021-01-30 18:25

I need to classify words into their parts of speech. Like a verb, a noun, an adverb etc.. I used the

nltk.word_tokenize() #to identify word in a sentence 
nltk.         


        
相关标签:
5条回答
  • 2021-01-30 18:42

    This will work

    for sent in chunked_sentences:
      for chunk in sent:
        if hasattr(chunk, "label"):
            print(chunk.label())
    
    0 讨论(0)
  • 2021-01-30 18:48

    Below is my code:

    chunks = ne_chunk(postags, binary=True)
    for c in chunks:
      if hasattr(c, 'node'):
        myNE.append(' '.join(i[0] for i in c.leaves()))
    
    0 讨论(0)
  • 2021-01-30 18:55

    I agree with bdk

    sent3[2].node

    O/P - 'NE'

    I think there is no function in nltk to do it.Above solution will work but for reference you can check here

    for looping problem you can do :-

     for i in range(len(sent3)):
         if "NE" in str(sent3[i]):
              print sent3[i].node
    

    I have executed this in nltk and it works fine..

    0 讨论(0)
  • 2021-01-30 19:02

    This answer may be off base, and in which case I'll delete it, as I don't have NLTK installed here to try it, but I think you can just do:

       >>> sent3[2].node
       'NE'
    

    sent3[2][0] returns the first child of the tree, not the node itself

    Edit: I tried this when I got home, and it does indeed work.

    0 讨论(0)
  • 2021-01-30 19:02

    Now sent3[2].node is outdated.

    use sent3[2].label() instead

    0 讨论(0)
提交回复
热议问题