Reputation: 6694
I am writing an SPARQL query where I am creating an RDF graph. I am using SPARQL CONSTRUCT. As a requirement of my work, I have to concatenate two subject values and used it with CONSTRUCT statement. I have tried to do following (my RDF graph is in Virtuoso):
prefix map: <#>
prefix db: <>
prefix vocab: <vocab/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>
prefix jdbc: <http://d2rq.org/terms/jdbc/>
prefix fn: <http://www.w3.org/2005/xpath-functions#>
CONSTRUCT {
?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE
{
<http://www.ndssl.bi.vt.edu/fuse#DataSource> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
<http://www.ndssl.bi.vt.edu/fuse#OracleDataSource> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.ndssl.bi.vt.edu/fuse#DataSource>.
?DB <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ndssl.bi.vt.edu/fuse#OracleDataSource>.
<http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
?Table <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion>.
BIND(CONCAT(?DB, ?Table) AS ?p1)
}
However, I am getting following Error:
Virtuoso RDF01 Error Bad variable value in CONSTRUCT: "http://www.ndssl.bi.vt.edu/fuse#PROTOPOPhttp://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1" (tag 246 box flags 0) is not a valid subject, only object of a triple can be a literal
Please let me know how to solve it.
Upvotes: 1
Views: 1481
Reputation: 3301
The error is basically saying that you are concatenating two URIs:
http://www.ndssl.bi.vt.edu/fuse#PROTOPOP
http://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1
into a literal. I don't know what you are exactly trying to do, but do you really want to concat the WHOLE URI or only the last part after the #
? If you want to concat after the #
you need to omit the namespace.
bind (concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:))) as ?p)
Even at this stage the result of the bind is a literal
that you need to convert into a URI.
bind (uri(concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:)))) as ?p)
Generally I would simplify your query massively:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix fuse: <http://www.ndssl.bi.vt.edu/fuse#>
prefix owl:<http://www.w3.org/2002/07/owl#>
CONSTRUCT {
?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE
{
fuse:DataSource a owl:Class.
fuse:OracleDataSource rdfs:subClassOf fuse:DataSource.
?DB a fuse:DataSource.
fuse:HouseholdsWithinAdminRegion a owl:Class.
?Table a fuse:HouseholdsWithinAdminRegion.
bind (uri(concat(strafter(str(?DB),str(fuse:)),
strafter(str(?Table),str(fuse:)))) as ?p)
}
Upvotes: 3