Hello everyone, I need to load an existing knowled...
# nebula
o
Hello everyone, I need to load an existing knowledge graph (RDF) into nebula graph store. This is what the knowledge graph looks like https://github.com/anandkp92/relaxed-brick-queries/blob/main/Data%20-%20Brick%20models/acad.ttl. Does anyone know how can I do this?
b
You'd have to first convert the RDF ontology used by that dataset into a graph schema that you could define in Nebula Graph (as a Property Graph). You would then likely need to convert the Turtle files into CSV in order to import the data into Nebula. You may be able to use something like G2GML for this: https://g2gml.readthedocs.io/en/latest/contents/g2gml.html
👍 5
w
You could quickly start in a non-elegant way first to see how it goes with your use cases: map Subject, Predict, Object to a schema-less model.
(:Entity)-[:RELATIONSHIP]->(:Entity)
, where you put RELATIONSHIP.name as the Predicate, `Entity.name`as Subject& Object for instance:
Copy code
In [1]: import rdflib
   ...:
   ...: g = rdflib.Graph()
   ...: g.parse("acad.ttl", format="ttl")
Out[1]: <Graph identifier=N8879a2d625384bf89a1e40ea3ccba3ef (<class 'rdflib.graph.Graph'>)>

In [2]: for subj, pred, obj in g:
   ...:     print(f"Subject: {subj}, Predicate: {pred}, Object: {obj}")
   ...:
Subject: <http://buildsys.org/ontologies/ACAD#RM2375>, Predicate: <https://brickschema.org/schema/Brick#hasPart>, Object: <http://buildsys.org/ontologies/ACAD#RM2375_room>
Subject: <http://buildsys.org/ontologies/ACAD#ACAD.ZONE.AHU01.RM2368_MIX.Zone_Air_Temp>, Predicate: <http://www.w3.org/2000/01/rdf-schema#label>, Object: ACAD.ZONE.AHU01.RM2368_MIX.Zone Air Temp
Copy code
"RM2375" - "hasPart"-> "RM2375_room"
And "http://buildsys.org/ontologies/ACAD#RM2375" is the vertex id, "RM2375" is the property
name
With that ETL processing, you could leverage nebula-importer/nebula-studio to ingest the csv files to NebulaGraph with ease. The schema for reference would be:
Copy code
CREATE SPACE IF NOT EXISTS relaxed_brick (vid_type=FIXED_STRING(256));

-- wait for space creation ---
USE relaxed_brick;
CREATE TAG IF NOT EXISTS Entity(name string);
CREATE EDGE IF NOT EXISTS RELATIONSHIP(name int);
-- wait for DDL done ---
CREATE TAG INDEX Entity_index on Entity(name(128));
CREATE EDGE INDEX IF NOT EXISTS RELATIONSHIP_index on RELATIONSHIP(name(128));
@Bill H g2g is indeed amazing, thinking of creating a nebula sink integration later when I got some time!!!
👍 1