rdf_generator.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. from rdflib import Graph, BNode, Literal, Namespace
  2. from rdflib.namespace import XSD
  3. odml = Namespace("http://g-node/odml#")
  4. g = Graph()
  5. doc = BNode("d1")
  6. s1 = BNode("s1")
  7. p12 = BNode("p1")
  8. g.add((doc, odml.version, Literal(1.1)))
  9. g.add((doc, odml.docversion, Literal(42)))
  10. g.add((doc, odml.author, Literal('D. N. Adams')))
  11. g.add((doc, odml.date, Literal('1979-10-12', datatype=XSD.date)))
  12. g.add((doc, odml.hasSection, s1))
  13. g.add((s1, odml.property, p12))
  14. g.add((s1, odml.type, Literal('crew')))
  15. g.add((s1, odml.description, Literal('Information on the crew')))
  16. g.add((s1, odml.name, Literal('TheCrew')))
  17. g.add((p12, odml.hasValue, Literal('[Arthur Philip Dent,Zaphod Beeblebrox,Tricia Marie McMillan,Ford Prefect]')))
  18. g.add((p12, odml.description, Literal('List of crew members names')))
  19. g.add((p12, odml.dtype, Literal('person')))
  20. g.add((p12, odml.name, Literal('NameCrewMembers')))
  21. res = g.serialize(format='application/rdf+xml').decode("utf-8")
  22. print(res)
  23. f = open("generated_ex1.xml", "w")
  24. f.write(res)
  25. f.close()