The Lehigh University Benchmark (LUBM) is the standard synthetic benchmark for RDF stores with OWL reasoning: a university-domain ontology, a data generator that produces any number of universities, and 14 test queries whose answers depend on the ontology as much as on the data. This page puts each of those 14 original queries next to its extended version, explains what was added and why, and shows the two inference rules the extended set relies on. It is a reference to the queries themselves — it publishes no timings.
Where the queries come from
ub:
<http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
xsd:integer
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
The authors of the extension are explicit about the trade-off: "The LUBM data model combined with SPARQL best practices would certainly allow us to come up with cleaner and more efficient queries, however the main objective of the extended queries was to explore the impact of SPARQL 1.1 features on query performance." Read the extended queries as feature-coverage tests, not as model answers.
Reasoning. 10 of the 14 original queries rely on reasoning — rdfs:subClassOf and rdfs:subPropertyOf hierarchies, a transitive property (subOrganizationOf), an inverse property (hasAlumnus) and one class that exists only by definition (Chair). Only Queries 1, 2, 3 and 14 return their full answer on the raw data. In the extended set Queries 1, 3 and 14 still need none; extended Query 2 now depends on Rule 2 having run. Each section below says which.
rdfs:subClassOf
rdfs:subPropertyOf
subOrganizationOf
hasAlumnus
Chair
All 28 queries and both rules ship with the two LUBM templates, so nothing has to be typed in.
a
b
ub:Type2
ub:Type9
The file behind each library entry is a small Turtle document that wraps the SPARQL text as a literal, together with its label, description and tags — the blocks below are those literals, copied as shipped.
ORDER BY DESC
FILTER CONTAINS
FILTER (!BOUND)
FILTER IN
BIND IRI
CONCAT
Query 1a — Graduate Students Taking a Specific Course
What LUBM says about it: Large input, high selectivity. Queries one class and one property. No hierarchy or inference required.
No reasoning needed — the classes and properties it reads are asserted directly in the data.
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> }
Query 1b — Graduate Students Taking a Specific Course
From the extension's authors: Added name, address, optional telephone and limited result sorted by name.
Instead of one fixed course it lists graduate students with their name and e-mail address, adds the telephone when there is one, sorts by name and stops at 100 rows.
No reasoning needed.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?graduateStudent ?name ?address ?telephone WHERE { ?graduateStudent rdf:type ub:GraduateStudent ; ub:name ?name ; ub:emailAddress ?address . OPTIONAL { ?graduateStudent ub:telephone ?telephone . } } ORDER BY ?name LIMIT 100
Query 2a — Graduate Student Triangular Pattern
What LUBM says about it: 3 classes, 3 properties with triangular relationship pattern. 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 }
Query 2b — Graduate Student Triangular Join
From the extension's authors: This query has been modified to use Rule 2.
Every join of the original — student, department, university, degree — has already been done by Rule 2, so the query reads the inferred class ub:Type2 and two of its properties. It only returns rows on a database where the rule has run.
Needs Rule 2 to have run (see The two rules below); the underlying hierarchy reasoning is done inside the rule's body.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?X ?Y ?Z WHERE { ?X a ub:Type2 ; ub:memberOf ?Z ; ub:undergraduateDegreeFrom ?Y . }
Query 3a — Publications by a Specific Professor
What LUBM says about it: 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> }
Query 3b — Publications by a Specific Professor
From the extension's authors: This query adds aggregation and sorting to the original Query 3. It returns the top 10 publications by number of authors.
Counts authors per publication and keeps the ten with the most.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?publication (COUNT(?publicationAuthor) AS ?authorCount) WHERE { ?publication rdf:type ub:Publication ; ub:publicationAuthor ?publicationAuthor . } GROUP BY ?publication ORDER BY DESC(?authorCount) LIMIT 10
Query 4a — Professor Details at Department
What LUBM says about it: Small input, high selectivity. Assumes subClassOf between Professor and its subclasses. Queries multiple properties of a single class.
Needs reasoning: the answer is complete only after materialisation.
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 }
Query 4b — Professor Details at Department
From the extension's authors: This version of query 4 unions two filtered BGP, uses some basic functions and string manipulation. The data model would certainly allow us to come up with a more efficient query, however the objective here is not to use the most efficient method, but to explore sparql functionality and their impact on query performance.
Two branches joined by UNION: professors of one department, and graduate students of one course, each with three optional contact fields. The telephone is rewritten with REPLACE, a place column is picked with COALESCE, and FILTER (CONTAINS(STR(...))) narrows each branch by IRI text.
FILTER (CONTAINS(STR(...)))
Needs reasoning, like the original.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT DISTINCT ?name ?emailAddress (REPLACE(?telephone, "x", "0") AS ?phoneNumber) ?university ?universityName ?course ?courseName (COALESCE(?universityName,?courseName) AS ?place) WHERE { { ?professor rdf:type ub:Professor ; ub:worksFor ?university . OPTIONAL { ?professor ub:name ?name } OPTIONAL { ?professor ub:emailAddress ?emailAddress } OPTIONAL { ?professor ub:telephone ?telephone } ?university ub:name ?universityName . FILTER (CONTAINS(STR(?university),"Department10.University200")) } UNION { ?student rdf:type ub:GraduateStudent ; ub:takesCourse ?course . OPTIONAL { ?student ub:name ?name } OPTIONAL { ?student ub:emailAddress ?emailAddress } OPTIONAL { ?student ub:telephone ?telephone } ?course ub:name ?courseName FILTER (CONTAINS(STR(?course),"Department20.University30")) } } LIMIT 5000
Query 5a — Persons Member of Department
What LUBM says about it: Assumes subClassOf between Person and its subclasses and subPropertyOf between memberOf and its sub-properties. 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> }
Query 5b — Persons Member of Department
From the extension's authors: Optionals, filtering and pagination was added the original Query 5.
Adds the degree properties as optional columns, keeps only people who are not the head of anything (FILTER (!BOUND(?headOf))), sorts by department and returns the second page of 100 rows.
FILTER (!BOUND(?headOf))
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?person ?memberOf ?degreeFrom ?doctoralDegreeFrom ?undergraduateDegreeFrom WHERE { ?person rdf:type ub:Person . ?person ub:memberOf ?memberOf ; ub:degreeFrom ?degreeFrom ; OPTIONAL { ?person ub:doctoralDegreeFrom ?doctoralDegreeFrom } OPTIONAL { ?person ub:headOf ?headOf } OPTIONAL { ?person ub:undergraduateDegreeFrom <http://www.University719.edu> } FILTER (!BOUND(?headOf)) } ORDER BY ?memberOf OFFSET 100 LIMIT 100
Query 6a — All Students (subClassOf Inference)
What LUBM says about it: Queries one class but assumes both explicit subClassOf (UndergraduateStudent → Student) and implicit (GraduateStudent → Student). Large input, 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 }
Query 6b — All Students (subClassOf Inference)
From the extension's authors: Added count to the original Query 6.
Same class as the original, one number back: COUNT.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT (COUNT(?student) AS ?studentCount) WHERE { ?student rdf:type ub:Student }
Query 7a — Students Taking Courses from a Professor
What LUBM says about it: Similar to query 6 for class Student but increases in number of classes and properties. High 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 ?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 }
Query 7b — Students Taking Courses from a Professor
From the extension's authors: Adds data type conversion, string manipulation, filter on list of converted values, filter and sorting on aggregated data. Storing the course number in the triplestore, instead of having to extract it from the IRI would certainly be more efficient. But, again, the idea is to find out how the triplestore handles different tasks.
Reads the course number out of the course IRI with STRAFTER and xsd:integer, keeps twelve chosen numbers with FILTER ... IN, then counts students per professor and keeps professors with at least four (HAVING), most first.
FILTER ... IN
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?professor ?professorName (COUNT(?student) AS ?studentCount) WHERE { ?student rdf:type ub:Student . ?course rdf:type ub:Course ; ub:name ?courseName . ?student ub:takesCourse ?course . ?professor ub:teacherOf ?course ; ub:name ?professorName . BIND(xsd:integer(STRAFTER(STR(?course), "Course")) as ?courseNumber) FILTER (?courseNumber IN (1, 3, 4, 6, 10, 12, 23, 24, 26, 32, 40, 41)) } GROUP BY ?professor ?professorName HAVING ((COUNT(?student)) >= 4) ORDER BY DESC(COUNT(?student))
Query 8a — Students at a University with Email
What LUBM says about it: More complex than query 7 by including one more property. Students who are members of departments that are sub-organizations of a university.
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 }
Query 8b — Students at a University with Email
From the extension's authors: This query is further more complex than Query 7 by including aggregation and sorting.
Counts departments per university and returns the ten largest.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> # Top 10 largest universities by number of departments SELECT ?U (COUNT(?Y) AS ?deptCount) WHERE { ?Y rdf:type ub:Department . ?U rdf:type ub:University . ?Y ub:subOrganizationOf ?U . } GROUP BY ?U ORDER BY DESC(?deptCount) LIMIT 10
Query 9a — Student-Advisor-Course Triangular
What LUBM says about it: Most classes and properties in the query set. Triangular pattern: 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 }
Query 9b — Student-Advisor-Course Triangular Join
From the extension's authors: This query has been modified to use Rule 9.
Reads the inferred class ub:Type9 and its two inferred properties ub:hasFaculty and ub:hasCourse, which Rule 9 writes; the three-way join is done by the rule. It only returns rows on a database where the rule has run.
ub:hasFaculty
ub:hasCourse
Needs Rule 9 to have run (see The two rules below); the underlying hierarchy reasoning is done inside the rule's body.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?X ?Y ?Z WHERE { ?X a ub:Type9 ; ub:hasFaculty ?Y ; ub:hasCourse ?Z . }
Query 10a — Students Taking a Specific Graduate Course
What LUBM says about it: Differs from queries 6-9: only requires the implicit subClassOf between GraduateStudent and Student. The UndergraduateStudent subclass does not add to 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> }
Query 10b — Students Taking a Specific Graduate Course
From the extension's authors: Adds GROUP BY and GROUP_CONCAT to the original query 10.
Adds the student's name and advisor, filters on the literal advisor name and folds each student's courses into one comma-separated cell with GROUP_CONCAT.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?studentName (GROUP_CONCAT(?courseName; SEPARATOR=",") AS ?courseList) WHERE { ?student rdf:type ub:Student ; ub:name ?studentName ; ub:advisor ?advisor ; ub:takesCourse ?course . ?course ub:name ?courseName . ?advisor ub:name "AssistantProfessor0" . } GROUP BY ?studentName LIMIT 100
Query 11a — Research Groups via Transitive subOrganizationOf
What LUBM says about it: OWL reasoning required: subOrganizationOf is transitive. ResearchGroup → Department → University, so inference about the transitive relationship between ResearchGroup and University is needed.
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 . ?X ub:subOrganizationOf <http://www.University0.edu> }
Query 11b — Research Groups via Transitive subOrganizationOf
From the extension's authors: This query is further more complex than the original query 11. It adds a subquery, data aggregation, sorting, and inverted property path.
A subquery finds the five universities with the most students; the outer query walks two inverse subOrganizationOf steps (^ub:subOrganizationOf/^ub:subOrganizationOf) from each of them to its research groups.
^ub:subOrganizationOf/^ub:subOrganizationOf
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?U ?R WHERE { ?R rdf:type ub:ResearchGroup . ?U rdf:type ub:University . # University <- Department (omitted) <- ResearchGroup ?U ^ub:subOrganizationOf/^ub:subOrganizationOf ?R . # Top 5 largest universities by number of students { SELECT ?U (COUNT(?X) AS ?StudentCount) WHERE { ?X rdf:type ub:Student . ?Y rdf:type ub:Department . ?U rdf:type ub:University . ?X ub:memberOf ?Y . ?Y ub:subOrganizationOf ?U . } GROUP BY ?U ORDER BY DESC(?StudentCount) LIMIT 5 } } LIMIT 5000
Query 12a — Chair Realization (OWL Reasoning)
What LUBM says about it: Requires OWL realization: the benchmark data has no explicit Chair instances. A professor is inferred to be a Chair because they are the head of a Department (via equivalentClass axiom).
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> }
Query 12b — Chair Realization (OWL Reasoning)
From the extension's authors: Added filter, string concatenation and property path.
Every inferred Chair with name, research interest, e-mail and courses; an IRI is built from those values with BIND (IRI(LCASE(CONCAT(...)))), then filtered on its text and on a NOT IN list of universities.
BIND (IRI(LCASE(CONCAT(...))))
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> PREFIX : <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?X ?N ?I ?E ?T ?C ?U WHERE { ?X rdf:type ub:Chair . ?X ub:worksFor/ub:subOrganizationOf ?U ; ub:name ?N ; ub:researchInterest ?I ; ub:emailAddress ?E ; ub:teacherOf ?T . BIND (IRI(LCASE((CONCAT(SUBSTR(STR(?X),1,10), ".",STRBEFORE(?E, "@"), "-", ?I, "-", STRAFTER(?E, "@"))))) AS ?C) FILTER ( (CONTAINS(STR(?C), "research9") || CONTAINS(STR(?C), "research12")) && ?U NOT IN (IRI("http://www.University12.edu"), IRI("http://www.University22.edu")) ) }
Query 13a — Alumni via Inverse Property
What LUBM says about it: Requires inference about inverseOf and subPropertyOf. hasAlumnus is inverse of degreeFrom, which has sub-properties (undergraduateDegreeFrom, mastersDegreeFrom, doctoralDegreeFrom).
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 }
Query 13b — Alumni via Inverse Property
From the extension's authors: Added MINUS, string replace, data type conversion, filtering and sorting.
Alumni via the inferred inverse property, MINUS those whose masters degree is from the same university; the university number is cut out of the IRI with REPLACE and xsd:integer, kept between 10 and 80, sorted.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?X ?U ?N WHERE { { ?X rdf:type ub:Person . ?U ub:hasAlumnus ?X . } MINUS { ?X rdf:type ub:Person ; ub:mastersDegreeFrom ?U . } BIND(xsd:integer(REPLACE(REPLACE(STR(?U), "http://www.University", ""), ".edu", "")) AS ?N) FILTER (?N > 10 && ?N < 80) } ORDER BY ?N LIMIT 5000
Query 14a — All Undergraduate Students
What LUBM says about it: Simplest query in the set. Large input, low selectivity. No hierarchy or inference required.
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 }
Query 14b — All Undergraduate Students
From the extension's authors: Added COUNT.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT (COUNT(?student) AS ?studentCount) WHERE { ?student rdf:type ub:UndergraduateStudent }
Rules are part of the agnos.ai extension to the original LUBM Benchmark and were created to improve the performance of queries 2 and 9. Each rule takes the triangular join that the original query performs at query time and materialises its result as a new class — ub:Type2, ub:Type9 — so the extended query becomes a lookup of that class. The agnos.ai rules page shows the same two rules in several engines' rule languages; below they are given once in an engine-neutral IF/THEN form, and then as the rule files RDF Studio ships.
In RDF Studio a rule is a SPARQL CONSTRUCT: the WHERE part is the IF, the CONSTRUCT template is the THEN, and the reasoner adds the constructed triples to the database as inferred facts. The two files live in the template's queries/rules/ folder and appear under Query ▸ Rules.
CONSTRUCT
WHERE
queries/rules/
This rule will infer a Student Type2 which matches the following conditions: a graduate student who is a member of a university which has a department where the student already has a degree from.
Engine-neutral form:
IF { ?student a ub:GraduateStudent . ?student ub:memberOf ?dept . ?dept a ub:Department . ?dept ub:subOrganizationOf ?uni . ?uni a ub:University . ?student ub:undergraduateDegreeFrom ?uni . } THEN { ?student a ub:Type2 . }
RDF Studio's rule file, queries/rules/rule-01-type2-classification.ttl:
queries/rules/rule-01-type2-classification.ttl
@prefix lubmq: <http://swat.cse.lehigh.edu/onto/univ-bench.owl/query/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dc: <http://purl.org/dc/terms/> . @prefix sp: <http://spinrdf.org/sp#> . lubmq:rule-type2-classification a sp:Construct ; rdfs:label "Rule: LUBM Type 2 Classification" ; dc:description "This rule will infer a Student Type2 which matches the following conditions: A graduate student who is a member of a university which has a department where the student already has a degree from. This is a standard LUBM benchmark rule that exercises multi-hop pattern matching across student membership, department hierarchy, and degree provenance." ; lubmq:category "Rules" ; lubmq:order 1 ; lubmq:tag "rule" ; lubmq:tag "materialization" ; lubmq:tag "lubm" ; lubmq:tag "classification" ; lubmq:sparql """PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> CONSTRUCT { ?student a ub:Type2 } WHERE { ?student a ub:GraduateStudent ; ub:memberOf ?dept . ?dept a ub:Department ; ub:subOrganizationOf ?uni . ?uni a ub:University . ?student ub:undergraduateDegreeFrom ?uni . }""" .
This rule will infer a Student Type9 which matches the following conditions: a faculty member, who is the advisor of a student, teaches a course that the student also takes. Besides the class it also records which faculty member and which course completed the triangle, as ub:hasFaculty and ub:hasCourse — the two properties extended Query 9 reads.
IF { ?student a ub:Student . ?faculty a ub:Faculty . ?course a ub:Course . ?student ub:advisor ?faculty . ?faculty ub:teacherOf ?course . ?student ub:takesCourse ?course . } THEN { ?student a ub:Type9 ; ub:hasFaculty ?faculty ; ub:hasCourse ?course . }
RDF Studio's rule file, queries/rules/rule-02-type9-student-advisor-course.ttl:
queries/rules/rule-02-type9-student-advisor-course.ttl
@prefix lubmq: <http://swat.cse.lehigh.edu/onto/univ-bench.owl/query/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dc: <http://purl.org/dc/terms/> . @prefix sp: <http://spinrdf.org/sp#> . lubmq:rule-type9-student-advisor-course a sp:Construct ; rdfs:label "Rule: LUBM Type 9 — Student-Advisor-Course" ; dc:description "This rule will infer a Student Type9 which matches the following conditions: A faculty member, who is the advisor of a student, teaches a course that the student also takes. Exercises a three-way join pattern: student-advisor relationship, student-course enrollment, and faculty-course teaching." ; lubmq:category "Rules" ; lubmq:order 2 ; lubmq:tag "rule" ; lubmq:tag "materialization" ; lubmq:tag "lubm" ; lubmq:tag "classification" ; lubmq:sparql """PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> CONSTRUCT { ?student a ub:Type9 ; ub:hasFaculty ?faculty ; ub:hasCourse ?course . } WHERE { ?student a ub:Student ; ub:advisor ?faculty ; ub:takesCourse ?course . ?faculty a ub:Faculty ; ub:teacherOf ?course . ?course a ub:Course . }""" .
Note that both rule bodies name ub:Student and ub:Faculty, which are superclasses in the LUBM ontology: a rule fires on a graduate student only once the reasoner has already inferred that the graduate student is a ub:Student. That is why the rules run as part of materialisation rather than instead of it.
ub:Student
ub:Faculty