Ask for the presence of all specified values? - sparql

I have exactly these triples in GraphDB:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
<http://example.com/greeting>
a <http://example.com/word> ;
rdfs:label "hello" .
I want to know if there is a thing in my triplestore with the label "hello" and another with the label "goodbye"
PREFIX : <http://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ASK
WHERE
{ VALUES ?l { "goodbye" "hello" }
?s a :thing ;
rdfs:label ?l
}
I am being told that yes, this is true, as if it is saying at least one of those are true. But I want to know if all of those patterns are true.
Can I do that in a SPARQL ASK?
I also tried the following but got the same (unwanted) result:
PREFIX : <http://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ASK
WHERE
{ VALUES (?l) { ("goodbye") ("hello") }
?s a :thing ;
rdfs:label ?l
}
Sanity check: the answer to this ASK is false
PREFIX : <http://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
ASK
WHERE
{ VALUES (?l) { ("goodbye") }
?s a :thing ;
rdfs:label ?l
}

Rather than asking "are all of these present", ask "is any of these not present" (and then negate the result either I've your application or with another "filter not exists":
ask {
values ?label { "hello" "goodbye" }
filter not exists {
?s a :thing ; rdfs:label ?word
}
}

My group is developing tools to convert tabular data about hospital records into RDF triples and then perform various cleanups and aggregations.
I have started this "answer" by writing out an illustration of this workflow with sample data.
Working implementations of the suggestions from #Joshua Taylor and #AKSW's are at the bottom.
The tabular data is first converted into "shortcut triples", which instantiate a minimal number of classes and link all literal values to those classes, even if the literal values are really "more about" something else.
So tabular data like this:
+-------+------------+----------+----------+
| EncID | EncDate | DiagCode | CodeType |
+-------+------------+----------+----------+
| 102 | 12/05/2015 | J44.9 | ICD-10 |
| 103 | 11/25/2015 | 602.9 | ICD-9 |
| 102 | 12/05/2015 | I50.9 | ICD-10 |
+-------+------------+----------+----------+
First becomes triples like this (ignoring the EncDates and CodeTypes.)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX turbo: <http://example.org/ontologies/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
INSERT DATA {
GRAPH turbo:encounters_from_karma {
turbo:5f62d61cee174283a4f875ccb8bb91a1 rdf:type obo:OGMS_0000097 .
turbo:5f62d61cee174283a4f875ccb8bb91a1 turbo:ScEnc2DiagCode "J44.9" .
turbo:5f62d61cee174283a4f875ccb8bb91a1 turbo:ScEnc2DiagCodeRegText "ICD-10" .
turbo:5f62d61cee174283a4f875ccb8bb91a1 turbo:ScEnc2EncID "102" .
turbo:81fcbb5c5bd141c9bde7f23321648ff7 rdf:type obo:OGMS_0000097 .
turbo:81fcbb5c5bd141c9bde7f23321648ff7 turbo:ScEnc2DiagCode "I50.9" .
turbo:81fcbb5c5bd141c9bde7f23321648ff7 turbo:ScEnc2DiagCodeRegText "ICD-10" .
turbo:81fcbb5c5bd141c9bde7f23321648ff7 turbo:ScEnc2EncID "102" .
turbo:820dd597229244ab853ed845dd740f1f rdf:type obo:OGMS_0000097 .
turbo:820dd597229244ab853ed845dd740f1f turbo:ScEnc2DiagCode "602.9" .
turbo:820dd597229244ab853ed845dd740f1f turbo:ScEnc2DiagCodeRegText "ICD-9" .
turbo:820dd597229244ab853ed845dd740f1f turbo:ScEnc2EncID "103" . }
}
And is then expanded like this
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX turbo: <http://example.org/ontologies/>
INSERT {
GRAPH turbo:expanded_encounters {
?NewEnc rdf:type obo:OGMS_0000097 .
?NewEnc turbo:previousUriText ?previousUriText .
?NewEnc obo:OBI_0000299 ?DiagCrid .
?DiagCrid rdf:type turbo:DiagCrid .
?DiagCrid obo:BFO_0000051 ?DiagSymb .
?DiagSymb rdf:type turbo:EncounterDiagCodeSymbol .
?DiagSymb turbo:thingLiteralValue ?DiagSymbVal .
}
}
WHERE
{ GRAPH turbo:encounters_from_karma
{ ?EncFromKarma
rdf:type obo:OGMS_0000097 ;
turbo:ScEnc2DiagCode ?DiagSymbVal
BIND(str(?EncFromKarma) AS ?previousUriText)
BIND(uri(concat("http://transformunify.org/ontologies/", struuid())) AS ?NewEnc)
BIND(uri(concat("http://transformunify.org/ontologies/", struuid())) AS ?DiagCrid)
BIND(uri(concat("http://transformunify.org/ontologies/", struuid())) AS ?DiagSymb)
}
}
And therefore looks like this:
#prefix turbo: <http://purl.obolibrary.org/obo/> .
#prefix obo: <http://example.org/ontologies/> .
<http://example.org/ontologies/b9dc5b08-cf1b-465e-8773-4b19bfbcf803>
a <http://purl.obolibrary.org/obo/OGMS_0000097> ;
turbo:OBI_0000299 <http://example.org/ontologies/8a04f52f-22d2-4aab-bacf-d96e1c7fe900> ;
obo:previousUriText "http://example.org/ontologies/5f62d61cee174283a4f875ccb8bb91a1" .
obo:8a04f52f-22d2-4aab-bacf-d96e1c7fe900
a obo:DiagCrid ;
turbo:BFO_0000051 obo:6738d8c0-8bb8-4078-8430-5e9294e5af15 .
obo:6738d8c0-8bb8-4078-8430-5e9294e5af15
a obo:EncounterDiagCodeSymbol ;
obo:thingLiteralValue "J44.9" .
obo:d3a8a700-2eb9-420d-a863-d47462fa393c
a turbo:OGMS_0000097 ;
turbo:OBI_0000299 obo:c12acc26-6dbe-486d-9ae9-9f34c9561aea ;
obo:previousUriText "http://example.org/ontologies/81fcbb5c5bd141c9bde7f23321648ff7" .
obo:c12acc26-6dbe-486d-9ae9-9f34c9561aea
a obo:DiagCrid ;
turbo:BFO_0000051 obo:3b784151-b369-4594-9ce3-285f5fe60850 .
obo:3b784151-b369-4594-9ce3-285f5fe60850
a obo:EncounterDiagCodeSymbol ;
obo:thingLiteralValue "I50.9" .
obo:af0e949a-99e4-48cd-885b-7cb1aa3dd265
a turbo:OGMS_0000097 ;
turbo:OBI_0000299 obo:c2da52ec-7331-4011-b8f8-6fbf8b419708 ;
obo:previousUriText "http://example.org/ontologies/820dd597229244ab853ed845dd740f1f" .
obo:c2da52ec-7331-4011-b8f8-6fbf8b419708
a obo:DiagCrid ;
turbo:BFO_0000051 obo:7f8399ef-5fcd-447c-80a4-18dfb160e99c .
obo:7f8399ef-5fcd-447c-80a4-18dfb160e99c
a obo:EncounterDiagCodeSymbol ;
obo:thingLiteralValue "602.9" .
Finally, I can check for the correct transformation with the suggestions from #Joshua Taylor or #AKSW:
#Joshua Taylor
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX turbo: <http://example.org/ontologies/>
ASK
WHERE
{ { GRAPH turbo:expanded_encounters
{ VALUES ( ?previousUriTextVal ?DiagSymbVal ) {
( "http://example.org/ontologies/5f62d61cee174283a4f875ccb8bb91a1" "J44.9" )
( "http://example.org/ontologies/820dd597229244ab853ed845dd740f1f" "602.9" )
( "http://example.org/ontologies/81fcbb5c5bd141c9bde7f23321648ff7" "I50.9" )
}
FILTER NOT EXISTS { ?NewEnc rdf:type obo:OGMS_0000097 ;
turbo:previousUriText ?previousUriTextVal ;
obo:OBI_0000299 ?DiagCrid .
?DiagCrid rdf:type turbo:DiagCrid ;
obo:BFO_0000051 ?DiagSymb .
?DiagSymb rdf:type turbo:EncounterDiagCodeSymbol ;
turbo:thingLiteralValue ?DiagSymbVal
}
}
}
}
#AKSW
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX turbo: <http://example.org/ontologies/>
ASK
WHERE
{ GRAPH turbo:expanded_encounters
{ FILTER ( ?count = 3 )
{ SELECT (COUNT(DISTINCT ?NewEnc) AS ?count)
WHERE
{ VALUES ( ?previousUriTextVal ?DiagSymbVal ) {
( "http://example.org/ontologies/5f62d61cee174283a4f875ccb8bb91a1" "J44.9" )
( "http://example.org/ontologies/820dd597229244ab853ed845dd740f1f" "602.9" )
( "http://example.org/ontologies/81fcbb5c5bd141c9bde7f23321648ff7" "I50.9" )
}
?NewEnc rdf:type obo:OGMS_0000097 ;
turbo:previousUriText ?previousUriTextVal ;
obo:OBI_0000299 ?DiagCrid .
?DiagCrid rdf:type turbo:DiagCrid ;
obo:BFO_0000051 ?DiagSymb .
?DiagSymb rdf:type turbo:EncounterDiagCodeSymbol ;
turbo:thingLiteralValue ?DiagSymbVal
}
}
}
}

Related

SPARQL selecting unittext (blank nodes)

I recently started working with Linked Data and SPARQL.
I've a dataset which contains unittext, indicating what kind of unit the property has (meters, kilograms and so on).
The unit is a values which is inserted on the relationship between object and its quantitative property.
In my RDF dataset the units are included in a blank node and indicated by https://schema.org/unitText.
An example of the data set is included below.
], [
a owl:Restriction ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ;
owl:onProperty <https://someuri> ;
ns1:unitText "kg"
How can I select this property?
The query so far is:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select distinct ?label ?aspect ?datatype where {
?s rdfs:subClassOf/owl:onProperty ?aspect .
?aspect rdf:type owl:ObjectProperty.
?aspect skos:prefLabel ?label .
?aspect rdfs:range ?datatype .
FILTER EXISTS{ ?aspect rdfs:range ?datatype. }
VALUES ?datatype {
xsd:string
xsd:gYear
xsd:boolean
xsd:decimal
xsd:integer
xsd:date
}
}
The RDF dataset looks actually like this:
rdfs:subClassOf [ a owl:Restriction ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ;
owl:onProperty <someuri> ;
<https://schema.org/unitText> "kg"
] ;

SPARQL help to build modify query

I have to add a few new fields to existing report. Our system already have a lot of reports with types AccountTeamBodReport, CoordinatorBodReport. Also I want to set default value for new fields.
PREFIX : <http://example.com/knowledge-black-belt#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
INSERT { ?s :hasResult "" ; //(new fields)
:hasResultPriority "MEDIUM";
:hasLowMarginComments "";
:hasLowMarginCommentsPriority "MEDIUM";
}
WHERE
{ ?s rdf:type ?type ;
FILTER ( ?type IN (:AccountTeamBodReport, :CoordinatorBodReport) )
}
It doesn't work. There is any errors. What I did wrong? I use fuseki server and check all my query there. Fuseki logs have only successful responds. When I want to see specific report I use:
PREFIX : <http://dataart.com/knowledge-black-belt#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT *
WHERE
{ ?s :hasId ?name ;
rdf:type ?type ;
:hasCreationTime ?created ;
:hasReportMonth ?reportMonth ;
:hasAchievements ?achievements ;
:hasAchievementsPriority ?achievementsPriority ;
:hasRisksIssues ?risksIssues ;
:hasRisksIssuesPriority ?risksIssuesPriority ;
:hasOther ?other ;
:hasOtherPriority ?otherPriority ;
:hasPerformance ?performance ;
:hasCustomerRelationship ?customerRelationship ;
:hasTeamMorale ?teamMorale ;
:hasNoNews ?noNews ;
:hasResult ?result ;
:hasResultPriority ?resultPriority;
:hasLowMarginComments ?lowMarginComments;
:hasLowMarginCommentsPriority ?lowMarginCommentsPriority;
:hasClient ?client
OPTIONAL
{ ?s :hasIndicatorDescription ?indicatorDescription}
?s rdf:type ?type ;
:hasClient :clientSomeId
FILTER ( ?type IN (:AccountTeamBodReport, :CoordinatorBodReport) )
}
And there is any changes after Insert query.

Sparql - Applying limiting criteria to predicates

I'm fairly new to RDF / Sparql, so apologies for any incorrect terminology, and also for the fairly terrible example that follows:
Given the following RDF dataset:
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix e: <http://www.example.com/#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
e:Freemason a owl:Class .
e:Civilian a owl:Class .
e:Marty a e:Freemason .
e:Eugene a e:Freemason .
e:Mike a e:Freemason .
e:Alan a e:Freemason .
e:Paul a e:Civilian .
e:Marty foaf:knows e:Eugene .
e:Eugene foaf:knows e:Mike .
e:Eugene foaf:knows e:Paul .
e:Paul foaf:knows e:Alan .
I'm trying to identify friends-of-friends that e:Marty knows through other e:Freemasons only.
So:
Marty knows Mike through Eugene, and they're all Freemason's so it's fine
Marty knows Eugene, who has a Civilian friend Paul. Paul has a Freemason friend Alan. However, Marty doesn't have a "freemason only" path to Alan, so he should be excluded.
Here's the SPARQL query I have:
prefix e: <http://www.example.com/#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
{
<http://www.example.com/#Marty> foaf:knows+ ?target .
?target a e:Freemason .
}
This returns:
http://www.example.com/#Eugene
http://www.example.com/#Mike
http://www.example.com/#Alan
Here, Alan is included as he matches the is-a-freemason criteria.
How I do modify the query to exclude Alan?
I don't know the solution in pure SPARQL, sorry.
In OpenLink Virtuoso's SPARQL-BI, the solution is this query
prefix e: <http://www.example.com/#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select *
where
{
{ select ?orig ?target
where
{ ?orig foaf:knows ?target .
?target a e:Freemason .
}
}
option ( TRANSITIVE,
T_IN(?orig),
T_OUT(?target),
T_DISTINCT,
T_MIN(1)
)
filter ( ?orig = <http://www.example.com/#Marty> )
}
-- with these results --
orig target
<http://www.example.com/#Marty> <http://www.example.com/#Eugene>
<http://www.example.com/#Marty> <http://www.example.com/#Mike>
Here's an example using SPARQL that has been deprecated from the spec (for reasons I never understood) but remains supported in Virtuoso (which will be the case for the unforeseeable future)
## RDF-Turtle Start ##
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix e: <http://www.example.com/#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
e:Freemason a owl:Class .
e:Civilian a owl:Class .
e:Marty a e:Freemason .
e:Eugene a e:Freemason .
e:Mike a e:Freemason .
e:Alan a e:Freemason .
e:Paul a e:Civilian .
e:Marty foaf:knows e:Eugene .
e:Eugene foaf:knows e:Mike .
e:Eugene foaf:knows e:Paul .
e:Paul foaf:knows e:Alan .
## RDF-Turtle End ##
Using Property Path Pattern from SPARQL that has been deprecated
but preserved in Virtuoso
PREFIX e: <http://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Tutorials/club-member-test.ttl#>
PREFIX dsn: <http://kingsley.idehen.net/DAV/home/kidehen/Public/Linked%20Data%20Documents/Tutorials/club-member-test.>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
FROM dsn:ttl
WHERE {
e:Marty foaf:knows{2} ?target .
?target a e:Freemason .
}
Live Links:
Query Solution
Query Definition

sparql query: get several values from a List

My query returns result dependent on which one of two sparql OPTIONS clauses come first for a List of Images. Although using Jena ARQ is not an option at this point, and I'd like to solve this with a pure SPARQL query, still I'd like to know how it could be solved with Jena as well.
My data presentation is attached below, the data may contain a list of images. My image representation is also below. I'm attaching my query as well.
The sprql query has two variables urlX, and urlY declared in the 2 OPTIONS blocks, if a List of images exists. Depending on which of the OPTIONS comes first, I get the value for that one variable, while the other one doesn't get reached. It seems the issue has to do with using OPTIONS clause. I'm not sure what else I can try instead, I'm far from being an expert on sparql queries. I want the query to do the following: if a collection of images is present, I want to see if both image sizes (dc:conformsTo) are present and get both urlX and urlY values, or get the ones that exist. Much appreciate your time.
My data representation:
#prefix dc: <http://purl.org/dc/terms/> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix lews: <http://lews.com/content/> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
lews:26331340 lews:name "the Human Good Luck Charm is Back"^^xsd:token ;
dc:created "2014-10-20T17:14:55.357-07:00"^^xsd:dateTime ;
dc:identifier "26331340"^^xsd:int ;
dc:modified "2016-08-04T13:43:00.897-07:00"^^xsd:dateTime ;
dc:title "the Human Good Luck Charm is Back" ;
dc:hasPart <http://lews.com/content/26331340#Images> ;
dc:abstract "As the World Series gets underway..." ;
dc:description "The super fan who rooted for the Royals is back to boost morale." ;
dc:subject "hoping for a World Series victory".
<http://lews.com/content/26331340#Images> dc:identifier "Images"^^xsd:token ;
rdf:first lews:26331375 ;
rdf:rest _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331376 ;
rdf:li <http://lews.com/content/26331340#Images> , _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331376 , _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331377 , _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331378 , _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331379 , _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331380 ;
a rdf:List .
_:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331376 rdf:first lews:26331376 ;
rdf:rest _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331377 .
_:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331377 rdf:first lews:26331377 ;
rdf:rest _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331378 .
_:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331378 rdf:first lews:26331378 ;
rdf:rest _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331379 .
_:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331379 rdf:first lews:26331379 ;
rdf:rest _:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331380 .
_:genid-15e530b0195547d9ac3f8e5e6785a747-x26331340Images26331380 rdf:first lews:26331380 ;
rdf:rest rdf:nil .
My image representation:
#prefix dc: <http://purl.org/dc/terms/> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix lews: <http://abcnews.com/content/> .
#prefix mrss: <http://search.yahoo.com/mrss/> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
lews:26331376 lews:name "141020_wn_donvan0_704x396.jpg"^^xsd:token ;
lews:section "wnt"^^xsd:token ;
lews:type "Image"^^xsd:token ;
dc:conformsTo "704x396"^^xsd:token ;
dc:created "2014-10-20T17:15:09.637-07:00"^^xsd:dateTime ;
dc:hasFormat <http://lews.go.com/images/WNT/141020_wn_donvan0_704x396.jpg> ;
dc:identifier "26331376"^^xsd:int ;
dc:isPartOf <http://lews.go.com/WNT> ;
dc:modified "2014-10-20T17:15:09.947-07:00"^^xsd:dateTime ;
dc:type "StillImage"^^xsd:token ;
mrss:height "396"^^xsd:int ;
mrss:width "704"^^xsd:int ;
xsd:date "2014-10-20"^^xsd:date ;
xsd:gMonthDay "--10-20"^^xsd:gMonthDay ;
xsd:gYear "2014"^^xsd:gYear ;
xsd:gYearMonth "2014-10"^^xsd:gYearMonth .
My query:
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX mrss: <http://search.yahoo.com/mrss/>
PREFIX search: <http://www.openrdf.org/contrib/lucenesail#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX lews: <http://abcnews.com/content/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?id ?title ?description ?urlX ?urlY ?section ?imgName
?subject dc:identifier ?id.
OPTIONAL {?subject dc:title ?title.}
OPTIONAL {?subject dc:description ?description.}
OPTIONAL {?subject dc:isPartOf ?section.}
OPTIONAL {
?subject dc:hasPart ?imageCol.
?imageCol dc:identifier "Images"^^xsd:token.
OPTIONAL{
?imageCol rdf:li ?bnode.
?bnode rdf:first ?image.
?image lews:name ?imgName;
dc:conformsTo "4x3";
dc:hasFormat ?urlX.
}
OPTIONAL{
?imageCol rdf:li ?bnode.
?bnode rdf:first ?image.
?image lews:name ?imgName;
dc:conformsTo "16x9";
dc:hasFormat ?urlY.
}
}
}
LIMIT ${limit}
If I understood correctly what it is you want, you just need to group the optionals differently:
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX mrss: <http://search.yahoo.com/mrss/>
PREFIX search: <http://www.openrdf.org/contrib/lucenesail#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX lews: <http://abcnews.com/content/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?id ?title ?description ?urlX ?urlY ?section ?imgName {
?subject dc:identifier ?id.
OPTIONAL { ?subject dc:title ?title. }
OPTIONAL { ?subject dc:description ?description. }
OPTIONAL { ?subject dc:isPartOf ?section. }
OPTIONAL {
?subject dc:hasPart ?imageCol.
?imageCol dc:identifier "Images"^^xsd:token.
OPTIONAL {
?imageCol rdf:li ?bnode.
?bnode rdf:first ?image.
?image lews:name ?imgName;
# Here we optionally bind ?urlX and/or ?urlY
OPTIONAL {
?image dc:conformsTo "4x3";
dc:hasFormat ?urlX.
}
OPTIONAL {
?image dc:conformsTo "16x9";
dc:hasFormat ?urlY.
}
}
}
}

