stanford openie python
1.0.0
최신 CORENLP 라이브러리 4.5.3 (2023-03-10 기준)을 지원합니다.
Open Information Extraction (Open IE)은 일반 텍스트에서 구조화 된 관계 트리플의 추출을 의미하며, 따라서 이러한 관계에 대한 스키마를 미리 지정할 필요가 없습니다. 예를 들어, 버락 오바마는 하와이에서 태어 났으며 열린 도메인 관계에 해당하는 트리플 (Barack Obama; was born in; Hawaii) 을 만들어 냈습니다. Corenlp는 논문에 설명 된 개방형 IE 시스템의 Java 구현입니다.
자세한 내용은 여기를 참조하십시오. Openie 라이브러리는 영어로만 구입할 수 있습니다.
Python3 및 Java (JRE)를 설치해야합니다. Java는 Corenlp 라이브러리에서 사용됩니다.
Java가 먼저 설치되어 있는지 확인하십시오.
java -version그런 다음 lib를 설치하십시오.
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 ( '[...]' )예상 출력
|- {'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'}
graph.png 에서 GraphViz Dot을 생성합니다.

참고 : GraphViz가 미리 설치되어 있는지 확인하십시오. dot 명령을 실행하여 이것이 사실인지 확인하십시오. 그렇지 않은 경우 Ubuntu에서 실행중인 경우 sudo apt-get install graphviz 실행하십시오. MacOS에서는 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}},
}