An Open Information Extraction System mainly designed for German.
pip install turcy
python -m spacy download de_core_news_lg-3.0.0 --direct
Can be applied to other languages as well, however some extrawork is necessary as no patterns for english are shipped. Therefore, you would have to build your own patterns first. For building patterns, a `pattern_builder module is available.
- Load the German Language Model from spaCy.
- Add turCy to the nlp-Pipeline.
- Pass the document to the pipeline.
- Iterate over the sentences in the document and access the triples in each sentence.
def example():
nlp = spacy.load("de_core_news_lg", exclude=["ner"])
nlp.max_length = 2096700
turcy.add_to_pipe(nlp) # apply/use current patterns in list
pipeline_params = {"attach_triple2sentence": {"pattern_list": "small"}}
doc = nlp("Nürnberg ist eine Stadt in Deutschland.", component_cfg=pipeline_params)
for sent in doc.sents:
print(sent)
for triple in sent._.triples:
(subj, pred, obj) = triple["triple"]
print(f"subject:'{subj}', predicate:'{pred}' and object: '{obj}'")