Reputation: 422
Is there a way using rdflib
or a similar package to validate a set of elements?
e.g.
from rdflib import Graph, Namespace, Literal
from rdflib.namespace import DCTERMS
n = Namespace("http://example.org/books/")
n.book
g = Graph()
g.bind("dc", DCTERMS)
g.bind("ex", n)
g.add((n["book"], DCTERMS["title"], Literal("Example Title"))) # Valid
g.add((n["book"], DCTERMS["tite"], Literal("Example Title"))) # Invalid
Or how it would look as a .ttl file:
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/books/>
ex:book dc:title "Example Title" . # Valid
ex:book dc:tite "Example Title" . # Invalid
There's a good chance I'm approaching this from the wrong angle entirely so any help is appreciated.
Upvotes: 1
Views: 831
Reputation: 1241
@UninformedUser commented:
check if the property is part of the DCTerms vocabulary - which is trivial to check
rdf:Property
in the other graph, as per:if not (the_property_being_tested, RDF.type, RDF.Property) in graph:
Or, just see if it's a subject in the graph (looser test):
in_graph = False
for s, p, o in g.triples((the_property_being_tested, None, None)):
in_graph = True
Upvotes: 2