What Is Inference?
Inference (also called reasoning or entailment) is the process of automatically deriving new facts from existing ones, based on logical rules defined in your ontology.
If you know:
- alice rdf:type Employee
- Employee rdfs:subClassOf Person
Then an inference engine can automatically conclude: 3. alice rdf:type Person ← inferred, not explicitly stated
This is powerful because you only need to assert the most specific facts — the general ones follow automatically.
Nodes
- Employeeclass
Class: Employee
- Personclass
Class: Person
- Agentclass
Class: Agent
- aliceinstance
Instance: alice
Edges
- Employeerdfs:subClassOfPerson
- Personrdfs:subClassOfAgent
- alicerdf:typeEmployee
RDFS Inference Rules
RDFS defines a set of entailment rules — if certain patterns exist in the graph, new triples can be derived:
| Rule | Pattern | Inferred |
|---|---|---|
| rdfs2 | ?p rdfs:domain ?C . ?x ?p ?y . | → ?x rdf:type ?C |
| rdfs3 | ?p rdfs:range ?C . ?x ?p ?y . | → ?y rdf:type ?C |
| rdfs9 | ?x rdfs:subClassOf ?y . ?z rdf:type ?x . | → ?z rdf:type ?y |
| rdfs11 | ?x rdfs:subClassOf ?y . ?y rdfs:subClassOf ?z . | → ?x rdfs:subClassOf ?z |
| rdfs7 | ?p rdfs:subPropertyOf ?q . ?x ?p ?y . | → ?x ?q ?y |
Rule rdfs9 is the one that infers "alice is a Person" from "alice is an Employee and Employee subClassOf Person". Rule rdfs11 makes subClassOf transitive — if A ⊆ B and B ⊆ C, then A ⊆ C.
OWL Inference
OWL adds many more inference rules beyond RDFS:
Inverse Properties
If ex:worksFor owl:inverseOf ex:employs:
- Alice worksFor Acme → Acme employs Alice (inferred)
Transitive Properties
If ex:locatedIn a owl:TransitiveProperty:
- London locatedIn England, England locatedIn UK → London locatedIn UK (inferred)
Symmetric Properties
If foaf:knows a owl:SymmetricProperty:
- Alice knows Bob → Bob knows Alice (inferred)
Equivalent Classes
If ex:Employee owl:equivalentClass schema:Employee:
- Any ex:Employee is also a schema:Employee (inferred)
import org.apache.jena.rdf.model.*;
import org.apache.jena.reasoner.*;
import org.apache.jena.reasoner.rdfsReasoner.*;
// Load base graph
Model base = ModelFactory.createDefaultModel();
base.read("knowledge_graph.ttl", "TURTLE");
// Load ontology (T-Box)
Model schema = ModelFactory.createDefaultModel();
schema.read("schema.ttl", "TURTLE");
// Create RDFS reasoner
Reasoner reasoner = RDFSRuleReasonerFactory.theInstance()
.create(null);
reasoner = reasoner.bindSchema(schema);
// Apply reasoning
InfModel infModel = ModelFactory
.createInfModel(reasoner, base);
// Inferred triples are now available
System.out.println("Inferred triples: " + infModel.size());
// Query inferred facts
StmtIterator it = infModel.listStatements(
null, RDF.type, null
);
while (it.hasNext()) {
Statement s = it.next();
System.out.println(s);
}Forward vs Backward Chaining
Reasoners use one of two strategies:
Forward Chaining (Data-Driven)
- Start with known facts, apply all applicable rules, generate new facts
- Repeat until no new facts can be derived (fixpoint)
- Result: a materialized set of all inferred facts
- ✅ Fast at query time (facts pre-computed)
- ❌ Slow at load time; large materialized graph
Backward Chaining (Goal-Driven)
- Start with a query/goal, work backwards to find supporting facts
- Only compute what's needed to answer the query
- ✅ No pre-computation; handles large rule sets
- ❌ Slower at query time for complex queries
Most production triple stores use a hybrid approach or configurable materialization strategies.
Knowledge check
Given: "alice rdf:type Employee" and "Employee rdfs:subClassOf Person", what does RDFS inference conclude?
Summary
In this chapter you learned:
- Inference automatically derives new facts from existing ones using ontology rules
- The Open World Assumption makes reasoning possible — unknown ≠ false
- RDFS inference rules (rdfs9, rdfs11) handle class hierarchies and property hierarchies
- OWL adds inverse, transitive, symmetric, and many more inference rules
- Forward chaining pre-computes all facts; backward chaining computes on-demand
In the final chapter, we'll see how all these concepts come together in real-world use cases.