Unterstützt die neueste CoreLP-Bibliothek 4.5.3 (ab 2023-03-10).
Open Information Extraction (Open IE) bezieht sich auf die Extraktion strukturierter Verhältnisse aus dem einfachen Text, so dass das Schema für diese Beziehungen nicht im Voraus angegeben werden muss. Zum Beispiel wurde Barack Obama in Hawaii geboren, ein Triple (Barack Obama; was born in; Hawaii) erzeugt, was der offenen Domain -Beziehung entspricht "wurde in" geboren in ". Corenlp ist eine Java -Implementierung eines offenen IE -Systems, wie im Papier beschrieben:
Weitere Informationen finden Sie hier. Die Openie -Bibliothek ist nur in Englisch erhältlich.
Sie brauchen Python3 und Java (JRE) installiert. Java wird in der CoreLP -Bibliothek verwendet.
Stellen Sie sicher, dass Java zuerst installiert ist.
java -versionDann die lib installieren.
pip install stanford_openie from openie import StanfordOpenIE
# https://stanfordnlp.github.io/CoreNLP/openie.html#api
# Default value of openie.affinity_probability_cap was 1/3.
properties = {
'openie.affinity_probability_cap' : 2 / 3 ,
}
with StanfordOpenIE ( properties = properties ) as client :
text = 'Barack Obama was born in Hawaii. Richard Manning wrote this sentence.'
print ( 'Text: %s.' % text )
for triple in client . annotate ( text ):
print ( '|-' , triple )
graph_image = 'graph.png'
client . generate_graphviz_graph ( text , graph_image )
print ( 'Graph generated: %s.' % graph_image )
with open ( 'corpus/pg6130.txt' , encoding = 'utf8' ) as r :
corpus = r . read (). replace ( ' n ' , ' ' ). replace ( ' r ' , '' )
triples_corpus = client . annotate ( corpus [ 0 : 5000 ])
print ( 'Corpus: %s [...].' % corpus [ 0 : 80 ])
print ( 'Found %s triples in the corpus.' % len ( triples_corpus ))
for triple in triples_corpus [: 3 ]:
print ( '|-' , triple )
print ( '[...]' )Erwartete Ausgabe
|- {'subject': 'Barack Obama', 'relation': 'was', 'object': 'born'}
|- {'subject': 'Barack Obama', 'relation': 'was born in', 'object': 'Hawaii'}
|- {'subject': 'Richard Manning', 'relation': 'wrote', 'object': 'sentence'}
Graph generated: graph.png.
Corpus: According to this document, the city of Cumae in Ćolia, was, at an early period [...].
Found 1664 triples in the corpus.
|- {'subject': 'city', 'relation': 'is in', 'object': 'Ćolia'}
|- {'subject': 'Menapolus', 'relation': 'son of', 'object': 'Ithagenes'}
|- {'subject': 'Menapolus', 'relation': 'was Among', 'object': 'immigrants'}
Es erzeugt einen Graphviz -Punkt in graph.png :

Hinweis : Stellen Sie sicher, dass GraphViz vorher installiert ist. Versuchen Sie, den dot -Befehl auszuführen, um festzustellen, ob dies der Fall ist. Wenn nicht, führen Sie sudo apt-get install graphviz wenn Sie auf Ubuntu ausgeführt werden. Auf macOS ist es brew install graphviz .
@misc{StanfordOpenIEWrapper,
author = {Philippe Remy},
title = {Python wrapper for Stanford OpenIE},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {url{https://github.com/philipperemy/Stanford-OpenIE-Python}},
}