Python Forum
[nltk] Relations Extractor - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: [nltk] Relations Extractor (/thread-19421.html)



[nltk] Relations Extractor - constantin01 - Jun-27-2019

Hello

I use nltk.sem.relextract to extract relations in text. I have a problem.

What I do:

1. Tools:

import nltk
import re 
from nltk.chunk import ne_chunk_sents
from nltk.sem import relextract
2. Take simple sentence and prepare it

sent = "China is in Asia"
sent = chunker(nltk.pos_tag(sent.split())) // tokenizing, tagging, chunking in NEs
sent
Tree('S', [Tree('GPE', [('China', 'NNP')]), ('in', 'IN'), Tree('GPE', [('Asia', 'NNP')])])
3. Pattern:

IN = re.compile (r'.*\bin\b(?!\b.+ing)')
4. Processing:

for rel in  nltk.sem.extract_rels('GPE','GPE',sent,corpus='ace',pattern=IN):
   print(nltk.sem.relextract.rtuple(rel))
[]
Fail! What is wrong?


RE: [nltk] Relations Extractor - scidam - Jun-28-2019

It seems that your question is related with the following issue. Nevertheless, your problem isn't fully reproducible, because the chunker function isn't defined.


RE: [nltk] Relations Extractor - constantin01 - Jun-28-2019

chunker it is just nltk.ne_chunk()

I have read this post before I created this thread, however it is does not work. I do all how it is explained in "Natural Language Processing with Python" (p. 284-290).


RE: [nltk] Relations Extractor - constantin01 - Jun-28-2019

I have solved the problem with editing of code of package nltk. Now it works.

But still I wonder why I should do it in order to receive a result with such simple expample as "China is in Asia"? Why the author does not fix it?