SPARQL query equivalence

2019-08-26 17:37发布

问题:

Under the following context:

// owl in terms of Java-like syntax
Class Person {}
Class GraduateStudent extends Person {reference takesCourse [*] : GraduateCourse}
Class Student intersect Person {reference takesCourse [*] : Course}
Class UndergradStudent extends Student {}

Class Course{}
Class GraduateCourse extends Course{}
Class CsCourse extends Course{}

may I ask how should I read the following query?

// Q1: 
SELECT ?x ?y WHERE 
{ 
  {
    { ?x a :UndergradStudent . 
      ?x :takesCourse ?y }
     UNION 
    { ?x a :GraduateStudent .
      ?x :takesCourse ?y } 
  } 
   ?y a :Course .
}

I think it means select undergraduate students take any Course and graduate students take any Course, what bothers me to confirm this is the following:

  • Is there suppose to be a dot before ?y a :Course, such that the UNION-patterns inside {...} can be viewed as a single pattern to match, or it does not matter?

  • Can I distribute ?y a :Course over UNION, i.e. turn Q1 into Q2.

:

// Q2: 
SELECT ?x ?y WHERE 
{ 
  {
    { ?x a :UndergradStudent . 
      ?x :takesCourse ?y .
      ?y a :Course }
     UNION 
    { ?x a :GraduateStudent .
      ?x :takesCourse ?y .
      ?y a :Course } 
    }
}
标签: sparql