0

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

Viki
  • 107
  • 1
  • 8
  • Could you please use the stack overflow image hosting for images, rather than using other sites where images night not stick around. – Joshua Taylor Jun 23 '16 at 12:03
  • Asked on the mailing list and got an answer there as well... – UninformedUser Jun 23 '16 at 13:01
  • [Thread](https://sourceforge.net/p/virtuoso/mailman/message/35174598/) on the [Virtuoso Users mailing list](https://sourceforge.net/p/virtuoso/mailman/virtuoso-users/)... – TallTed Jun 23 '16 at 19:13
  • @JoshuaTaylor: Point taken. Updated with stack overflow image hosting. Thanks. – Viki Jun 24 '16 at 03:14

1 Answers1

0

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 .
}
Jindřich Mynarz
  • 1,563
  • 1
  • 16
  • 31
  • 1
    The whole query is wrong because he/she didn't understand SPARQL and RDF. For instance `?class2` is totally useless and `domainName` of course refers to the `?domain`. And `returnType` refers to the `?method`. I answered it already on the mailing list, there I also could see the data. Indeed, without it's impossible to show the correct query. – UninformedUser Jun 23 '16 at 13:03
  • @jindrichm: Thank you for detailed explanation. The next line problem is resolved by using grouping. – Viki Jun 27 '16 at 03:56