Skip to content

Rules

Rules are known by different names across multiple triplestores, e.g. “Inference Rules”, “User-defined Rules”, "Rulesets”, and so on.

Rules define conditions to be matched in the data in order to infer new triples that become available to queries. They provide a mechanism that allows tailor-made performance improvements to specific queries. Rules are very powerful and an exclusive feature of Semantic RDF Graph Databases.

The following are the two rules that agnos.ai added to the LUBM Benchmark in order to improve the performance of queries 2 and 9.

Rule to optimise modified Query 2.

This rule will infer a Student Type2 which matches the following conditions: 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#> .
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

RULE ub:Type2
{
    ConditionsToMatch {
        ?student a ub:GraduateStudent .
        ?student ub:memberOf ?dept .
        ?dept a ub:Department .
        ?dept ub:subOrganizationOf ?uni .
        ?uni a ub:University .
        ?student ub:undergraduateDegreeFrom ?uni .
    }
    TriplesToInfer {
       ?student a ub:Type2 .
    }
}

Rule to optimise modified Query 9.

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.

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#> .

RULE ub:Type9
{
    ConditionsToMatch {
        ?student a ub:Student .
        ?faculty a ub:Faculty .
        ?course a ub:Course .
        ?student ub:advisor ?faculty .
        ?faculty ub:teacherOf ?course .
        ?student ub:takesCourse ?course .
    }
    TriplesToInfer {
        ?student a ub:Type9 ;
        ub:hasFaculty ?faculty ;
        ub:hasCourse ?course .
    }
}