spaCy is an open-source Python NLP library for turning text into structured linguistic data. Its pretrained pipelines support part-of-speech tagging, dependency parsing, text categorization, and named-entity recognition. section 5.3.1
A spaCy pipeline parses documents into sentences, tokens, linguistic labels, dependencies, phrases, and sometimes coreference information. Application code can then apply rules to those outputs—for example, mapping subjects, verbs, and objects into RDF triples for a knowledge graph. section 5.3.1
Common implementation patterns include:
- Extract relationships from sentence structure, then prune or merge noisy verb-based relationships. section 5.3.1
- Use Matcher patterns to collect noun and verb phrases for vocabulary, autocomplete, or semantic-search preparation. section 13.5.1
- Process corpora with nlp.pipe in parallel batches and filter concepts by frequency to reduce rare-term noise. section 13.5.1
From sentence to graph fact
For “Colin attends Riverside High School,” dependency and part-of-speech analysis can support the triple ("Colin", "attends", "Riverside High School"). Similar processing extracts facts such as ("Companies", "employ", "Data Scientists"). section 5.3.1
Listing 5.1 Extracting relationships and resolving co-references
def extract_relationships(text, lang_model, coref_model):
resolved_text = resolve_coreferences(text, coref_model) #1
sentences = get_sentences(resolved_text, lang_model) #2
return resolve_facts(sentences, lang_model) #3
text = """
Data Scientists build machine learning models. They also write code.
Companies employ Data Scientists.
Software Engineers also write code. Companies employ Software Engineers.
"""
lang_model = spacy.load("en_core_web_sm")
coref_model = spacy.load("en_coreference_web_trf") #4
graph = extract_relationships(text, lang_model, coref_model)
print(graph)
The pipeline resolves coreferences, obtains sentences from the language model, and resolves facts into graph-ready relationships. section 5.3.1




