SENG-42273 · Semantic Web & Ontology

Build a Movie Knowledge Graph

Create a complete Semantic Web application using real movie data from DBpedia and Wikidata. Design ontologies, write SPARQL queries, perform reasoning, and build visualizations.

4–6 Hours Real Data Linked Data Reasoning

Phase I — Domain Analysis

Before building, understand the movie domain thoroughly.

Learning Objectives
  • Analyze movie domain entities
  • Identify classes and properties
  • Explore existing vocabularies
  • Map concepts to RDF
Domain Entities
Entities

Movie, Person, Director, Actor, Genre, Studio

Relationships

directedBy, starring, hasGenre, producedBy

Attributes

title, releaseDate, runtime, budget, rating

Vocabularies

schema.org, DBpedia, FOAF, Wikidata

Why Reuse Vocabularies?

  • Enables interoperability with other datasets
  • Provides established semantics
  • Allows federated queries
  • Follows Linked Data best practices

Exercise — Domain Mapping

  1. A movie can have multiple actors — what property type is this?
  2. A director directs movies — should this be functional?
  3. How would you model the "sequel of" relationship?

Phase II — Design Ontology

Create a formal ontology using RDFS and OWL.

Complete the Ontology

  1. Add :Director and :Actor as subclasses of :Person
  2. Add :Genre class
  3. Define :directedBy, :starring, :hasGenre properties
  4. Add domain/range constraints
  5. Make :directedBy functional with inverse
Ontology Editor
Turtle

Phase III — Query DBpedia

Query real Linked Data from DBpedia.

About DBpedia

DBpedia extracts structured data from Wikipedia. It contains millions of entities including movies, people, and places — all available as Linked Data.

SPARQL Queries
SPARQL
Open in DBpedia →

Exercise

  1. Find all movies released in 2023
  2. Get the top 10 highest-budget films
  3. Find movies sharing actors with "Inception"

Phase IV — Build Dataset

Create instance data and link to external sources.

Linking to External Data

Use owl:sameAs to link your entities to DBpedia and Wikidata for seamless data integration across the Linked Data cloud.

Movie Dataset
Turtle

Extend the Dataset

  1. Add 2 more movies with all properties
  2. Add a new actor who appears in multiple films
  3. Add owl:sameAs links to DBpedia

Phase V — Reasoning

Understand how reasoners derive new knowledge.

RDFS Inference Rules
Subclass Transitivity

If A ⊆ B and B ⊆ C, then A ⊆ C

:Director rdfs:subClassOf :Person .
:nolan a :Director .
# → :nolan a :Person
Domain Inference

If P has domain C, x P y → x ∈ C

:directedBy rdfs:domain :Movie .
:inception :directedBy :nolan .
# → :inception a :Movie
Range Inference

If P has range C, x P y → y ∈ C

:directedBy rdfs:range :Director .
:inception :directedBy :nolan .
# → :nolan a :Director
Inverse Properties

If P inverseOf Q, x P y → y Q x

:directedBy owl:inverseOf :directed .
:inception :directedBy :nolan .
# → :nolan :directed :inception

Open World Assumption

In Semantic Web, missing data is unknown, not false. This differs fundamentally from traditional databases.

  • Missing information ≠ Non-existence
  • Use owl:complementOf for explicit negation
  • Use SPARQL NOT EXISTS for closed-world queries
Inference Examples
Asserted FactRuleInferred Fact
:nolan a :Directorrdfs:subClassOf:nolan a :Person
:inception :directedBy :nolanowl:inverseOf:nolan :directed :inception
:inception :starring :dicapriordfs:range:dicaprio a :Actor

Reasoning Practice

  1. What's inferred if :Studio rdfs:subClassOf :Organization?
  2. If :hasSequel is transitive, and A hasSequel B, B hasSequel C — what's inferred?
  3. How would you detect someone who is both a Director and Actor?

Phase VI — SPARQL Analytics

Write advanced analytical SPARQL queries.

Analytics Queries
SPARQL

SPARQL Analytics Features

Aggregates

COUNT, SUM, AVG, MIN, MAX, GROUP_CONCAT

Grouping

GROUP BY, HAVING for filtering groups

Subqueries

Nested SELECT for complex logic

Path Queries

Property paths: *, +, ?, |, / operators

Write Queries

  1. Find the director with the highest average movie rating
  2. List actors who have worked with multiple directors
  3. Calculate total budget per genre per year

Phase VII — Visualization

Build an interactive knowledge graph visualization.

Knowledge Graph
Movie
Director
Actor
Genre

Congratulations!

You've completed the hands-on project. You now have practical experience with:

  • Designing ontologies with RDFS and OWL
  • Querying real Linked Data from DBpedia
  • Creating and validating RDF datasets
  • Understanding semantic reasoning and inference
  • Writing analytical SPARQL queries
  • Visualizing knowledge graphs