SPARQL HTML result displaying in next line

I'm executing SPARQL query on virtuoso SPARQL editor.
The result of query in HTML format is displaying in next line for each corresponding record as shown on below image:
Kindly advise how to resolve this display issue.
Here is the SPARQL query:
prefix DOL: <http://www.MyOnt.com/something/v1#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select ?cName ?domain ?dValues ?method ?rType{
{
?class foaf:name "MyJavaClass" .
}
{ ?class foaf:name ?cName }
union
{ ?class DOL:belongsTo ?domain }
union
{ ?class2 DOL:domainName ?dValues }
union
{ ?class DOL:hasMethod ?method }
union
{ ?class2 DOL:returnType ?rType }
}
SPARQL output on virtuoso
UNION is for matching alternatives, so that the results of your query would match any of the patterns joined by UNION. If you want the results to match all the triple patterns in your query, you just group them:
PREFIX DOL: <http://www.MyOnt.com/something/v1#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?cName ?domain ?dValues ?method ?rType
WHERE {
?class foaf:name "MyJavaClass" ;
DOL:belongsTo ?domain ;
DOL:hasMethod ?method .
?class2 DOL:domainName ?dValues ;
DOL:returnType ?rType .
}
If you want the results to match only some of the triple patterns, you can use OPTIONAL to wrap the patterns that the results don't need to match, such as in the following:
PREFIX DOL: <http://www.MyOnt.com/something/v1#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?cName ?domain ?dValues ?method ?rType
WHERE {
?class foaf:name "MyJavaClass" ;
DOL:belongsTo ?domain .
OPTIONAL {
?class DOL:hasMethod ?method .
}
?class2 DOL:domainName ?dValues ;
DOL:returnType ?rType .
}