Knowledge graph construction from unstructured data
text2kgraph is a small Python package that sketches a pipeline from unstructured text to a knowledge graph. It finds entities in text with spaCy, builds a directed graph with NetworkX, and exports the graph in several standard formats. He wrote it in early 2025 to accompany written work on knowledge-graph construction, just before his ontology-engineering research at JAIST.
Pipeline
- Preprocessing cleans the input text.
- Entity extraction runs spaCy's English model (
en_core_web_sm) and keeps each named entity with its type, such as PERSON, DATE or WORK_OF_ART. - Relation extraction is the step that turns entities into facts. In this version it is a placeholder: it returns one fixed triple per sentence instead of real relations.
- Graph building adds every entity as a node and every relation as a labelled, directed edge in a NetworkX
DiGraph. - Export writes the graph as:
- node-link JSON;
- a tab-separated edge list (
source → target → relation); - an adjacency matrix, with a separate file of node names;
- GraphML, for tools such as Gephi and yEd.
Example
text = "Albert Einstein developed the theory of relativity in 1915."
entities = extract_entities(clean_text(text))
relationships = extract_relationships(text)
graph = build_graph(entities, relationships)
save_as_graphml(graph, "graph.graphml")
Status
The repository is an early scaffold rather than a finished extractor. The entity extraction, graph building and every exporter work, but relation extraction still needs to be implemented, for example with dependency parsing or a trained relation model. The later work went in that direction:
- At JAIST, his semantic extraction pipeline extracted structured facts and checked them with SPARQL.
- His ontology-augmented health recommendation project used a hand-built OWL ontology instead of extracting one from text.