juupje / pyMogwai

PyMogwai is a Python-based implementation of the Gremlin graph traversal language, designed to create and handle knowledge graphs entirely in Python without the need for an external Gremlin server.
Apache License 2.0
2 stars 0 forks source link

add RDF export option #22

Closed WolfgangFahl closed 1 week ago

WolfgangFahl commented 1 week ago

RoyalFamily

query

PREFIX royal: <http://royal.example.org/>

SELECT ?person ?full_name ?succeeds ?wikidata_id ?born_iso_date ?died_iso_date
WHERE {
  ?person royal:full_name ?full_name .
  OPTIONAL { ?person royal:succeeds ?succeeds }
  OPTIONAL { ?person royal:wikidata_id ?wikidata_id }
  OPTIONAL { ?person royal:born_iso_date ?born_iso_date }
  OPTIONAL { ?person royal:died_iso_date ?died_iso_date }
}
ORDER BY ?full_name

try it!

result

person full_name succeeds wikidata_id born_iso_date died_iso_date
http://royal.example.org/1 Charles III of the United Kingdom http://royal.example.org/2 Q43274 1948-11-14
http://royal.example.org/0 Elizabeth Alexandra Mary Windsor Q9682 1926-04-21 2022-09-08
http://royal.example.org/6 Harry Duke of Sussex Q152316 1984-09-15
http://royal.example.org/3 Prince George of Wales http://royal.example.org/4 Q13590412 2013-07-22
http://royal.example.org/5 Prince Louis of Wales http://royal.example.org/6 Q38668629 2018-04-23
http://royal.example.org/4 Princess Charlotte of Wales http://royal.example.org/5 Q18002970 2015-05-02
http://royal.example.org/2 William, Duke of Cambridge http://royal.example.org/3 Q36812 1982-06-21
WolfgangFahl commented 1 week ago
[
  {
    "born_iso_date": "1948-11-14",
    "full_name": "Charles III of the United Kingdom",
    "person": "http://royal.example.org/1",
    "succeeds": "http://royal.example.org/2",
    "wikidata_id": "Q43274"
  },
  {
    "born_iso_date": "1926-04-21",
    "died_iso_date": "2022-09-08",
    "full_name": "Elizabeth Alexandra Mary Windsor",
    "person": "http://royal.example.org/0",
    "wikidata_id": "Q9682"
  },
  {
    "born_iso_date": "1984-09-15",
    "full_name": "Harry Duke of Sussex",
    "person": "http://royal.example.org/6",
    "wikidata_id": "Q152316"
  },
  {
    "born_iso_date": "2013-07-22",
    "full_name": "Prince George of Wales",
    "person": "http://royal.example.org/3",
    "succeeds": "http://royal.example.org/4",
    "wikidata_id": "Q13590412"
  },
  {
    "born_iso_date": "2018-04-23",
    "full_name": "Prince Louis of Wales",
    "person": "http://royal.example.org/5",
    "succeeds": "http://royal.example.org/6",
    "wikidata_id": "Q38668629"
  },
  {
    "born_iso_date": "2015-05-02",
    "full_name": "Princess Charlotte of Wales",
    "person": "http://royal.example.org/4",
    "succeeds": "http://royal.example.org/5",
    "wikidata_id": "Q18002970"
  },
  {
    "born_iso_date": "1982-06-21",
    "full_name": "William, Duke of Cambridge",
    "person": "http://royal.example.org/2",
    "succeeds": "http://royal.example.org/3",
    "wikidata_id": "Q36812"
  }
]