Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Created May 14, 2019 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nooperpudd/e74b2c5ba40697897c39600bcf20cf1c to your computer and use it in GitHub Desktop.
Save nooperpudd/e74b2c5ba40697897c39600bcf20cf1c to your computer and use it in GitHub Desktop.
graph database
import os
import rdflib
from rdflib import Graph, Literal
from rdflib.namespace import RDFS, FOAF
PLACE = rdflib.Namespace("http://example.com/place/")
PATH = rdflib.Namespace("http://example.com/path/")
DEFAULT = rdflib.Namespace("http://www.example.com/default/")
graph = Graph()
graph.bind("foaf", FOAF)
graph.bind("rdfs", RDFS)
graph.bind("place", PLACE)
graph.bind("path", PATH)
country = PLACE["niga"]
sub_city = PLACE["xxxx"]
sub_city_2 = PLACE["BBBB"]
sub_word = PLACE["EEEEE"]
graph.add((country, PATH.city, sub_city))
graph.add((country, PATH.city, sub_city_2))
graph.add((country, RDFS.label, Literal("niga")))
graph.add((sub_city, RDFS.label, Literal("xxxx")))
graph.add((sub_city, PATH.wod, sub_word))
graph.add((sub_city_2, RDFS.label, Literal("BBBB")))
graph.add((sub_word, RDFS.label, Literal("EEEEE")))
graph.serialize(os.path.join("city_test.ttl"), format='turtle')
# country = BNode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment