Wiki › Paper

Knowledge graph construction from unstructured data

Paper · library · 2025 · Key work

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

  1. Preprocessing cleans the input text.
  2. 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.
  3. 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.
  4. Graph building adds every entity as a node and every relation as a labelled, directed edge in a NetworkX DiGraph.
  5. 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

python
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:

See also

In the knowledge graph

KG-from-text paper and the 16 things it is linked to. Open any dot for its page, or explore it in the full graph.

When
2023202420252026
Feb 2025 · 2 commits

As data

Everything on this page is read from triples in the knowledge graph. These are the 31 it states about KG-from-text paper, and 4 more its ontology implies; the console runs SPARQL over the whole graph, here in your browser.

Download
@prefix id: <https://ask.chaipat.cc/id/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix cj: <https://ask.chaipat.cc/ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

id:KGFromText
    a cj:Paper ;
    rdfs:label "Knowledge graph construction from unstructured data" ;
    cj:shortLabel "KG-from-text paper" ;
    cj:context id:AcademicOutput ;
    cj:uses id:KnowledgeGraphs ,
            id:Python ,
            id:spaCy ,
            id:NetworkX ,
            id:NLP ;
    cj:description "Pipeline that builds knowledge graphs from unstructured text: entity and relation extraction with spaCy, graph construction with NetworkX, export to edge lists, adjacency matrices and GraphML." ;
    cj:featured true ;
    cj:repository "https://github.com/AppleBoiy/text2kgraph"^^xsd:anyURI ;
    cj:firstCommit "2025-02-07"^^xsd:date ;
    cj:lastCommit "2025-02-07"^^xsd:date ;
    cj:commitCount 2 ;
    cj:kind "library" ;
    cj:license "MIT" ;
    cj:theme id:ThemeOntology , id:ThemeML ;
    cj:tier 1 ;
    cj:keyRank 7 ;
    cj:handles id:GraphMLFormat , id:JSONFormat ;
    cj:mentions id:HealthRec ,
                id:OWL ,
                id:RoleJAIST ,
                id:SPARQL ,
                id:SemanticExtraction ;
    cj:article "https://ask.chaipat.cc/wiki/KGFromText"^^xsd:anyURI ;
    cj:activeIn id:Y2025 ;
    cj:activity _:b87 .