Given an RDF::URI
and a SPARQL property path (stored as a String), I want to find values that satisfy the following query
SELECT ?value WHERE {
<URI> <property_path> ?value .
}
I managed to get by using the following snippet, but is feels very hackish:
query = SPARQL.parse(<<~QUERY)
SELECT ?value WHERE {
<#{uri}> #{property_path} ?value
}
QUERY
graph.query(query)
Is there a better way to achieve this, using a RDF::Query
for example?
From my understanding, you consider string interpolation to be "hackish" because you would like to deal with "things, not strings". This desire is definitely not reprehensible in a Semantic Web related field.
If so, you could construct queries using
SPARQL::Algebra
.All snippets below have the same meaning:
SPARQL query (
q1
)SPARQL Algebra expression (
q2
)Ruby code (
q3
)Compare internal representations or queries results:
The difference is that you do not need string manipulations in the third case.
These "operators" even have URIs (e.g.
Operator[:project]
).