With SPARQL, you can craft queries to retrieve the facts based on complex criteria.
The WHERE
clause in a SPARQL query defined a pattern that matches statements { subject
, tag
and object
}.
A semi-colon ;
indicates a set of tags belong to same subject.
A period .
indicates a closing statement, afterwards we need a new subject.
And the FILTER
only includes statements that match a boolean expression.
SELECT ?claim ?by
WHERE {
?claim rdf:type fact:Claim ;
prov:generatedBy ?by .
}
SmartTrust
topic:SELECT ?claim
WHERE {
?claim skos:member self:SmartTrust .
}
SELECT ?claim
WHERE {
?claim rdf:type fact:Claim ;
prov:wasGeneratedBy ?by .
FILTER (startswith(str(?by), "ethereum://"))
}
SELECT DISTINCT ?claim
WHERE {
?claim rdf:type schema:Organization.
}
sameAs
aliases:SELECT ?claim ?by
WHERE {
{
?claim (prov:wasGeneratedBy*/^prov:wasGeneratedBy) ?by .
}
UNION
{
?alias owl:sameAs ?claim.
?claim (prov:wasGeneratedBy*/^prov:wasGeneratedBy) ?by .
}
FILTER (startswith(str(?by), "ipfs://") || startswith(str(?by), "ethereum://"))
}
fact:Grounded
:INSERT {
?claim a fact:Grounded .
}
WHERE {
{
?claim (prov:wasGeneratedBy*/^prov:wasGeneratedBy) ?by .
}
UNION
{
?alias owl:sameAs ?claim .
?claim (prov:wasGeneratedBy*/^prov:wasGeneratedBy) ?by .
}
FILTER (startswith(str(?by), "ipfs://") || startswith(str(?by), "ethereum://"))
}
?claim
will be tagged a
fact:Grounded
.The WHERE
clause in SPARQL serves as a pattern matching mechanism, allowing you to specify patterns that RDF triples must conform to in order to match the query.
?claim rdf:type fact:Claim
matches triples where ?claim
is of type fact:Claim
.OPTIONAL
keyword. They allow you to specify patterns that may or may not match. If an optional pattern doesn't match, the variables within it will be bound to null.OPTIONAL
to find aliases connected via the owl:sameAs
property. However, it's not fully utilized due to a misunderstanding of its usage in this context.UNION
keyword allows you to combine multiple patterns together. Each pattern separated by UNION
operates independently, and results from each are combined.UNION
to combine patterns for finding both the original claim and its aliases (connected via owl:sameAs
, but schema:sameAs
is also common).FILTER
to restrict sources based on their prefixes (ipfs://
or ethereum://
).(prov:wasGeneratedBy*/^prov:wasGeneratedBy)
to traverse through chains of prov:wasGeneratedBy
relationships, including their inverses, an exhaustive search for claims.