def reverb_wrapper(text, stop=None):
"""
Function-wrapper for ReVerb binary. Extracts relations
found in text.
Input:
- text: str,
a piece of text or sentence
- stop: list,
list of stopwords to remove from the relations
Output:
- total: list,
list of lists. Each inner list contains one relation in the form
[subject, predicate, object]
"""
total = []
for sent in sent_tokenize(text):
cmd = 'echo "' + sent + '"' "| ./reverb -q | tr '\t' '\n' | cat -n"
reverb_dir = settings['load']['path']['reverb']
result = runProcess(cmd, reverb_dir)
# Extract relations from reverb output
result = result[-3:]
result = [row.split('\t')[1].strip('\n') for row in result]
# Remove common stopwords from relations
if stop:
result = [stopw_removal(res, stop) for res in result]
total.append(result)
# Remove empty relations
total = [t for t in total if t]
return total
评论列表
文章目录