remove_owl_data.py 724 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. import rdflib
  3. from rdflib.namespace import OWL
  4. from rdflib import Namespace
  5. GDPRtEXT = Namespace('http://purl.org/adaptcentre/openscience/ontologies/GDPRtEXT#')
  6. GDPRov = Namespace('http://purl.org/adaptcentre/openscience/ontologies/gdprov#')
  7. USECASE = Namespace('http://example.com/ontology/shoppingapp#')
  8. g = rdflib.Graph()
  9. g.parse('./data.ttl', format='ttl')
  10. unwanted_graph = rdflib.Graph()
  11. cleaned_graph = rdflib.Graph()
  12. for s, p, o in g:
  13. if s.startswith(USECASE):
  14. cleaned_graph.add((s, p, o))
  15. else:
  16. unwanted_graph.add((s, p, o))
  17. cleaned_graph.serialize(destination='cleaned.ttl', format='turtle')
  18. unwanted_graph.serialize(destination='removed.ttl', format='turtle')