Wiki
Advanced13 min read

The semantic web and ontologies

RDF triples, RDFS/OWL ontologies, SPARQL queries and inference — how knowledge graphs represent facts machines can reason over.

The web was built for people: a page links to another page, but the link means nothing to a machine beyond "follow this". The semantic web idea is to publish data in a form that carries meaning — not just documents that mention courses and students, but statements a program can combine and reason with.

The unit of that data is the triple. Everything else — ontologies, query languages, reasoning — is built on top of it.

Facts as edges, meaning as rules

A triple is subject–predicate–object, so a knowledge base is a directed, edge-labelled graph. Ontologies add rules: this class is a subclass of that one, this property points from students to courses. Reasoning is simply following those rules to derive triples nobody stored explicitly.

The widget below holds a small university ontology, toggles RDFS inference on and off, and lets you query it with a triple pattern.

A knowledge graph is a set of (subject, predicate, object) triples. Toggle RDFS inference and query it with a triple pattern.

⊑⊑⊑⊑⊑domrngdomrngtypeenrolledIntypepartOftype⊑⊑⊑typetypetypetypetypetypeStudentPersonAgentCourseAcademi…Program…Thingenrolle…partOfSarthiAI502MTechAI
23 triples

triple pattern (SPARQL-flavoured)

matches (23)

  • Student — rdfs:subClassOf → Person
  • Person — rdfs:subClassOf → Agent
  • Course — rdfs:subClassOf → AcademicThing
  • Programme — rdfs:subClassOf → AcademicThing
  • AcademicThing — rdfs:subClassOf → Thing
  • enrolledIn — rdfs:domain → Student
  • enrolledIn — rdfs:range → Course
  • partOf — rdfs:domain → Course
  • partOf — rdfs:range → Programme
  • Sarthi — rdf:type → Student
  • Sarthi — enrolledIn → AI502
  • AI502 — rdf:type → Course
  • AI502 — partOf → MTechAI
  • MTechAI — rdf:type → Programme
  • Student — rdfs:subClassOf → Agent
  • Course — rdfs:subClassOf → Thing
  • Programme — rdfs:subClassOf → Thing
  • Sarthi — rdf:type → Person
  • AI502 — rdf:type → AcademicThing
  • MTechAI — rdf:type → AcademicThing
  • Sarthi — rdf:type → Agent
  • AI502 — rdf:type → Thing
  • MTechAI — rdf:type → Thing

9 inferred triples (dashed edges), derived by RDFS rules.

A working micro-reasoner and pattern matcher over a toy ontology. Production triple stores handle millions of triples with OWL 2 profiles, SPARQL engines and provenance — the data model and the inference idea are exactly this.

Triples, IRIs and vocabularies

A triple (subject, predicate, object) uses globally unique identifiers (IRIs) so that terms from different publishers mean the same thing. A small set of standard vocabularies does most of the work:

  • RDF gives the model: subject predicate object, plus rdf:type.
  • RDFS adds schema vocabulary: rdfs:Class, rdfs:subClassOf, rdfs:domain, rdfs:range, rdfs:label.
  • OWL adds expressive logic: owl:equivalentClass, owl:disjointWith, cardinality restrictions, property characteristics (transitive, symmetric, functional).

An ontology is a set of schema triples describing a domain; the knowledge graph is the instance data plus that schema.

Inference: deriving what you did not store

RDFS entailment is a small rule set. Three rules do most of the visible work:

  1. Subclass transitivity: from (A subClassOf B) and (B subClassOf C), infer (A subClassOf C).
  2. Domain: from (p domain C) and (x p y), infer (x type C).
  3. Range: from (p range C) and (x p y), infer (y type C).

Plus type propagation: from (x type C) and (C subClassOf D), infer (x type D). Repeat to a fixed point and new triples appear that no one wrote down. OWL extends this with decidability-aware profiles (EL, QL, RL) tractable enough for real knowledge graphs.

SPARQL

Queries are graph patterns with variables. A pattern like

SELECT ?course WHERE {
  ?student :enrolledIn ?course .
  ?course rdf:type :Course .
}

matches every way of binding ?student and ?course in the store. Pattern matching over triples is the query engine; the reasoning above happens either eagerly (materialise inferred triples) or lazily during query rewriting.

Why it did not take over the web

The original vision assumed publishers would annotate everything. Incentives were weak, vocabularies multiplied, and the open-world assumption — absence of a triple is not falsity — confuses people expecting database semantics. What survived is the powerful part: knowledge graphs inside search engines, recommenders and enterprise systems, almost always with closed-world validation (SHACL) and entity linking rather than open-web annotation.

Open-world reasoning surprises

Under OWL's open-world assumption, (Sarthi type Student) does not imply Sarthi is the only student, and a missing (x type Person) does not mean x is not a person. Adding a single triple can therefore change what is entailed globally. This non-monotonic-feeling behaviour is why enterprise deployments use restricted OWL profiles and explicit validation shapes.

Illustrative vs real

The widget implements real triple storage, a small RDFS rule engine and pattern matching over a dozen triples. Real triple stores (Apache Jena, Virtuoso, Blazegraph, Neo4j's RDF layers) hold billions of triples, expose full SPARQL endpoints and support OWL profiles. The data model, the inference rules and the query-by-pattern idea are exactly those standards.

Check yourself

Eduspheria wiki · Applied AI, Social Network Analysis

0 / 5 answered

  1. 1What are the three components of an RDF statement?
    Multiple choice
  2. 2Given (enrolledIn rdfs:range Course) and (Sarthi enrolledIn AI502), RDFS entails (AI502 rdf:type Course).
    True / false
  3. 3Which W3C query language matches graph patterns over RDF triples?
    Short answer
  4. 4A store has (A subClassOf B), (B subClassOf C) and (C subClassOf D). How many subclass triples does the full transitive closure contain including the original three?
    Numeric answer
  5. 5Under the open-world assumption, if a triple is absent from the store it means…
    Multiple choice

From the exam paper

Modeled on NITJ AI-603, End-Sem May 2025

0 / 5 answered

  1. 1Using a single directed predicate between the two people in each fact, how many RDF triples state: Alice is a friend of Bob, Bob works with Charlie, and Alice and Charlie share a research project?
    Multiple choice
  2. 2In an RDF triple (subject, ?, object), what is the middle term called?
    Short answer
  3. 3From (Alice type Student) and (Student subClassOf Person), RDFS entails (Alice type Person).
    True / false
  4. 4Which capability lets a university collaboration ontology derive a fact such as 'researchers A and B are strong collaborators' when no such triple was stored?
    Multiple choice
  5. 5Under the open-world assumption, a missing triple is interpreted as false.
    True / false

Where next: from networks of people and facts to networks of pixels and physiology — medical imaging and wearables.