Semantic Data Solutions
Semantic Data Solutions
Semantic Data Solutions
1. Syntax of FOL
Suggested exercise 1 : which sentences are well formed FOL formulas or terms ?
Non logical symbols: constants a, b, functions f1, g2, predicates P1, R2, Q3 (with indicated arity).
2) ∃x R(x, y) y free
For any car on any highway road under normal conditions, fast speed is allowed.
Sometimes, either I don't travel anywhere or I travel far from the city I live in.
2) No two adjacent countries have the same map color. (this sentence requires equality).
5) Doctors sue back if they are sued. ∀x (doctor(x) → ∀y (sue(y, x)) → sue(x, y)))
4) Everything that is free has nothing on it. ∀x (Free(x) → ¬∃y On(y, x))
4. Manipulating formulas
Suggested exercise 1 : convert in conjunctive normal form
1) ¬ (¬p ∨ q) ∨ (r → ¬s)
2) p → (q ∧ r)
¬p ∨ (q ∧ r) NNF
(¬p ∨ q) ∧ (¬p ∨ r) CNF
3) p → (q → r)
4) (p → q) → r
(¬p ∨ q) → r
¬ (¬p ∨ q) ∨ r
(p ∧ ¬q) ∨ r NNF
(p ∨ r) ∧ (¬q ∨ r) CNF
5) (¬p → (p → q))
¬ ¬p ∨ (¬p ∨ q)
p ∨ ¬p ∨ q
True NNF and CNF
6) (p → (q → r)) → (p → (r → q))
¬ (¬p ∨ ¬q ∨ r) ∨ (¬p ∨ ¬r ∨ q)
(p ∧ q ∧ ¬r) ∨ (¬p ∨ ¬r ∨ q) NNF
(p ∨ ¬p ∨ ¬r ∨ q) ∧ (q ∨ ¬p ∨ ¬r ∨ q) ∧ (¬r ∨ ¬p ∨ ¬r ∨ q)
(¬r ∨ q) ∧ (q ∨ ¬p ∨ ¬r) ∧ (¬r ∨ ¬p ∨ q)
q ∨ ¬p ∨ ¬r CCF
Suggested exercise 2 : convert in prenex conjunctive normal form
∃z (∃x Q(x, z) ∨ ∃x P(x)) → ¬(¬∃x P(x) ∧ ∀x ∃z Q(z, x))
∃z (∃x Q(x, z) ∨ ∃x P(x)) → ¬(¬∃x P(x) ∧ ∀x ∃z Q(z, x)) eliminating « → »
¬ ∃z (∃x Q(x, z) ∨ ∃x P(x)) ∨ ¬(¬∃x P(x) ∧ ∀x ∃z Q(z, x)) importing negations
∀z ¬ (∃x Q(x, z) ∨ ∃x P(x)) ∨ (¬¬∃x P(x) ∨ ¬∀x ∃z Q(z, x))
∀z (¬∃x Q(x, z) ∧ ¬∃x P(x)) ∨ (∃x P(x) ∨ ∃x ∀z ¬ Q(z, x))
∀z (∀x ¬Q(x, z) ∧ ∀x ¬P(x)) ∨ (∃x P(x) ∨ ∃x ∀z ¬Q(z, x))
∀z ∀x (¬Q(x, z) ∧ ¬P(x)) ∨ ∃x (P(x) ∨ ∀z ¬Q(z, x)) renaming to pull quantifiers in front
∀z ∀x ∃y ∀w ((¬Q(x, z) ∧ ¬P(x)) ∨ (P(y) ∨ ¬Q(w, y))) prenex DNF
∀z ∀x ∃y ∀w ((¬Q(x, z) ∨ P(y) ∨ ¬Q(w, y)) ∧ (¬P(x) ∨ P(y) ∨ ¬Q(w, y))) prenex CNF
1) Q(f(Z)) True
2) R(X, Y) False
3) ∀w R(f(w), w) True
a)
On I= {<b1, b4>; <b4, b3>; <b3, table>; <b5, b2>; <b2, table>}
Above I = {<b1, b4>; <b1, b3>; <b1, table>; <b4, b3>; <b4, table>; <b3, table>; <b5, b2>; <b5,
table>; <b2, table>}
b)
Three students, Pierre, Jean and Marie are living in Liège, located in Belgium. They collectively
follow the course of Logic, given by Willard Quine.
Each student lives individually in Liège but they follow collectively the course. A possible solution
is to use a bag for the fact that they follow collectively the course :
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://example.org/myVocabulary/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
:Pierre :livesin :Liège .
:Jean :livesin :Liège .
:Marie :livesin :Liège .
:Liège a :city; :locatedin :Belgium .
[ a rdf:Bag ;
rdf:_1 :Pierre ;
rdf:_2 :Jean ;
rdf:_3 :Marie
] :follows _:x .
_:x a :course ; dc:title "Logic" .
:WilliamQuine :gives _:x .
Suggested exercise 4 : model the following graph in RDF Turtle, using appropriate
vocabularies and prefixes :
A possible solution is :
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://example.org/myVocabulary/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
Solution :
From exercise 1 :
Person ⊓ Happy Person(x) ∧ Happy(x)
Person ⊓ Happy ⊓ ∃owns.Pet Person(x) ∧ Happy(x) ∧ ∃y ((owns(x, y) ∧ Pet(y))
Person ⊓ ∀owns.Cat Person(x) ∧ ∀y(owns(x, y) → Cat(y))
Person ⊓ ¬Happy ⊓ ∃owns.(Cat ⊓ Old)
Person(x) ∧ ¬ Happy(x) ∧ ∃y ((owns(x, y) ∧ Cat(y) ∧ Old(y))
Person ⊓ ∃owns.Pet ⊓ ∀owns.(Cat ⊔ Fish)
Person(x) ∧ ∃y ((owns(x, y) ∧ Pet(y)) ∧ ∀z (owns(x, z) → Cat(z) ∨ Fish(z))
From exercise 2 :
Tree ⊆ Plant. ∀x (Tree (x) → Plan(x))
Branch ⊆ ∀partOf.Tree ∀x (Branch(x) → ∀y (partOf(x, y) → Tree(y))
Leaf ⊆ ∀partOf.Branch ∀x (Leaf(x) → ∀y (partOf(x, y) → Branch(y))
Herbivore ≡ Animal ⊓ ∀eats.(Plant ⊔ ∀partOf.Plant)
∀x (Herbivore(x) ↔ Animal(x) ∧ ∀y (eats(x, y) → Plant(y) ∨ ∀z (partOf(y, z) → Plant(z))))
Carnivore ≡ Animal ⊓ ∃eats.Animal
∀x (Carnivore(x) ↔ Animal(x) ∧ ∃y (eats(x, y) ∧ Animal (y)))
Giraffe ⊆ Herbivore ⊓ ∀eats.Leaf
∀x (Girafe(x) → Herbivore(x) ∧ ∀y (eats(x, y) → Leaf(y)))
Lion ⊆ Carnivore ⊓ ∀eats.Herbivore
∀x (Lion(x) → Carnivore(x) ∧ ∀y (eats(x, y) → Herbivore(y)))
TastyPlant ⊆ Plant ⊓ ∃isEatenBy.Herbivore ⊓ ∃isEatenBy.Carnivore
∀x (TastyPlant(x) → Plant(x) ∧ ∃y (isEatenBy(x, y) ∧ Herbivore (y)) ∧ ∃z (isEatenBy(x, z) ∧
Carnivore(z)))
From exercise 3 :
(Bob, QE2) : controls controls(Bob, QE2)
Bob : (∃controls.Car) ∃x (Car(x) ∧ controls(Bob, x))
QE2 : (Vehicle ⊓ ∃travelsOn.Water) Vehicle(QE2) ∧ ∃x (Water(x) ∧ travelsOn(QE2, x))
3. Interpretations / models
Suggested exercise 1 : is the following interpretation a model of the knowledge
base from section 2 – exercise 4, repeated below ? Justify.
Please refer to the practice slides for the definition of the knowledge base and the interpretation.
Answer : yes.
In this model, there are more cars, more drivers, and more humans than what is strictly required
by the knowledge base. Also, there are two cars sharing a wheel, and cars with a single wheel
only, and there are no bicycles, leaving that axiom satisfied by default.
However, this interpretation clearly satisfies all statements in the knowledge base and is
therefore a model of it.
Suggested exercise 2 : consider the following interpretation :
I : ΔI = {t1, t2, f1, f2, p1, p2, j, k, l, m, n}
AnimalI = {j, k, l, m, n}
PlantI = {t1, t2, f1, f2, p1, p2}
FernI = {f1, f2}
TulipI = {t1, t2}
eatsI = {(j, f1), (k, f1), (k, t2), (l, p1), (l, p2), (m, p1), (m, t2), (n, f2), (n, p2)}
Find the interpretation in I of the following concepts:
a) ∃eats.Fern ⊓ ∃eats.Tulip
b) ∃eats.Fern ⊓ ∀eats.Fern
c) ∃eats.Fern ⊓ ∃eats.¬Fern
d) ∃eats.Plant ⊓ ∀eats.¬(Tulip ⊔ Fern)
Solution (note that if you are only given the above concepts you cannot assume that ferns and
tulips are plants):
a) {k}
b) {j}
c) {k, n}
d) {l}
Suggested exercise 3 :
Suppose Manager and Project are concept names and manages is a role name. For each of the
following expressions φ:
i. state whether it is an ALC concept, an ALC concept inclusion or none of the above.
ii. if φ is a concept inclusion, check whether φ follows from the empty TBox (i.e., ∅ ⊨ φ). If
this is not the case, define an interpretation I such that I ⊭ φ.
if φ is a concept, check whether φ is satisfiable. If so, define an interpretation I such that φ I ≠ ∅ .
a) Manager ⊆ ∃ manages.⊥
i) concept inclusion.
ii) is not valid : ΔI={a,b}; managesI ={(a,b)}; ManagerI ={a}.
In fact, ∃ manages.⊥ is unsatisfiable (always empty!)
b) ( 7 manages.⊤) ⊆ Manager
states that anybody who manages at least 7things is a manager.
i) not an ALC concept nor ALC concept inclusion (because of the numerical quantification). It is
however a concept inclusion in an extension of ALC.
ii) is not valid : ΔI={a,b1, … , b7}; ManagerI = ∅; managesI ={(a,b1), …, (a, b7 }
c) ( 8 manages.Project) ⊆ Manager
states that anybody who manages at least 8 projects is a manager.
i) not an ALC concept nor ALC concept inclusion. It is however a concept inclusion in an extension
of ALC.
ii) is not valid : ΔI={a,b1, … , b8}; ManagerI = ∅; managesI ={(a,b1), …, (a, b8}; ProjectI = { b1, … , b8}
d) ∀manages.⊤ ⊆ ∃manages.Project
states “everything manages a project" because ∀manages.⊤ = ΔI for all interpretations.
i) concept inclusion.
ii) is not valid : ΔI={a}; managesI = ∅ , ProjectI = ∅
e) ∃manages.⊤ ⊆ ( 4 manages.⊤ )
i) concept inclusion.
f) ( 4 manages.⊤ ) ⊆ ∃manages.⊤
states that “everybody managing at least four things manages something".
i) concept inclusion.
ii) it is valid.
Practice 7. SPARQL
2. Querying DBpedia
In the following exercises all namespace declarations are already defined in the SNORQL
endpoint, except the one for dbo : which must be added.
DBPedia SNORQL endpoint to test DBPedia queries : http://dbpedia.org/snorql/
(select XML output).
Suggested exercise 1
a) Find all information on Steve Jobs.
describe :Steve_Jobs
Suggested exercise 2
a) Find all books published in 1970.
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE
{
?book a dbo:Book .
?book dbpedia2:pubDate 1970 .
?book dbo:publisher ?publisher .
}
c) For the books found in b), find their publication date and sort and count them by
publication date.
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?date (COUNT(?book) AS ?count)
WHERE
{
?book a dbo:Book .
?book dbo:author :Jules_Verne .
?book dbpedia2:pubDate ?date .
} ORDER BY ASC(?date)
Practice 8. Reasoning with description logics
1. Structural subsumption
Suggested exercise 1 : check if the following subsumptions are valid
a) Adult ⊓ (Male ⊓ Rich) ⊆ Adult ⊓ Male
The GCI needs to be transformed into a disjunction before calling the tableau algorithm :
¬Human ⊔ ∃hasParent.Human
That expression is in negative normal form.
All branches have led to clashes and there are no rules left to apply. The input concept is
unsatisfiable; hence the initial subsumption holds.
Suggested exercise 2
A satisfying model is : ΔI = {a, b, c, x, y, AI = {a}, BI = {b}, CI = {c}, FI = {x}, DI = {y}, rI = {(a, c)}, sI =
{(a, b), (a, x), (c, y)}
Suggested exercise 3
Given the knowledge base K with
T = {A ⊑ B, B ⊑ C, C ⊑ ∃r.D, D ⊑ ¬A, A ⊑ ∀r.A }
A = {a : A, c : D, (a, b) : r, (b, c) : r}
Check if K is consistent and if so provide a model for K.
A0 = {a : A; c : D; (a, b) : r; (b, c) : r}
→GCI A1 = A0 ∪ {a : B}
→GCI A2 = A1 ∪ {a : C}
→GCI A3 = A2 ∪ {a : ∃r.D}
→∃ A4 = A3 ∪ {(a, x) : r; x : D}
→GCI A5 = A4 ∪ {x : ¬A}
→GCI A6 = A5 ∪ {c : ¬A}
→GCI A7 = A6 ∪ {a : ∀r.A }
→∀ A8 = A7 ∪ {b : A}
→GCI A9 = A8 ∪ {b : B; b : C}
→∃ A10 = A9 ∪ {(b, y) : r; y : D} y blocked by x
→∀ A11 = A7 ∪ {c : A} clash
→∀ A11 = A7 ∪ {x : A} clash