LUBM SPARQL Statements¶
Introduction¶
LUBM benchmark comes with a set of 14 test queries which were extended by agnos.ai to include more realistic business-like use case scenarios.
The original queries were modified to include:
Rules
Queries 2 and 9 were modified to take advantage of Rule Based Inferencing (Rules 2 and 9 respectively).
Query Complexity
Sorting, Aggregation, and Filtering operations were added to the original queries to increase query complexity.
Note
Note: The LUBM data model and SPARQL best practices would certainly allow us to come up with more efficient queries, however the main objective of the modified queries was to explore the impact of SPARQL 1.1 features on query performance for each product tested in the benchmark.
The following are some of the SPARQL commands and features added to the original queries:
Subquery, Property Path, Data Type Conversion (e.g.: xsd:interger),
OPTIONAL, BOUND, FILTER, BIND, CONTAINS, UNION, MINUS,
ORDER BY, LIMIT, OFFSET, GROUP BY, DISTINCT, REPLACE,
COALESCE, STR, COUNT, STRAFTER, STRBEFORE, LCASE, SUBSTR,
IRI, NOT IN, HAVING, GROUP_CONCAT, etc.
Queries¶
This query bears large input and high selectivity. It queries about just one class and one property and does not assume any hierarchy information or inference.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:GraduateStudent .
?X ub:takesCourse
<http://www.Department0.University0.edu/GraduateCourse0>
}
This query increases in complexity: 3 classes and 3 properties are involved.
Additionally, there is a triangular pattern of relationships between the objects involved.
Use case: A graduate student who is member of a university which has a department where the student already has a degree from.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y ?Z
WHERE {
?X rdf:type ub:GraduateStudent .
?Y rdf:type ub:University .
?Z rdf:type ub:Department .
?X ub:memberOf ?Z .
?Z ub:subOrganizationOf ?Y .
?X ub:undergraduateDegreeFrom ?Y
}
This query is similar to query 1 but class Publication has a
wide hierarchy.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:Publication .
?X ub:publicationAuthor
<http://www.Department0.University0.edu/AssistantProfessor0>
}
This query has small input and high selectivity.
It assumes subClassOf relationship between Professor
and its subclasses.
Class Professor has a wide hierarchy.
Another feature is that it queries about multiple
properties of a single class.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y1 ?Y2 ?Y3
WHERE {
?X rdf:type ub:Professor .
?X ub:worksFor <http://www.Department0.University0.edu> .
?X ub:name ?Y1 .
?X ub:emailAddress ?Y2 .
?X ub:telephone ?Y3
}
This query assumes subClassOf relationship between Person
and its subclasses and subPropertyOf-relationship
between memberOf and its sub-properties.
Moreover, class Person features a deep and wide hierarchy.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:Person .
?X ub:memberOf <http://www.Department0.University0.edu>
}
This SPARQL statement queries about only one class.
But it assumes both the explicit subClassOf relationship between
UndergraduateStudent and Student and the implicit one between
GraduateStudent and Student.
In addition, it has large input and low selectivity.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X WHERE { ?X rdf:type ub:Student }
This query is similar to query 6 in terms of class
Student but it increases in the number of classes and
properties and its selectivity is high.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y
WHERE {
?X rdf:type ub:Student .
?Y rdf:type ub:Course .
?X ub:takesCourse ?Y .
<http://www.Department0.University0.edu/AssociateProfessor0>
ub:teacherOf ?Y
}
This query is further more complex than query 7 by including one more property.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y ?Z
WHERE {
?X rdf:type ub:Student .
?Y rdf:type ub:Department .
?X ub:memberOf ?Y .
?Y ub:subOrganizationOf <http://www.University0.edu> .
?X ub:emailAddress ?Z
}
Besides the aforementioned features of class Student and
the wide hierarchy of class Faculty, like query 2,
this query is characterized by the most classes and
properties in the query set and there is a triangular
pattern of relationships.
Use Case: A faculty member, who is the advisor of a student, teaches a course that the student also takes.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y ?Z
WHERE {
?X rdf:type ub:Student .
?Y rdf:type ub:Faculty .
?Z rdf:type ub:Course .
?X ub:advisor ?Y .
?Y ub:teacherOf ?Z .
?X ub:takesCourse ?Z
}
This query differs from query 6, 7, 8 and 9
in that it only requires the (implicit) subClassOf relationship between GraduateStudent
and Student, i.e., subClassOf relationship between UndergraduateStudent and Student
does not add to the results.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:Student .
?X ub:takesCourse
<http://www.Department0.University0.edu/GraduateCourse0>
}
queries 11, 12 and 13 are intended to verify the presence of certain
OWL reasoning capabilities in the system.
In this query, property subOrganizationOf is defined as transitive.
Since in the benchmark data, instances of ResearchGroup are stated
as a sub-organization of a Department-individual and the later sub-organization of
a University-individual, inference about the subOrganizationOf-relationship between
instances of ResearchGroup and University is required to answer this query.
Additionally, its input is small.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:ResearchGroup . # (1)!
?X ub:subOrganizationOf <http://www.University0.edu>
}
ResearchGroupis asubOrganizationOfDepartment, which is asubOrganizationOfUniversity.
The benchmark data do not produce any instances of class Chair.
Instead, each Department-individual is linked to the chair professor of
that department by property headOf.
Hence this query requires realization, i.e., inference that professor is an
instance of class Chair because he or she is the head of a Department.
Input of this query is small as well.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X ?Y
WHERE {
?X rdf:type ub:Chair .
?Y rdf:type ub:Department .
?X ub:worksFor ?Y .
?Y ub:subOrganizationOf <http://www.University0.edu>
}
Property hasAlumnus is defined in the benchmark ontology as the inverse of
property degreeFrom, which has three sub-properties: undergraduateDegreeFrom,
mastersDegreeFrom, and doctoralDegreeFrom.
The benchmark data state a person as an alumnus of a university using one of
three sub-properties instead of hasAlumnus.
Therefore, this query assumes subPropertyOf-relationships between
degreeFrom and its sub-properties, and also requires inference about inverseOf.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:Person .
<http://www.University0.edu> ub:hasAlumnus ?X
}
This query is the simplest in the test set. This query represents those with large input and low selectivity and does not assume any hierarchy information or inference.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
SELECT ?X
WHERE {
?X rdf:type ub:UndergraduateStudent
}