Jun-27-2019, 07:35 PM
Hello
I use nltk.sem.relextract to extract relations in text. I have a problem.
What I do:
1. Tools:
2. Take simple sentence and prepare it
3. Pattern:
4. Processing:
Fail! What is wrong?
I use nltk.sem.relextract to extract relations in text. I have a problem.
What I do:
1. Tools:
1 2 3 4 |
import nltk import re from nltk.chunk import ne_chunk_sents from nltk.sem import relextract |
1 2 3 4 |
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' )])]) |
1 |
IN = re. compile (r '.*\bin\b(?!\b.+ing)' ) |
1 2 3 |
for rel in nltk.sem.extract_rels( 'GPE' , 'GPE' ,sent,corpus = 'ace' ,pattern = IN): print (nltk.sem.relextract.rtuple(rel)) [] |