Compilation of Problems KMST
December 4, 2022 | Author: Anonymous | Category: N/A
Short Description
Download Compilation of Problems KMST...
Description
Knowledge Modeling and Semantic Technology
Compilation of Problems
Plaban Kumar Bhowmick
I NDIAN I NSTITUTE OF T ECHNOLOGY K HARAGPUR , I NDIA After teaching this course for few years, I felt the necessity of having a more or less comprehensive compilation of the problems in the Semantic Web Technology domain. This compilation has been created based on various resources from the Internet mostly from different courses on Knowledge Representa Repre sentation tion and Semantic Semantic Web Web around around the world. It is very hard to acknowled acknowledge ge individual individual contributions. However, this compilation would not have been possible without them. First release, August 2018
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
2 Knowledge Representation and FOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.1 English Sentence to FOL Statement
7
2.2 Are These Valid?
2.3 FOL Interpretations: 2.4 FOL Reasoning
12
13
19
Framework ork (RDF) . . . . . . . . . . . . . . . . . . . . . . . . . 3 Resource Description Framew
25
Web b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Querying Semantic We
41 41
4.2 SPARQL SPARQL Algebra & Evaluation
46
4.1 SPARQL SPARQL Query
5 Description Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
51
6 Web Ontology Language (OWL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
7 Ontology Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
55
1. Introduction
2. Knowledge Representation and FOL
2.1 English Sen Sentence tence to FOL Statement Some boys boys are sharp sharp and intell intellige igent nt Exercise 2.1 Some
Solution 2.1 ∃ x(Sharp( x) ∧ Boy( x) ∧ Int ell igent ( x))
boys s are intell intellige igent nt Exercise 2.2 Not all boy
Solution 2.2 There are two alternatives:
¬∀ x( Boy( x) =⇒ Intelligent ( x))
or
∃ x( Boy( x) ∧ ¬ Int ell igent ( x))
Some studen students ts of KMST KMST course course has got placed placed in Google Google and rest rest Exercise 2.3 Some has been been placed placed in Facebo Facebook ok
Solution 2.3 First we find the students who have been placed in Google and ’rest’ is modeled with equality (inequality predicate)
∃ x[Student ( x) ∧ placed InGoogl e( x) ∧ ∀ y( x = y) =⇒ placedInFaceBook ( y)]
8
Chapter 2. Knowledge Representation and FOL
always milk, whereas the milk is always white. Exercise 2.4 Some thing that is white is not always
Solution 2.4
∃ x(White( x) ∧ ¬ Mil k ( x)) ∧ ∀ y( Mil k ( y) =⇒ White( y))
Exercise 2.5 Break Breakfa fast st is se serv rved ed in me mess ss on al all l da days ys be betw twee een n 7a 7am m an and d 9a 9am m
ex exce cept pt Sunda Sunday. y.
An And, d, on Su Sund nday ays s it is se serv rved ed till till 10 am.
Solution 2.5
∀ x[Weekday( x) =⇒ break break f astServred astServred 7To 9( x)] ∧ ∀ x[ x x = Sunday bear ar f as astServ tServed ed 7t o10( x)] =⇒ be
Exercise 2.6 Everyb Everybody ody has a father father. . Solution 2.6
∀ x ∃ y Father ( y, x)
Nobody y ca can n be a fa fath ther er of hi hims msel elf f Exercise 2.7 Nobod
Solution 2.7
¬∃ x Father ( x, x)
Exercise 2.8 If somebody is a father of somebody else, then the latter cannot be a father of the former Solution 2.8
∀ x ∀ y Father ( x, y) ⇐⇒ ¬Father ( y, x)
Exercise 2.9 Everyb Everybody ody has at most most one father father. .
2.1 English Sentence to FOL Statement
9
Solution 2.9
∀ xyz Father ( y, x) ∧ Father ( z, x) =⇒ ( y = z )
Exercise 2.10 Represent the following statements into FOL:
1. Every Every A-type A-type obj object ect is attach attached ed to some some object object. . 2. No A-t A-type ype object object can be attach attached ed to an A-type A-type object. object. 3. An ob obje ject ct ro rota tate tes s if no ob obje ject ct is at atta tach ched ed to it it. . 4. Ther There e is on one e BB-ty type pe ob obje ject ct wi with th a fl flat at to top. p.
Solution 2.10 Following are the FOL sentences: S1: ∀ x A( x) =⇒ ∃ y attachedTo( x, y) S2: ¬∃ x ∃ y A( x) ∧ A( y) ∧ attachedTo ( x, y) S3: ∀ x (¬∃ y attachedTo ( y, x)) =⇒ Rotates( x) S4a: ∃ x B( x) ∧ f la latTop tTop( x) S4a: ¬∃ x ∃ y B( x) ∧ B( y) ∧ f la latTop tTop( x) ∧ f la latTop tTop( y) ∧ ( x = y)
Exercise 2.11 Represent the following sentences in FOL: 1. Some Some studen students ts took took KMST KMST in autumn autumn 2018. 2018. 2. Every Every studen student t who tak takes es KMST KMST passes passes it. 3. Only one studen student t took took Hie Hierog roglyp lyphic hics s in spring spring 2018. 2018. 4. The best best score score in Hierog Hieroglyp lyphic hics s is always always higher higher than than the best best score score
in KMST. KMST.
Solution 2.11 The FOL statements are as follows: S1: ∃ x Student ( x) ∧ Takes( x, KMST , Autumn2018) S2: ∀ x , s Stude tuden nt ( x) ∧ Takes( x, KMST , s) =⇒ Passes( x, KMST , s) S3: ∀ x ∃ y Student ( y) ∧ Takes( y, Hi Hierogly erogly phics, Spring2018) ∧ ( x = y) =⇒ ¬Takes( x, Hi Hierogly erogly phics, Spring2018) S4: ∀ x ∀ y ∀s Score( x, H Hierogly ierogly phics, s) > Score( y, KMST , s)
following sentences into FOL statements: Exercise 2.12 Translate the following 1. Every Every pe pers rson on wh who o bu buys ys a po poli licy cy is sm smar art. t. 2. No per person son buy buys s an expens expensive ive pol policy icy. . 3. Ther There e is an ag agen ent t wh who o se sell lls s po poli lici cies es on only ly to pe peop ople le wh who o ar are e no not t
insured.
10
Chapter 2. Knowledge Representation and FOL
Solution 2.12 The FOL statements are as follows: S1: ∀ x Person( x) ∧ (∃ p, z z Buys( x, p, z)) =⇒ Smart ( x) E x pensive( y) =⇒ ¬ Buys( x, y, z) S2: ∀ x, yy, z z Person( x) ∧ Policy( y) ∧ Ex S3: ∃a ∀ y, z z Agent (a) ∧ Sells(a, y, z) =⇒ (Person( z) ∧ ¬ Insured ( z))
following sentences into FOL statements: Exercise 2.13 Translate the following 1. A person born in the UK, each of whose parents is a UK citizen or a
UK re resi side dent nt, , is a UK ci citi tize zen n by bi birt rth. h. 2. A pe pers rson on bo born rn ou outs tsid ide e th the e UK UK, , on one e of wh whos ose e pa pare rent nts s is a UK ci citi tize zen n by birth, bir th, is a UK citize citizen n by descen descent. t.
Solution 2.13 The FOL statements are as follows: =⇒ ∃r Citizen( y, U K , r ) ∨ S1: ∀ x Person( x) ∧ Born( x, U K ) ∧ [∀ y Parent ( y, x) Resident ( y, U K )] )] Birth h) =⇒ Citizen( x, U K , Birt S2: ∀ x Person( x) ∧ ¬ Born( x, U K ) ∧ [∃ y Parent ( x, y) ∧ Citizen( y, U K , Birt Birth h)] =⇒ Citizen( x, U K , Descent )
following sentences into FOL statements: Exercise 2.14 Translate the following 1. Ther There e is at le leas ast t on one e st stud uden ent t wh who o do does esn’ n’t t ha hate te (a (any ny of of) ) th the e AI
homework. 2. Cats Cats rule rule and dogs dogs drool. drool. 3. All All the bases that belonged belonged to Captai Captain n now belong belong to CATS CATS 4. There There is only only one Superman Superman in the Universe Universe. . 5. Ever Every y ch chil ild d wh who o ha has s a Po Poke kemo mon n ca card rd is co cool ol. .
Solution 2.14 The FOL statements are as follows: S1: ∃s ∀h Student (s) ∧ Hom Homework ework (h, AI ) ∧ ¬ H Hates ates (s, h) S2: ∀ x (Cat ( x) =⇒ Rules( x)) ∧ ( Dog( x) =⇒ Drools( x)) S3: ∀b ∀t Base(b) ∧ BelongsTo(b, Captain, t ) ∧ IsBefore(t , now) BelongsT o(b, CATS , now) S4: ∃ x Superman( x, Universe) ∧ (∀ y Superman ( y, Universe) =⇒ x = y) S5: ∀c, p Child (c) ∧ PokemonCard ( p), Owns(c, p) =⇒ Cool (c)
=⇒
following sentences into FOL statements: Exercise 2.15 Translate the following 1. Every Every student student loves loves some stud student. ent. 2. Every Every studen student t loves loves some some oth other er studen student. t. 3. There There is a st stud uden ent t wh who o is lo love ved d by ev ever ery y ot othe her r st stud uden ent. t.
2.1 English Sentence to FOL Statement
11
4. Every Every studen student t takes takes at least least one cou course rse. . 5. Only Only one student student failed failed Geometry Geometry. . 6. No stu studen dent t failed failed Geo Geomet metry ry but at least least one studen student t failed failed Analys Analysis. is.
Solution 2.15 The FOL statements are as follows: S1: ∀ x Student ( x) =⇒ ∃ y Student ( y) ∧ Loves( x, y) S2: ∀ x Student ( x) =⇒ ∃ y Student ( y) ∧ Loves( x, y) ∧ ¬( x = y) S3: ∃ x Student ( x) ∧ ∀ y [Student ( y) ∧ ¬( x = y) =⇒ Loves( y, x)] S4: d ∀ x Student ( x) =⇒ ∃ y Course( y) ∧ Takes( x, y) S5: ∃ x Student ( x) ∧ Failed ( x, Geometry) ∧ [∀ y Student ( y) ∧ Failed ( x, Geometry) =⇒ ( x = y)] S6: [¬∃ x Student ( x) ∧ Failed ( x, Geometry)] ∧ [∃ y Student ( y) ∧ Failed ( y, Analysis )]
following sentences into FOL statements: Exercise 2.16 Translate the following 1. A is above C, D is on E and above F. 2. A is green while C is not. 3. Everythi Everything ng is on something something. . 4. Every Everythi thing ng that that is free free has nothing nothing on it. 5. Everyt Everythin hing g that that is green green is free. free. 6. Ther There e is so some meth thin ing g th that at is re red d an and d is no not t fr free ee. . 7. Ever Everyt ythi hing ng th that at is no not t gr gree een n an and d is ab abov ove e B, is re red. d.
symbols to be: Solution 2.16 Let us consider the symbols • Constants: A , B , C , D , E , F • Predicates: On( x, y), Above( x, y), Free( x), Red ( x), Green( x) The FOL statements are as follows: S1: Above( A, C ) ∧ Above( D, E ) ∧ On( D, F ) S2: Green( A) ∧ ¬Green(C ) S3: ∀ x ∃ y On( x, y) S4: ∀ x Free( x) =⇒ ¬∃ y On( y, x) S5: ∀ x Green( x) =⇒ Free( x) S6: ∃ x Red ( x) ∧ ¬Free( x) S7: ∀ x ¬Green( x) ∧ Above( x, B) =⇒ Red ( x)
Exercise 2.17 Translate the following sentence into FOL statement:
Po Poli liti tici cian ans s ca can n fo fool ol so some me of th the e pe peop ople le al all l of th the e ti time me, , an and d th they ey ca can n fo fool ol al all l of th the e pe peop ople le so some me of th the e ti time me, , bu but t th they ey ca can’ n’t t fo fool ol al all l of th the e pe peop ople le al all l of th the e ti time me. .
12
Chapter 2. Knowledge Representation and FOL
Solution 2.17 The FOL statement is as follows:
∀ x Politician ( x) =⇒
[∃ p ∀t Person( p) ∧ Time(t ) ∧ MakeFool ( x, p, t ))]] [∀ p Person( p) =⇒ (∃t Time(t ) ∧ MakeFool ( x, p, t ))]] [∃ p ∃t Person(t ) ∧ Time(t ) =⇒ ¬ MakeFool ( x, p, t ))]]
The sp spee eed d of li ligh ght t is no not t sa same me in al all l me medi dium ums. s. Exercise 2.18 The
Solution 2.18 There are two solutions: 1) Solution 1 states that it is not true that for any given pair of mediums speed of light is same, 2) Solution 2 represents that there exists at least one pair of distinct mediums where the speed of light is different. different.
¬∀ x∀ y( Med Medium ium( x) ∧ Med Medium ium( y) ∧ ( x = y) =⇒ Speed ( x) = S pee peed d ( y)) ∃ x∃ y( Med Medium ium( x) ∧ Med Medium ium( y) ∧ ( x = y) ∧ (Speed ( x) = S pee peed d ( y)))
or
Exercise 2.19 In a group of five people (where any two people are either friends or enemies), there are not necessarily three mutual friends or three mutual enemies. Solution 2.19 Here we make use of special syntax that is not directly suppo supported rted by FOL. The following follo wing syntax is introduced to shorten the formula. formula. For example example yi = y j , 1 ≤ i < j ≤ 5 is a short notation of ( ( y1 = y2 ) ∧ ( y1 = y3 ) ∧ ( y1 = y 4 ) ∧ ( y1 = y5 ) ∧ ( y2 = y3 ) ∧ ( y2 = y 4 ) ∧ ( y2 = y5 ) ∧ ( y3 = y4 ) ∧ ( y3 = y5 ) ∧ ( y4 = y5 )
¬∀ y1 y2 y3 y4 y5 [( yi = y j , 1 ≤ i < j ≤ 5 ∧ ∀1≤k ≤5 People( yk )) =⇒ {∃1≤u,v,w≤5 (( yu = yv = yw ) ∧ Mut MutualF ualFriend riendss( yu , yv , yw ))∨ MutualE ualE nemies( yu , yv , yw ))}] exists 1≤u,v,w≤5 (( yu = yw ) ∧ Mut = yv
2.2 Are These Valid? A formula is valid if it is true for all interpretatio interpretations. ns. An example example of valid formula is ¬ P ∨ P. In FOL terms, the example may be translated as ∀ x ¬P( x) ∨ P( x) or ∀ x P( x) =⇒ P( x). In more generic follow owing ing term, ∀ x P( x) =⇒ Q( x) is a valid formula if P( x) ≡ Q ( x) or P( x) ⇐⇒ Q( x). The foll problems involve testing validity of different FOL formula that have been represented in P ⇐⇒ Q form. Exercise 2.20 Decide whether the following FOL formula are valid or not: 1. ∀ ∃ Loves( x, y) ⇐⇒ ⇐⇒ ∃∀ Loves( x, y) x y
y
2.3 FOL Interpretations:
13
2. ∀ x Loves( x, Yeppie) ⇐⇒ ⇐⇒ ¬∃ x ¬ Loves( x, Yeppie) 3. ∃ x Loves( x, Youtube) ⇐⇒ ⇐⇒ ¬∀ x ¬ Loves( x, Youtube) 4. ∀ x, yy P( x, y) =⇒ P( y, x) 5. ∃ x, yy x = y 6. ∀ x, yy x = y
2.3 FOL Interpretations: in 2.6--2.9. 2.9. Give an interpretation where all the Exercise 2.21 Consider the statements presented in 2.6 sentences are true. interpretation to be ∆, I where ∆ is the set of natural numbers Solution 2.20 Let us consider the interpretation and I (Father ) = {(n + 1, n) : n ∈ N} Exercise 2.22 For each of the sentences in 2.6-2.9 in 2.6-2.9,, give an interpretation where it is false and rests are true. Solution 2.21 Find below the solutions: • ∆ be a finite initial segment of the natural numbers; then the largest number will not have a successor succes sor so (2.6) is 2.6) is false but 2.7 but 2.7--2.9 are 2.9 are true. have a situation like this. this. 2.7 2.7 is is logically entailed by 2.8. by 2.8. Thus Thus both 2.7 both 2.7 and and • Not possible to have 2.8 are 2.8 are false simultaneously. • 2.8 is 2.8 is false and 2.6,2.7 and 2.6,2.7 and and 2.9 2.9 true true if we add to the natural numbers two extra elements d 1 and d 2 such that I (Father ) = {(d 1 , d 2 ), (d 2 , d 1 )} ∪ {(n + 1; n) : n ∈ N}. • to make 2.9 make 2.9 false and the rest true, we can make D = N and I (Father ) = {(m, n) : m > n, n, m ∈ N}.
give a logical interpretation that makes that Exercise 2.23 For each of the following sentences, give sentence false and the other two sentences true: 1. ∀ x∀ y∀ z[P( x, y) ∧ P( y, z) =⇒ P( x, z)] 2. ∀ x∀ y[P( x, y) ∧ P( y, x) =⇒ ( x = y)] 3. ∀ x∀ y[P(a, y) =⇒ P( x, b)]
interpretation ∆, I . Analysi Analysiss of three cases are as follows: Solution 2.22 Let is consider an interpretation 1. To make the first sentence sentence false, a non-transit non-transitive ive relation relation is required. required. Let us consider consider ∆ = { A, B, C , D} and I (a) = A , I (b) = B, I (c) = C , I (d ) = D, I (P) = {( B, C ), (C , D)}. The interpretation function I (P) makes the relation non-transitive as the tuple ( B, D) is not in I (P). The second sentence will evaluate to be true as for all the possible assignments to P
14
Chapter 2. Knowledge Representation and FOL
the antecedent is false which in turn makes the sentence true ( X is is false in X =⇒ Y ). The third sentence sentence is true for the same reason (in this case there is no tuple in I (P) such that A is its first element). 2. A symmetric and reflexive relation with no element equal to each other will make the second sentence false. Let us consider an interpretation accordingly. Let ∆ = { A, B, C , D} and I (a) = A, I (b) = B, I (c) = C , I (d ) = D, I (P) = {( B, C ), (C , B), ( B, B), (C , C )}. With the variable assignment µ ( x) = B and µ ( y) = C , the antecedent of the second sentence will be not be true for all x and y as B = C . The first sentence is true because for the variable assignments ( µ ( x) = B , µ ( y) = C and µ ( z) = B ) that make the antecedent (P( B, C ) ∧ P(C , B)) of the entailment true, its consequent ( P( B, B)) is also true, so the entailment entailment is always true. The third sentence is true because there is no variable assignment that makes its antecedent antecedent true, because there is no tuple in I (P) such that A is its first element. 3. Let ∆ = { A, B, C , D} and I (a) = A, I (b) = B, I (c) = C , I (d ) = D , I (P) = {( A, C )}. For the third sentence, the antecedent of the third sentence is true for variable assignment µ y y = C , but the consequent is false with any assignment of x. Thus the sentence sentence is false under under any assignment of x x and y . The other two true because their antecedents are false for all variable assignments.
barber. Exercise 2.24 In a certain town, there are the following regulations concerning the town barber. • Anyone who does not shave himself must be shaved by the barber. • Whomever the barber shaves, must not shave himself. Translate the regulations into FOL statements. Show that any interpretation under which the first regulation is true makes the second regulation false. Solution 2.23 Translation into FOL:
∀ x[¬Shaves( x, x) =⇒ Shaves(barber , x)] ∀[Shaves(barber , x) =⇒ ¬Shaves( x, x)] Suppose there is an interpretation ∆, I under which both sentence sentence 1 and 2 are true. There must be an object in ∆ that refers to the meaning of barer barer . Let us assume it to be b . The object b either shaves himself or not. In logic term, the interpretation I (Shaves) does either contain (b, b) or not. Let (b, b) ∈ I (Shaves). If the second second sentence sentence is true for every every x, it should also be true for the barber . In logic sen sense, se, for every every assignme assignment nt µ , ∆, I , µ |= [Shaves(barber , x) =⇒ ¬Shaves( x, x)]. The particu particular lar assignment assignment µ ( x) = b yields ∆, I , µ (b) |= ¬Shaves(b, b). Thus contradiction. (b, b) ∈ / I (Shaves), which is a contradiction. Let (b, b) ∈ / I (Shaves). As the first stateme statement nt is true for ev every ery assignment assignment µ , ∆, I , µ |= x = b, ∆, I , µ ( x) = b |= [¬Shaves(barber , x) =⇒ Shaves( x, x)]. Particularly for assignment µ x Thus [¬Shaves(b, b) =⇒ Shaves(b, b)]. As (b, b) ∈ / I (Shaves), we can infer Shaves(b, b). Thus Shaves(b, b) ∈ I (Shaves), which is again a contradiction. contradiction.
2.3 FOL Interpretations:
15
knowledge: Exercise 2.25 Consider the following piece of knowledge: Tony, Mike and John belong to the Alpine Club. Every member of the Alpine Club who is not a skier is a mountain climber. Mountain climbers do not like rain, and anyone who does not like snow is not a skier. Mike dislikes whatever Tony likes, and likes whatever Tony dislikes. Tony likes rain and snow. Prove that the given sentences logically entail that there is a member of the Alpine Club who is a mountain climber but not a skier. Solution 2.24 Let us consider the following predicates and constants: • MemberAC : Unary predicate representing member of Alpine Club • Skier : Unary predicate representing Skier class • Climber : Unary predicate representing mountain climber class predicate where Likes( x, y) represents x likes y • Likes: Binary predicate • constants: tony, mike, john, rain, snow STEP 1: Translating 1: Translating English sentences in FOL Tony, Mike and John belong to Alpine Club
S1: MemberAC (tony) S2: MemberAC (mike) S3: MemberAC ( john ) Every member of the Alpine Club who is not a skier is a mountain climber climber.. S4: ∀ x MemberAC ( x) ∧ ¬Skier ( x) =⇒ Climber ( x) Mountain climbers do not like rain S5: ∀ xClimber ( x) =⇒ ¬ Likes( x, rain) anyone who does not like snow is not a skier S6: ∀ x ¬ Likes( x, snow) =⇒ ¬Skier ( x) Mike dislikes disl ikes whatever Tony likes and likes whatever what ever Tony dislikes S7: ∀ x Likes(tony, x) =⇒ ¬ Likes(mike, x) S8: ∀ x ¬ Likes(tony, x) =⇒ Likes(mike, x) Tony likes rain and snow. S9: Likes(tony, rain) S10: Likes(tony, snow)
Goal: There is a member of the Alpine Club who is a mountain climber but not a skier G: ∃ x MemberAC ( x) ∧ Climber ( x) ∧ ¬Skier ( x)
16
Chapter 2. Knowledge Representation and FOL
We need to come up with any interpretation ( D, I ) where S1-S10 are true. We need to show that
(∆, I ) |= ∃ x MemberAC ( x) ∧ Climber ( x) ∧ ¬Skier ( x)
∈ ∆ such that if an assignment v that assigns d to x , To prove this we got to find some object d ∈ then (∆, I ), v |= ∃ x MemberAC ( x) ∧ Climber ( x) ∧ ¬Skier ( x) The domain is defined as ∆
= { I (tony), I (mike), I ( john ), I (snow), I (rain)}
The interpretation set I ( MmeberAC ) = { I (tony), I (mike), I ( john)}. For at least one object d ∈ ∆, we need to find one d ∈ ∈ ∆ such that d ∈ ∈ I ( MemberAC ), d ∈ ∈ I (Climber ), d ∈ / I (Skier )
. Clearly john, rain, snow do not qualify to be one such d .
Let us check whether I (tony) ∈ I (Climber ). Fro From m S9, we know know I (tony), I (rain) ∈ I ( Likes). v where I (tony shall derive In S5, if assume variableinassignment assigned ), we I (tony I (tony )x is ∈ Climber ), I we (rain ) to bea FALSE order to make and and we get a contradiction. So, Tony cannot be a climber.
Let us run our probe for Mike. From S10, we know that I (tony), I (snow) ∈ I ( Likes). From S7, if we assume assignment v( x) = I (snow), we derive
(∆, I ), v |= ¬ Likes( x, snow) . So, I (mike), I (snow) / consider an assignment assignment v ( x) = I (mike), we ∈ I ( Likes). From S6, if we consider can derive I (mike) / ∈ I (Skier ). From S4, for an assignment v ( x) = I (mike), we obtain I (mike) ∈ I (Climber ). Thus Thus we hav havee found found d = = I (mike) such that I (mike) ∈ I ( MemberAC ), I (mike) ∈ I (Climber ) and I (mike) ∈ I ( MemberAC ). Thus it is proved that
(∆, I ) |= ∃ x MemberAC ( x) ∧ Climber ( x) ∧ ¬Skier ( x)
2.16 and and corresponding FOL sentences in Exercise 2.26 Consider the sentences in Exercise 2.16 Solution 2.16. Solution 2.16. Come Come up with interpretations for the following visual situations.
2.3 FOL Interpretations:
17
Use the int inter erpre pretat tation ion to te test st whethe whetherr ea each ch formul formulaa in Soluti Solution on 2.16 is satisfi satisfied ed by the int inter erpre pretat tation ion or not. Solution 2.25 Let the interpretation I be the following: • I ( A) = b 1 , I ( B) = b2 , I (C ) = b3 , I ( D) = b4 , I ( E ) = b5 , I (F ) = table
• I (On) = {b1 , b4 b4 , b3 , b3, table, b5 , b2, b2 , table} • I ( Above) = {b1 , b4 , b1 , b3 , b1 , table, b4 , b3 , b4 , table, b3 , table, b5 , b2 , b5 , table, b2 , table} • I ( Red ) = {b1 , b5 } • I (Green) = {b4 } • I ( Red ) = {b1 , b5 } I | |= ¬S 1 ∧ ¬S 2 ∧ ¬S 3 ∧ S 4 ∧ ¬S 5 ∧ ¬S 6 ∧ S 7
Exercise 2.16 and and corresponding FOL sentences in Exercise 2.27 Consider the sentences in Exercise 2.16 Solution 2.16. Solution 2.16. Come Come up with interpretations for the following visual situations.
Use the int inter erpre pretat tation ion to te test st whethe whetherr ea each ch formul formulaa in Soluti Solution on 2.16 is satisfi satisfied ed by the int inter erpre pretat tation ion or not.
18
Chapter 2. Knowledge Representation and FOL
Solution 2.26 Let the interpretation I be the following: • I ( A) = hat , I ( B) = Joe, I (C ) = bike, I ( D) = Jill , I ( E ) = case, I (F ) = ground • I (On) = {hat , Joe Joe, bike, bike, ground , Jil l , case, case, ground }} • I ( Above) = {hat , Joe, hat , bike, hat , ground , Joe, bike, Joe, ground , bike, ground , Jil l , case, Jil l , ground , case, ground }} • I ( Red ) = {bike, case} • I (Green) = {hat , ground }} • I ( Red ) = {case, bike} I | |= S 1 ∧ S 2 ∧ ¬S 3 ∧ S 4 ∧ ¬S 5 ∧ S 6 ∧ S 7
Exercise 2.28 Consider the following sentences: Bob. S1: Andrew is the father of Bob. father of Chris. Chris. S2: Bob is the father S3: Every grandfather is someone’s someone’s father. father. S4: Andrew is a grandfather of Chris. Use the above statements to answer the following: 1. Translate these sentences into first-order logic, using binary predicates Father and Grand and Grand and constants a , b, c for Andrew, Bob and Chris. father and father 2. Show semantically (by reasoning about interpretations) that S1-S3 that S1-S3 do do not logically entail S4 S4.. 3. Write in first-order logic an additional sentence that defines a general property of grandfathers, and show that S1-S3 that S1-S3 together together with this new sentence entail S4 S4..
Solution 2.27 Solutions are as follows: 1. The FOL sentences sentences are S1: Father (a, b) S2: Father (b, c) S3: ∀ x ∃ y GrandFather ( x, y) =⇒ ∃ z Father ( x, z)
S4: GrandFather a, c) 2. To show that S1-S3( do not logically entail S4 we must provide an interpretation which makes S1-S3 true and S4 fal false. se. Let us consid consider er an interp interpret retati ation on ∆, I , where ∆ = {a, b, c}, I (Father ) = {a, b, b, c} and I (GrandFather = = 0/ ). Thus S1-S3 are true and GrandFather (a, c) is false. 3. The sentence sentence is trivially trivially
∀ xyz [Father ( x, y) ∧ Father ( y, z) =⇒ GrandFather ( x, z)]
Exercise 2.29 Consider the following sentences: S1: Five is larger than three.
2.4 FOL Reasoning
19
S2: Three is larger larger than than one. every number there is another number that is larger than it (the first number). S3: For every S4: Five, three and one are numbers. S5: Five is larger than one. Use the above statements to answer the following: 1. Translate Translate these senten sentences ces into first-order logic. logic. 2. Show semantically (by reasoning about interpretations) that S1-S4 that S1-S4 do do not logically entail S5 S5.. 3. Write in first-order logic an additional sentence that defines a general property property of numbers, and show that S1-S4 that S1-S4 together together with this new sentence sentence entail entail S5 S5..
Exercise 2.30 Consider the following sentences: S1: Jack is Rob’s Rob’s brother. Mike’s brother. brother. S2: Rob is Mike’s S3: If one person is someone else’s else’s brother, brother, then this second person also is a brother to the first one. Rob and Mike are people. people. S4: Jack, Rob
Jack is Mike’s Mike’ s brother. brother S5: the Use above statements to .answer the following: 1. Translate Translate these senten sentences ces into first-order logic. logic. 2. Show semantically (by reasoning about interpretations) that S1-S4 that S1-S4 do do not logically entail S5 S5.. 3. Write in first-order logic an additional sentence that defines a general property property of brothers, and show that S1-S4 that S1-S4 together together with this new sentence sentence entail entail S5 S5..
Exercise 2.31 Consider the following sentences: every person that is nice. S1: Neil likes every S2: Mike is not annoying. S3: If a person is not annoying, annoying, then tha thatt person is nice. nice.
other person that likes her her.. S4: If a person is nice, then there is some other S5: Neil is is a person. person. likes Mike. Mike. S5: Neil likes Use the above statements to answer the following: 1. Translate Translate these senten sentences ces into first-order logic. logic. 2. Show semantically (by reasoning about interpretations) that S1-S5 that S1-S5 do do not logically entail S6 S6.. 3. Write in first-order logic an additional sentence, and show that S1-S5 together with this new sentence entail S6 entail S6..
2.4 FOL Reasoning
20
Chapter 2. Knowledge Representation and FOL
Exercise 2.32 Determine whether the following sentence is valid using resolution:
∃ x ∀ y ∀ z [(P( y) =⇒ Q( z)) =⇒ (P( x) =⇒ Q( x))]
Solution 2.28 The negated Goal:
¬∃ x ∀ y ∀ z [(P( y) =⇒ Q( z)) =⇒ (P( x) =⇒ Q( x))] ¬∃ x ∀ y ∀ z [(¬P( y) ∨ Q( z)) =⇒ (¬P( x) ∨ Q( x)] ¬∃ x ∀ y ∀ z [¬(¬P( y) ∨ Q( z)) ∨ (¬P( x) ∨ Q( x)] ∀ x ∃ y ∃ z [(¬P( y) ∨ Q( z)) ∧ ¬(¬P( x) ∨ Q( x)] ∀ x ∃ y ∃ z [(¬P( y) ∨ Q( z)) ∧ P( x) ∧ ¬Q( x)] ∀ x [(¬P( f ( x)) ∨ Q(g( x))) ∧ P( x) ∧ ¬Q( x)] {[¬P( f ( x)) ∨ Q(g( x))] ))],, [P( x)] )],, [¬Q( x)]}
Exercise 2.25. Use Use resolution to prove that there exists a member of the Exercise 2.33 Refer to Exercise 2.25. Alpine club who is a climber but not a skier. skier. knowledge base (S1-S10) presented presented in 2.24 in 2.24 can can be represe represented nted in clausal form Solution 2.29 The knowledge as follows: C1: MemberAC (tony) C2: MemberAC (mike) C3: MemberAC ( john ) C4: ¬ MemberAC ( x) ∨ Skier ( x) ∨ Climber ( x)
2.4 FOL Reasoning
21
C5: ¬Climber ( x) ∨ ¬ Likes( x, rain) C6: Likes( x, snow) ∨ ¬Skier ( x) C7: ¬ Likes(tony, x) ∨ ¬ Likes(mike, x) C8: Likes(tony, x) ∨ Likes(mike, x) C9: Likes(tony, rain) C10: Likes(tony, snow) The negation negation of goal (S11) is ∀ x [¬ MemberAC ( x) ∨ ¬Climber ( x) ∨ ¬Skier ( x)]
¬ MemberAC ( x) ∨ ¬Climber ( x) ∨ ¬Skier ( x)
[¬ MemberAC ( x) ∨ ¬Climber ( x) ∨ Skier ( x)]
[¬ MemberAC ( x) ∨ Climber ( x) ∨ Skier ( x)]
ε
[¬ MemberAC ( x) ∨ Skier ( x)]
MemberAC (mike)] [ MemberAC
{ x/mike}
[Skier (mike)]
[ Likes( x, snow) ∨ ¬Skier ( x)]
{ x/mike} [ Likes Likes(mike, snow)]
[¬ Likes(tony, x) ∨ ¬ Likes(mike, x)]
{ x/snow}
[¬ Likes(tony, snow)]
ε
[ Likes Likes(tony, snow)]
22
Chapter 2. Knowledge Representation and FOL
Exercise 2.34 Hairy animals animals are mammals. mammals. A bear is an animal and it has got hair. hair. A rabbit is a mammal. Winnie is a bear and Bugsbunny is a rabbit. Sylvester is an animal and is hairy. Prove that Winnie is a mammal. Solution 2.30 FOL sentences for the given English description are as follows: HasH asHair air ( x) =⇒ Mammal ( x) S1: ∀ x Animal ( x) ∧ H S2: ∀ x Bear ( x) =⇒ HasHair ( x) S3: ∀ x Rabbit ( x) =⇒ Mammal ( x) S4: Bear (winnie) S5: Rabbit (bugsbunny) S6: Animal (sylvester ) ∧ H HaH aHair air (sylvester ) The result of resolution resolution procedure is as follows. follows.
[¬ Bear ( x) ∨ Animal ( x)]
HasH asHair air ( x)] [¬ Bear ( x) ∨ H
[ Bear (winnie)]
{ x/winnie}
[ Animal Animal (winnie)]
{ x/winnie}
[ Has HasHa Hair ir (winnie)]
[¬ Animal ( x) ∨ ¬ H HasH asHair air ( x) ∨ Mammal ( x)]
{ x/winnie}
[¬ Animal (winnie) ∨ Mammal (winnie)]
ε
[¬ Mammal (winnie))]
[ Mammal (winnie)]
ε
Exercise 2.35 Represent the following sentences in FOL: 1. All professors professors are people. people. 2. Deans are are professor professors. s.
2.4 FOL Reasoning 3. All professors professors consider consider dean a friend or don’t know know him. 4. Everyone Everyone is a friend of someone. someone. 5. People only criticize criticize people people that are not their friends. friends. 6. Lucy is is a professor professor 7. John iiss the dean. dean. 8. Lucy criticized criticized John. John. 9.Is John a friend of Lucy’s? Lucy’s? Using resolution prove or disprove “Lucy is a friend of John”.
23
Solution 2.31 The FOL statements are as follows: S1: ∀ x Professor ( x) =⇒ Person( x) S2: ∀ x Dean( x) =⇒ Professor ( x) S3: ∀ p,d Professor ( p) ∧ Dean(d ) =⇒ Friend ( p, d ) ∨ ¬Knows( p, d ) S4: ∀ x ∃ y Friend ( x, y) S5: ∀ x, yy Person( x) ∧ Person( y) ∧ Criticize( x, y) =⇒ ¬Friend ( x, y) S6: Professor ( Lucy) S7: Dean( John) S8: Criticize( Lucy, John) G: Friend ( Lucy, John)
The FOL statements S1-S8 statements S1-S8 and and G in clausal form: G in Pro f es essor sor ( x) ∨ Person( x) C1: ¬Pro C2: ¬ Dean( x) ∨ Pro Pro f es esso sor r ( x) C3: ¬Pro Pro f es essor sor ( p) ∨ ¬ Dean(d ) ∨ Friend ( p, d ) ∨ ¬Knows( p, d ) C4: Friend ( x, F ( x)) C5: ¬Person( x) ∨ ¬Person( y) ∨ ¬Criticize( x, y) ∨ ¬Friend ( x, y) C6: Professor ( Lucy) C7: Dean( John) C8: Criticize( Lucy, John) CG: ¬Friend ( Lucy, John) The result of reasoning is as follo follows: ws:
24 C 2
Chapter 2. Knowledge Representation and FOL C 7
C 1
{ x/ john } [Professor ( john )]
{ x/lucy}
C 1
[Person(lucy)]
{ x/ john }
[Person( john )]
C 6
C 5
{ x/lucy}
[¬Person( y) ∨ ¬Criticize( Lucy, y) ∨ ¬Friend ( Lucy, y)]
C 8
{ y/ john }
[¬Person( john ) ∨ ¬Friend ( Lucy, john)]
ε
[¬Friend (lucy, john)] Exercise 2.36 Consider the following sentences: S1: ∀ x Book ( x) ∧ ManyPages( x) =⇒ Thick ( x) S2: ∀ x Magazine ( x) =⇒ ¬Thick ( x) ∧ ¬ Book ( x) S3: Book (lordOfTheRings ) ∧ Magazine (time)
S4: ManyPages(lordOfTheRings ) Using resolution, prove that Thick (lordOfTheRings ) ∧ ¬Thick (time)
Exercise 2.37 Consider the following sentences: S1: ∀ x, yy, z z R( x, y) ∧ R( y, z) =⇒ R( x, z) S2: ∀ x R( x, f ( x)) =⇒ R( f ( x), f ( f ( x))) S3: R(a, f (a)) Using resolution, prove that R (a, f ( f (a)))
3. Resource Description Framework (RDF)
knowledge (e.g.Every company is an organizaExercise 3.1 What is the role of terminological knowledge tion.), and what is the role of facts (e.g. Microsoft is an organization. Microsoft is headquartered in Redmond.) in a knowledge-based system? Solution 3.1 1. Te Terminological rminological knowledge • is used to define relevant concepts of a problem domain • is used to describe describe general general charac characteri teristics stics of entities entities and interrela interrelations tions between between entities entities of a specific domain • allows to abstract from facts and can be used to derive ne new w concrete knowledge 2. Concrete Concrete knowledge knowledge • states concrete facts • states explicit information about specific entities
Remark: Remar k: An ontology requires both kinds of knowledge. knowledge.
Exercise 3.2 Describe the information you have about model:mol1 in your own words. RDF-N3 Syntax:
@prefix model: @prefix model: . @prefix cdk: . @prefix rdfs: . @prefix owl: . @Prefix chem: model:atom1 a cdk:Atom ; cdk:hasFo cdk: hasFormal rmalChar Charge ge "1" ; cdk:sy cdk :symbo mbol l "O" .
26
Chapter 3. Resource Description Framework Framework (RDF)
model:atom2 a cdk:Atom ; cdk:sy cdk :symbo mbol l "C" . model:mol1 a cdk:Molecule ; rdfs:labe rdfs :label l "Methanol "Methanol" " ; cdk:hasAt cdk: hasAtom om model:at model:atom2 om2 ,model:at ,model:atom1 om1 ; cdk:hasBo cdk: hasBond nd model:bo model:bond1 nd1 . owl:sameAs chem:CH4O/c1-2/h2H,1H3 chem:CH4O/c1-2/h2H,1H3 ; model:bond1 a cdk:Bond ; cdk:binds cdk: bindsAtom Atom model:at model:atom1 om1 ,model:at ,model:atom2 om2 ; cdk:hasOr cdk: hasOrder der cdk:Singl cdk:SingleBon eBond d .
Figure 3.1: RDF Graph
Solution 3.2 The methanol molecule consists of 2 atoms, namely C and O, which both are bound by single bonds. Methanol is the same thing as the one described in the resource (URI) Chem:CH4O/c1-2/h2H,1H3 RDF(Modeling) : One On e wi wide dely ly kn know own n RD RDFF vo voca cabu bula lary ry is FOAF FOAF (Fri (Frien end d of a Frie Friend nd)) wh whic ich h is us usef eful ul fo forr ex expr pres essi sing ng meta-data meta -data about people, people, and their interes interests, ts, relations relationships hips and activities. activities. You can find an introduction here http://www.xm http://www.xml.com/pub/a/2 l.com/pub/a/2004/02/04/foa 004/02/04/foaf.html f.html and the complete specification here http://xmlns. http://xmlns.com/foaf/spec com/foaf/spec.
27 Exercise cise 3.3 Look Look at the definitio definitions ns of the follo followin wing g classe classes: s: foa foaf:G f:Group roup,, foaf:P foaf:Pers erson, on, Exer foaf:Organ foaf:O rganizat ization. ion. Mark (e.g. underline) underline) all relev relevant ant entities entities in the given given text with regard regard to the foaf-classes mentioned above. Metallica Metal lica is an American American heavy heavy metal band from Los Angeles, Angeles, California California.. The band’s band’s fast tempos, instrumentals, and aggressive musicianship placed them as one of the founding "big four" of thrash metal alongside Slayer, Megadeth, and Anthrax. Metallica formed in 1981 when James Hetfield responded to an advertisement that drummer Lars Ulrich had posted in a local newspaper. As of 2003, the line-up features long-time lead guitarist Kirk Hammett (who joined the band in 1983) and bassist Robert Trujillo (a member since 2003) alongside Hetfield and Ulrich. Previous members of the band are lead guitarist Dave Mustaine (who went on to found the band Megadeth), and bassists Ron McGovney, Cliff Burton and Jason Newsted. The band also had a long collaboration with producer Bob Rock, who produced all of its albums from 1990 to 2003 and served as a temporary bassist between the departure of Newsted and the hiring of Trujillo. The band earned a growing fan-base in the underground music community and critical acclaim with its first four albums, with their third, Master of Puppets (1986), described as one of the most influential and "heavy" thrash metal albums. Metallica achieved substantial commercial success with their eponymous fifth album (also known as The Black Album), which debuted at number one on the Billboard Billboard 200. Solution 3.3
Foaf:Pers Foaf:P erson: on: James James Hetfie Hetfield, ld, Lar Lars s Ulrich Ulrich, , Kirk Kirk Hammet Hammett, t, Robert Robert Trujil Trujillo, lo, Dave Dav e Mustai Mustaine, ne, Ron McGovn McGovney, ey, Cliff Cliff Burton Burton, , Jason Jason Newste Newsted, d, Bob Rock Rock Foaf:Gro Foaf :Group: up: Slayer, Slayer, Megadeth, Megadeth, Anthrax, Metallica, Metallica, Megadeth Megadeth Foaf:Org Foaf :Organiza anization tion: : None Create te an RD RDF F mo mode del l fo for r th the e te text xt ab abou out t Me Meta tall llic ica. a. Exercise 3.4 Crea
On Only ly us use e th the e classes clas ses foaf:Grou foaf:Group, p, foaf:Per foaf:Person son and foaf:Org foaf:Organiz anizatio ation n and the followin following g properti prop erties: es: foaf:bir foaf:birthday thday, , foaf:memb foaf:member, er, foaf:kno foaf:knows. ws. Solution 3.4 RDF (Modeling)
< r d f : R D F x m l n s : r d f = " h t t p : / / ww www . w3 w3 . o r g / 1 9 9 9 / 0 2 / 2 2 − r d f −s y n t a x −n s # " xmlns:dbp =" ht t p : / / dbpe dia . org / page / " x m l n s : f o a f = " h t t p : / / xm x m lln n s . c om om / f o a f / 0 . 1 / " x m l n s : e x = " h t t p : / / e x a mp mp l e . o r g / C u s t o m E n t i t y / " > < f o a f : P e r s o n r d f : a b o u t = d b p : J a m e s _H _ H e t f i eell d > < f o a f :n : n a m e >J > J aam m es e s H e t f i e l d < / f o a f :n :n a m e > >"" 0 03 3 −0 4 " < / f o a f : b i r t h d a y > < f o af a f : kn k n o ws w s r d f : r e s o u r c e = d b p : L a rrss _ U l r i c h >< >< / f o a f : k kn now wss > < f oa o a f ::m m em e m b er e r r d f : r e s o u r c e = d b p : M e t a l l i c a > < / f o af af : m mee m b bee r > < f o a f : P e r s o n r d f : a b o u t = d b p : L a r s _ U lr lr i ch > < f o a f :n : n a m e > La L a r s U l r i c h < / f o a f :n :n a m e > < !−− e t c −−>
28
Chapter 3. Resource Description Framework Framework (RDF)
}
Exercise 3.5 RDFS Modeling: 1. Define a few classes and a small hierarchy of classes for rock band types in Turtle notation.
2. Define the relationships between the individuals from the previous exercise 3.4 and 3.4 and the classes from part 1. of this exercise using Turtle notation. 3. Define a domain and a range for each of the properties (e.g.,foaf:knows) of your RDF model. 4. Which RDF statements statements satisfy these constrain constraints, ts, which violate them? Give exa examples. mples.
Exercise 3.4 Model Model is Extended: Solution 3.5 The Exercise 3.4 1. ex:HardRockBand rdfs:subclassOf ex:RockBand . ex:RockBand rdf:type rdfs:Class . ex:HardRockBand rdf:type rdfs:Class . 2. ex:Metallica rdf:type ex:HardRockBand . 3. foaf:knows foaf:knows rdfs:domain rdfs:domain foaf foaf:Perso :Person n. foaf:knows rdfs:range foaf:Person . foaf:member rdfs:domain foaf:Person . foaf:member rdfs:range ex:Band . 4. In this example, all statements in my original model (Exercise 3.4) (Exercise 3.4) satisfy satisfy the constraints listed in 1) and 3) (as does the only new fact listed in 2)), but this will depend ultimately on your own model.
specification, what is the semantics if you specify more than one Exercise 3.6 Following RDFS specification, domain for a property (see example below)?
ex:containedI ex:contai nedInBox nBox rdfs:dom rdfs:domain ain ex:Banan ex:Banana a . ex:contai ex:co ntainedI nedInBox nBox rdfs:dom rdfs:domain ain ex:Apple ex:Apple . ex:contai ex:co ntainedI nedInBox nBox rdfs:ran rdfs:range ge ex:Fruit ex:FruitBox Box .
Solution 3.6 We reason reason set-theo set-theoreti retically cally. . Let I be an RD RDFS FS model models s of the pr prev evio ious us triple triples. s. dom (ex : containedInBox I ) ⊆ ex : Banana I ∩ ex : Apple I
Th Then en (3.1)
Basically Basica lly what what this this means means is that that follow following ing our model model anythi anything ng that that is co cont ntai aine ned d in a bo box x is both both an app apple le and a ba bana nana na! ! In gener general al, , we get always alw ays an inters intersect ection ion of the typ typing ing declar declarati ations ons, , even even if they they are counte cou nter-i r-intu ntuiti itive ve or non-se non-sensi nsible ble. . The model model is still still consist consistent ent. . This This
29 is becaus because e there there is no negati negation on to expres express s that that banana bananas s are distin distinct ct from from apples. Exercise 3.7 What happens if you define cyclic subclass relations? Is there a situation where this is desired? desired?
ex:A rdfs:sub rdfs:subClass ClassOf Of ex:B . ex:B rdfs:sub rdfs:subClass ClassOf Of ex:C . ex:C rdfs:sub rdfs:subClass ClassOf Of ex:A .
(ex:A, ex:B, ex:C) are equiv equivalent. alent. Solution 3.7 In general, we get that all classes in the cycle (ex:A, Whether this is desired or not, it really depends on the application. In general, this can be bad, as redundancy redundan cy will induce RDFS reasoners into potentially tons of redundant redundant unnecessary unnecessary inferences. But it is a common phenomenon in large scale RDFS ontologies, that are complex and dynamic (changee over time), as it might be that we weren’t (chang weren’t apriori aware when adding a new subclass subclass triple, that a cycle would result. statements can be modeled with RDF/S. If yes, write down Exercise 3.8 Decide if the following statements the statement statement in Turtle Turtle notation. If not, write down what is missing from RDF/S. Every pear is a fruit. 2. 1. If customer customer X ordered box Y, Y, then box Y is ordered ordered by customer X. 3. Every fruit fruit box contains contains fruit flies. 4. A customer customer is never never a fruit. 5. A fruit box can have only one order order number. number. 6. Everything Everything that is in a fruit box is a fruit. fruit. 7. If something something contains contains fruit, it is a fruit box. 8. No fruit box box contains contains meat.
Solution 3.8 1. Yes: ex:Pear rdfs:subClassOf ex:Fruit. 2. No: RDFS cannot express inv inverse erse properties (in which we invert the sense of a relationship edge) 3. Yes: ex:contains rdfs:range ex:Fruit_Flies. ex:contains rdfs:domain ex:FruitBox. 4. No: RDFS cannot cannot express that customers customers and fruits are disjoint (no negation) negation) 5. No: RDFS cannot cannot express express cardinality cardinality constraints constraints 6. Yes: ex:contains rdfs:domain ex:FruitBox. ex:contains rdfs:range ex:Fruit. 7. Yes:
30
Chapter 3. Resource Description Framework Framework (RDF)
ex:contains rdfs:range ex:Fruit. ex:contains rdfs:domain ex:FruitBox. 8. No: RDFS cannot expres expresss negation (we’d (we’d need to assert that fruit and flies are disjoint from meat)
Exercise 3.9 The exercises will give an overview of entailment and decide the logical consequences of RDFS statements. Let entailments.n3 below, where rdf and rdfs are the usual names namespaces. paces. entailments.n3 be the file listed below,
:Person :Perso n a rdfs:C rdfs:Clas lass s . :Man :Ma n a rdfs:C rdfs:Clas lass s ; rdfs:subC rdfs: subClassO lassOf f :Person :Person . :Paren :Pa rent t a rdfs:C rdfs:Clas lass s ; rdfs:sub rdfs :subClass ClassOf Of :Person :Person . :Fathe :Fa ther r a rdfs:C rdfs:Clas lass s ; rdfs:sub rdfs :subClass ClassOf Of :Parent :Parent ; rdfs:sub rdfs :subClass ClassOf Of :Man . :Child :Ch ild a rdfs:C rdfs:Clas lass s ; rdfs:sub rdfs :subClas ClassOf sOf :Person :Person . :hasPare :has Parent nt a rdf:Prop rdf:Property erty ; rdfs:dom rdfs :domain ain :Person :Person ; rdfs:ran rdfs :range ge :Parent :Parent . :hasFath :has Father er a rdf:Prop rdf:Property erty ; rdfs:sub rdfs :subProp Property ertyOf Of :hasPare :hasParent nt ; rdfs:ran rdfs :range ge :Father :Father . :isChild :isC hildOf Of a rdf:Prop rdf:Property erty ; rdfs:dom rdfs :domain ain :Child :Child ; rdfs:ran rdfs :range ge :Parent :Parent . :A :Ann nn a :P :Per erso son n ; :hasFathe :hasF ather r :Carl . :Carl a :Man . Is entailmen entailments.n ts.n3 3 syntacti syntacticall cally y correct correct RDF(S)? RDF(S)? Solution 3.9 Yes.
Exercise 3.10 Explain what it means for one set of statements to entail a (different) set of statements. Solution 3.10 Quoting Quoting RDF semantic semantics: s:
Entailment Entailme nt is the key idea which connects connects model-theore model-theoretic tic semantics semantics to real-w real-worl orld d applic applicati ations ons. . As noted noted earlie earlier, r, making making an assert assertion ion amount amo unts s to claimi claiming ng that that the world world is an interp interpret retati ation on which which assign assigns s th the e va valu lue e tr true ue to th the e as asse sert rtio ion. n.
If A en enta tail ils s B, th then en an any y in inte terp rpre reta tati tion on
31 th that at ma make kes s A tr true ue al also so ma make kes s B tr true ue, , so th that at an as asse sert rtio ion n of A al alre read ady y co cont ntai ains ns th the e sa same me "m "mea eani ning ng" " as an as asse sert rtio ion n of B; on one e co coul uld d sa say y th that at th the e meaning of B is somehow contained in, or subsumed by, that of A.
(given ven in ExcerExercise 3.11 First, to get the an overview of the statements in entailments.n3 (gi cise 3.9 cise 3.9), ), draw a diagram.
represented ted in the diagram diagram as nodes. A resource resource of type Solution 3.11 Legend: Nodes are represen rdfs:Class is depicted with a circle. A resource of type rdf:Property is depicted with a diamond. A box is a resource resource which is not of type rdfs:Class rdfs:Class or rdf:Resource rdf:Resource.. The resources resources rdfs:Class, rdfs:Class, rdf:Property, rdf:type, rdfs:subClassOf and rdfs:subPropertyOf are not marked by nodes in the diagram. Triples are illustrated with edges, where the node which the edge points from is the subject, the edge itself is the predicate and the object is the node which the edge points to. A solid unlabelled edge represent an rdfs:subClassOf or a rdfs:subPropertyOf rdfs:subPropertyOf predicate. predicate. Dashed edges show domain and range restrictions restrictions for properties. properties. An edge pointing to a prope property rty represents represents the domain restriction for the property, a range restriction is marked with an outwards pointing edge.
Figure 3.2: A diagram diagram of the entailments.n3 entailments.n3 graph
given ven Exercise 3.12 In the following exercises decide if entailment.n3 entails the statement(s) gi and explain why/why not? If the answer is "yes, the statement(s) is entailed by entailments.n3", then use the simple entailment rules (se1, se2) and the rdfs entailment rules (rdfs1, . . , rdfs12) answer.. If the answer is "no", then expl explain, ain, found at at RDFS entailment rules to prove your answer informally or formally, why this is so.
:Father :Fat her rdfs:subC rdfs:subClass lassOf Of :Person :Person .
32
Chapter 3. Resource Description Framework Framework (RDF)
Solution 3.12 True. : Father is (transitively) a subclass of :Person.(Rule rdfs11) In the proof below each line is marked with "P" if the statement is a premise, i.e., exists in entailments.n3, or with the rule and the input statements to this rule by which the line in question is concluded. Proof:
1. :Fath er rdfs:su rdfs:subClassO :Paren t --PP 2. :Father :Parent :Parent rdfs:subClassO rdfs:subClassOf bClassOfff :Parent :Person 3. :Father :Father rdfs:su rdfs:subClassO bClassOff :Person - 1, 2, rdfs11 Statements State ments 1. and 2. are found in entailments entailments.n3 .n3 and are premises premises to the application application of the entailment rule rdfs11 on line 3, which yields the statement we’re after.
rdfs:subClass lassOf Of :Person :Person . Exercise 3.13 :Man rdfs:subC
True. This is explicitly explicitly stated in entailments.n3 entailments.n3,, so the entailme entailment nt is triv trivial. ial. Solution 3.13 True.
:Carl a :P :Per erso son n . Exercise 3.14 :Carl
True. . Soluti Sol ution on 3.1 3.14 4 True
:Car :Carl l is a :Man :Man. . :Man :Man is a sub subcl clas ass s of :Pers :Person on. . :C :Car arl l is a :P :Per erso son. n. Ru Rule le rdfs9 rdfs9. . Proof: 1. :Man :Man rdfs:s rdfs:subc ubclas lassOf sOf :Perso :Person n - P 2. :C :Car arl l rd rdf: f:ty type pe :M :Man an - P 3. :C :Car arl l rd rdf: f:ty type pe :P :Per erso son n - 1, 2, rd rdfs fs9 9
Th Thus us, ,
:Carl a :P :Par aren ent t . Exercise 3.15 :Carl
Solution 3.15 True. True. Carl is in the range of hasF hasFather ather (:Ann (:Ann :hasFathe :hasFatherr :Carl). The range of hasFather is :Father. Thus, :Carl is a :Father. :Father is a subclass of :Parent, which makes :Carl a
:Parent. Rule rdfs3 and rdfs9. Proof: 1. :hasFather :hasFather rdfs:range rdfs:range :Father :Father - P 2. :Ann :hasFathe :hasFatherr :Carl - P 3. :Carl rdf:type rdf:type :Father :Father - 1, 2, rdfs3 4. :Father :Father rdfs:su rdfs:subClassO bClassOff :Parent :Parent - P 5. :Carl rdf:type rdf:type :Parent :Parent - 4, 3, rdfs9
:Carl :hasCh :hasChild ild :An :Ann n . Exercise 3.16 :Carl
False. The predicate predicate :hasChild does not exist in entailments.n3 entailments.n3 . Solution 3.16 False.
33 :Ann a :C :Chi hild ld . Exercise 3.17 :Ann
False. e. Solu So luti tion on 3. 3.17 17 Fals
The statem statement ents s about about Ann in entailme entailments nts.n3 .n3 are :Ann a Person Per son and :Ann :hasFat :hasFather her :Carl. :Carl. None None of these statem statement ents s force force us to conclu con clude de that that :Ann :Ann is a :Child :Child. .
Exercise 3.18 :Ann :Ann :hasPa :hasParen rent t :Carl :Carl .
True. Soluti Sol ution on 3.1 3.18 8 True.
:Ann :Ann :hasFa :hasFathe ther r :Carl :Carl is a statem statement ent in entail entailmen ments. ts.n3. n3. :hasFa :ha sFathe ther r is a subpro subproper perty ty of :hasPa :hasParen rent. t. This This means means that that all pairs pairs relate rel ated d by the :ha :hasFa sFathe ther r proper property ty are also also relate related d by the :hasPa :hasParen rent t proper pro perty. ty. Rule Rule rdfs7 rdfs7. . Proof: 1. :Ann :hasFa :hasFathe ther r :Carl :Carl - P 2. :hasFath :hasFather er rdfs:sub rdfs:subPrope PropertyO rtyOf f :hasParen :hasParent t - P 3. :A :Ann nn :h :has asPa Pare rent nt :C :Car arl l - 2, 1, rd rdfs fs7 7
Exercise 3.19 :Ann :Ann :hasPa :hasParen rent t _:x .
Solution 3.19 True. This follows from the results from the exercise 3.18. exercise 3.18. Since it is true that "Ann has a parent Carl", Carl", then it is true that "Ann has some parent parent". ". This is a conclusion conclusion by the application of a simple entailment rule. Proof: 1. :Ann :hasParent :hasParent :Carl :Carl - P (from exercise exercise 3.18 3.18)) 2. :Ann :hasPare :hasParent nt _:x - 1, se1
:Ann :hasPa :hasParen rent t [ rdf:ty rdf:type pe :Perso :Person n ] . Exercise 3.20 :Ann
Solu So luti tion on 3. 3.20 20 True True. .
Th This is fo foll llow ows s fr from om th the e re resu sult lts s of th the e ex exer erci cise se 3.19 and the fact that that the range of the property property :hasPare :hasParent nt is :Perso :Person. n. 1. :Ann :Ann :hasPa :hasParen rent t _:x - P (from (from exerci exercise se 3.19) 3.19) 2. :hasPa :hasParen rent t rdfs:r rdfs:rang ange e :Pa :Paren rent t - P 3. _: _:x x rd rdf: f:ty type pe :P :Par aren ent t - 2, 1, rd rdfs fs3 3 4. :Paren :Parent t rdfs:s rdfs:subC ubClas lassOf sOf :Perso :Person n - P 5. _: _:x x rd rdf: f:ty type pe :P :Per erso son n - 4, 3, rd rdfs fs9 9 :Ann :An n :hasPa :hasParen rent t [ rdf:ty rdf:type pe :Perso :Person n ] is just just an other other form form of writin writing g the st stat atem emen ents ts 1. an and d 5. :Father rdfs:sub rdfs:subClass ClassOf Of [ rdfs:sub rdfs:subClas ClassOf sOf :Person :Person ] . Exercise 3.21 :Father
34
Chapter 3. Resource Description Framework Framework (RDF)
True ue. . Solution 3.21 Tr 1. 2. 3. 4.
Pr Proo oof: f: :Fathe :Father r rdfs:s rdfs:subC ubClas lassOf sOf :Paren :Parent t - P :Fathe :Father r rdfs:s rdfs:subC ubClas lassOf sOf _:n - 1, se1 :Paren :Parent t rdfs:s rdfs:subC ubClas lassOf sOf :Perso :Person n - P _:n rdfs:s rdfs:subC ubClas lassOf sOf :Pe :Perso rson n - 3, se2
Com Combin bine e 2. :Person :Per son ].
and 4.
to get :Fathe :Father r rdfs:su rdfs:subCl bClass assOf Of [ rdfs:s rdfs:subC ubClas lassOf sOf
Exercise 3.22 Write an ontology about geography: cities, countries, capitals, borders, states, and so on.
Solution 3.22 Ontology(RDF/XML):
rdf:ID="country"> The The class of countries countries rdf:ID="city"> The The class of cities cities rdf:ID="state"> The The class of states states It relate relates s cities cities to countr countries ies
35 rdf:resource="#city"/> rdf:resource="#country"/> It relate relates s cities cities to states states rdf:resource="#city"/> rdf:resource="#state"/> It relate relates s states states to countr countries ies rdf:resource="#state"/> rdf:resource="#country"/> rdf:ID="capital"> The class class of capita capitals ls It relates relates borderst bordersto o countrie countries s rdf:resource="#country"/> rdf:resource="#country"/> It is a proper property ty of countr countries ies and takes takes litera literals ls as values values. . rdf:resource="#country"/>
Exercise 3.23 Consider the classes of males males and females. Name a relationship between them that should be included in an ontology.
36
relatio tionsh nship: ip: Solution 3.23 rela
Chapter 3. Resource Description Framework Framework (RDF) husban husbandOf dOf; ; invers inverse e relati relations onship hip: :
wifeOf wifeOf
Exercise 3.24 Consider the classes of persons, males and females. Name a relationship between all the three that should be included included in an ontology ontology.. Which Which part of this relationshi relationship p can be expressed in RDF Schema.
Husband, , Wife, Mother, Mother, Father Father Solution 3.24 Husband
Mary.. Obviously there is a Exercise 3.25 Suppose we declare Bob and Peter to be the father of Mary semantic error here. How should the semantic model make this error impossible? Solution 3.25 by a cardinali cardinality ty restrict restriction. ion.
relationship exist between between “is child of” and “is parent of” ? Exercise 3.26 What relationship
Solution 3.26 inverse relationship Exercise 3.27 Consider the property eats with domain Animal and range Animal or Plant. Suppose we define a new class Vegetarian. Name a desirable restriction on eats for this class. Do you think that this restriction can be expressed in RDF Schema by using rdfs:range?
Specifyin ying g a subcla subclass ss by re restr stric ictin ting g the range range of a proper property ty is outsid outsidee the ex expr press ession ion Solution 3.27 Specif Solution power of RDF Schema. In particular, rdfs:range defines the range, e.g., eats, for all classes. following English paragraphs. Make use of RDF and Exercise 3.28 Draw RDF graphs for the following RDF(S) vocabulary
Dr. Bose, Bose, who is a scient scientist ist in Geneti Genetic c Evolut Evolution ion Laborat Laboratory ory (GEL) (GEL) in New Delhi, Delhi, has bee been n invest investiga igatin ting g the cau cause se of respir respirato atory ry diseas disease e ‘Luche ‘Lu chem’. m’. After After initia initial l invest investiga igatio tion, n, he conjec conjectur tured ed that that either either of the followin foll owing g alternati alternatives ves is plausible plausible: : i Luchem Luchem is caused caused by contam contamina inatio tion n in ‘Sagar ‘Sagar Lake’ Lake’ ii Luche Luchem m is ca caus used ed by th the e vi viru rus s ‘H ‘HAd AdVV-1’ 1’ wh whic ich h is of ty type pe ‘Adenoviridae’ iii Luchem Luchem is caused caused by ‘soldi ‘soldier er flies’ flies’ which which belong belongs s to ‘Stratiomyomorpha’ ‘Stratiomyo morpha’ category
Solution 3.28 Following are different important modelling decisions: • ’he conjectured... alternatives’: It is modelled as rdf:Alt.
statement ment • Conjecture of different statements: It is modelled as Reification because it is a state
37
Figure 3.3: RDF data model for Dr. Bose and his investigation. about a statement. The RDF graph is presented presented in Figure 3.3. Figure 3.3.
following English paragraphs. Make use of RDF and Exercise 3.29 Draw RDF graphs for the following RDF(S) vocabulary. vocabulary.
A resear research ch paper paper titled titled ‘Ti ‘Title tle X’ has been been author authored ed by three three resear researche chers, rs, the ordering ordering of the authors authors being being ‘Autho ‘Author r A1’ is the first author, author, ‘Autho ‘Au thor r A2’ is the second second author author and ‘Autho ‘Author r A3’ is the third third author author. . Anothe Ano ther r paper paper having having tit title le ‘Title ‘Title Y’ hypoth hypothesi esized zed that that the paper paper titled titled ‘Title ‘Ti tle X’ has the potent potential ial to design design a drug drug for curing curing a diseas disease e ‘Disea ‘Disease se D’ D’. . Ho Howe weve ver, r, a re rece cent nt pa pape per r ti titl tled ed ‘T ‘Tit itle le Z’ wa warn rned ed th that at an any y dr drug ug th that at is design des igned ed out of paper paper ‘Title ‘Title X’ has side side effect effect ‘Side Effect Effect S’. ‘Author ‘Author A2’ refuted refuted the claim claim in paper paper titled titled ‘Title ‘Title Z’ in anothe another r paper paper titled titled ‘Title ‘Ti tle P’ author authored ed only only by him. him. presented in Figure 3.4. Figure 3.4. Important Important design Solution 3.29 The RDF graph for the description is presented decisions are as follows: to model author sequence in articles. • Use of rdf:List rdf:List to reification to model warned , hypothesized , refuted • Use of reification
38
Chapter 3. Resource Description Framework Framework (RDF)
Figure 3.4: Research Research papers and their claims.
Exercise 3.30 Consider the following RDF(S) data model. Answer the questions based on the data model.
ex exr: r:Op Oppo po rdf:t df:typ ype e exs: exs:Co Comp mpa any. ny. exr:Oppo exr: Oppo exs:Spon exs:Sponsors sors exr:India exr:IndianCri nCricket cketTeam Team exr:In exr :India dianCr nCrick icketT etTeam eam exs:ha exs:hasAl sAllro lround underM erMemb ember er exr:Ha exr:Hardi rdik_P k_Pand andya. ya. exr:Ha exr :Hardi rdik_p k_pand andya ya rdf:ty rdf:type pe exs:Fr exs:Frequ equent entSix SixHit Hitter terAll Allrou rounde nder. r. exs:hasAllrounderMember exs:hasAllrou nderMember rdfs:subPropertyOf rdfs:subPropertyOf exs:hasTeamMember. exs:hasTeamMember. exs:hasAl exs: hasAllrou lrounder nderMembe Member r rdfs:dom rdfs:domain ain exs:Cric exs:CricketT ketTeam. eam. exs:hasAl exs: hasAllrou lrounder nderMembe Member r rdfs:ran rdfs:range ge exs:Allro exs:Allrounde under. r. exs:hasTe exs: hasTeamMe amMember mber rdf:type rdf:type rdfs:Con rdfs:Constra straintMe intMember mbership shipPrope Property. rty. cricket team having • Use RDFS entailment to answer “Is there a company that sponsors a cricket an allrounder in the team?". team?". Show the intermediate intermediate steps. • if S S 1 and S 2 represent the sets of individuals for exs:Frequent exs:FrequentSixHitterAllr SixHitterAllrounder ounder and exs:Allrounder exs:Allrounder respectively, decide (with justification) which set theoretic rela-
39 tion(s) hold(s) between S 1 and S 2 . Do not use any knowledge other than the data model to answer.
4. Querying Semantic Web
4.1 SPARQL SPARQL Query (c, g) where g is a grandparent grandparent of c c Exercise 4.1 Find all pairs (c,
Solution 4.1 Here we use a path regular expression expression of the form path pattern pattern {n} where the path pattern pattern is repeated n times.
PREFIX fam: SELECT SEL ECT ?x ?y WHERE { ?x (fam:has (fam:hasMoth Mother er | fam:hasFa fam:hasFather ther | fam:hasP fam:hasParen arent){2} t){2} ?y }
x. Exercise 4.2 Find all pairs (x,y) where y is the uncle of x
combination of alternate alternate and sequence Solution 4.2 A path pattern that is a combination
PREFIX fam: SE SELE LECT CT ?x ?y WHERE { ?x (fam:has (fam:hasMoth Mother er | fam:hasF fam:hasFather ather | fam:hasP fam:hasParen arent) t) / fam:hasB fam:hasBroth rother er ?y }
42
Chapter 4. Querying Semantic Web
Exercise 4.3 List individuals and the number of siblings they have.
individual may not have a sibling Solution 4.3 An individual
PREFIX fam: PREFIX foaf: SELECT ?x (count(? SELECT (count(?y) y) AS ?ycount) ?ycount) WHERE { ?x a foaf:P foaf:Pers erson on . OPTIONAL { ?x (fam:h (fam:hasB asBrot rother her | fam:ha fam:hasSi sSiste ster) r) ?y } } GR GROU OUP P BY ?x
How ow many many writ writer erss di died ed in anot anothe herr coun countr try y th than an they they go gott bo born rn acco accord rd-Exercise Exer cise 4.4 H in ing g to DBPe DBPedi dia. a. Gr Grou oup p th thee resu result ltss by coun countr trie iess of birth birth of the writ writer ers. s. Le Lett dbo: . Make u usse of of dbo:occupation, dbo:birthPlace, dbo:deathPlace, dbo:Country with their usual meanings. Solution 4.4 The SPARQL query is as follows:
PREFIX dbo: SELECT ?bp (co SELECT (count unt(*) (*) AS ?count ?count) ) WHERE { ?p dbo:occu dbo:occupati pation on dbo:write dbo:writer r ; dbo:deat dbo: deathPlac hPlace e ?dp ; dbo:birt dbo: birthPlac hPlace e ?bp . ?dp a dbo:Co dbo:Count untry ry . ?bp a dbo:Co dbo:Count untry ry . FILTER(?d FILTE R(?dp p != ?bp) } GR GROU OUP P BY ?b ?bp p ORDER ORDE R BY desc(?co desc(?count) unt)
Exercise 4.5 For each country, country, give the name, and the population. population. If more than 1/4 of the population are living in its capital, give also the name and the population of the capital. Make use of dbo:Country dbo:Country, dbo:populatio dbo:population n, dbo:capital and rdfs:label.
4.1 SPARQL Quer y
43
Solution 4.5 The SPARQL query is as follows:
PREFIX dbo: SELECT SELE CT ?cntry ?cntry ?cname ?cname ?cpop ?cpop ?cap_nam ?cap_name e ?cap_pop ?cap_pop WHERE { ?cntry ?cntr y a dbo:Count dbo:Country; ry; dbo:population dbo:populatio n ?cpop; rdfs:label ?cname. OPTIONAL { ?cntry ?cnt ry dbo:capit dbo:capital al ?cap. ?cap. ?cap rdfs:labe rdfs:label l ?cap_name ?cap_name; ; dbo:population dbo:populatio n ?cap_pop. FILTER(? FILT ER(?cap_ cap_pop pop 500). 500). } FILTER (!BOUND(?pages)). (!BOUND(?pages)). }
about a social social network network shown shown in Figure 4.1. Figure 4.1. Write SPARQL SPARQL Exercise 4.7 Consider the graph data about queries to retrieve answers for the following questions. Write down the retrieved answers also.
44
Chapter 4. Querying Semantic Web
Figure 4.1: RDF data model for social network i Find the user pairs that are members of same comm community unity.. ii Find the users that are members of more than one community. Retrieve the member and the count of communities that she is in. iii Find the communities that have observed increase in member registration from 2015 to 2016.
pairs that belong to the same community community.. Solution 4.7 1. Find distinct user pairs
PREFIX soc: SELECT ?u1 ?u2 SELECT WHERE { ?u1 soc:isMemberOf/^soc:isMem soc:isMemberOf/^soc:isMemberOf berOf ?u2. FILTER FIL TER (?u (?u1 1 != ?u2). ?u2). } 2. Find the users that are members of more than one community. Retrieve the member and
4.1 SPARQL Quer y
45
the count of communities that she is in.
PREFIX soc: SELECT ?u (count(? SELECT (count(?c)) c)) AS ?count_me ?count_mem_in m_in_comm _comm WHERE { ?u soc:is soc:isMem Member berOf Of ?c. ?c. } GR GROU OUP P BY ?u HAVING COUNT(?c)>1 3. Find the communities communities that have observed increase increase in membe memberr registratio registration n from 2015 to 2016.
PREFIX soc: SELECT ?communi SELECT ?community ty ?regin_2 ?regin_2015 015 ?regin_20 ?regin_2016 16 WHERE { {
SELECT ?communit SELECT ?community y ?regin_20 ?regin_2015 15 WHERE { ?community soc:hasMembership _:b1. _:b1 soc:year soc:year ?year; ?year; soc:memberjoined soc:memberjoin ed ?regin_2015. FILTER FIL TER (?year (?year = 2015). 2015). }
} { SELECT ?communit SELECT ?community y ?regin_20 ?regin_2016 16 WHERE {
?community soc:hasMembership _:b2. _:b2 soc:year soc:year ?year; ?year; soc:memberjoined soc:memberjoin ed ?regin_2016. FILTER FIL TER (?year (?year = 2016). 2016).
} } FILTER FILTE R (?regin_ (?regin_2016 2016 > ?regin_20 ?regin_2015) 15) }
Exercise 4.8 Consider the following description of movie domain. A movie is characterized by
• Movie has a title
46
Chapter 4. Querying Semantic Web
• Movie has a year of release release • Movie has a genre (action, thriller, drama etc) directed by a director who is a person and has a name • Movie is directed attributes like name, year of birth, age, • Movie has a list of actors. An actor is identified by attributes gender and awards received in different years (e.g., Academy award in 2014). • A movie has rating point (like IMDB rating). rating). • A movie is based on a novel. Answer the following based on the movie data model: 1. Represent the described domain with a graph based data model. Define prefixes and make use of them in your data model. 2. Write SPARQL SPARQL queries corresponding corresponding to the following statements: statements: i. For actors actors born after 1950, retrieve retrieve the actors’ name and awards awards own by them ii. List the movies movies that are based on the same novel. novel. iii. List all the movies for those the average average age of the female actors is greater than that of the male actors. actors. iv iv.. List all the movies where each of the actors in the movies recei received ved an award award.. v. List the thriller movies movies that have been released released after 1980.
4.2 SPARQL SPARQL Algebra & Ev Evaluation aluation There are normal examples of translating SPARQL query into the corresponding algebraic expressions. I have covered covered all most all the cases in the class. class. You may take any SPARQL SPARQL query and 1 peculiarr or generate the corresponding algebra with Apache with Apache Jena . Here, I am trying to put some peculia boundary cases. following SPARQL SPARQL query is syntactically valid or not. If it Exercise 4.9 Determine whether the following is, write down the corresponding SPARQL algebra expression. If not, do a minimal correction. What would be the SPARQL algebra for the minimally corrected version?
PREFIX vCard: PREFIX foaf: SELECT SEL ECT ?name ?name ?url ?url ?title ?title WHERE { OPTION OPT IONAL AL { ?X foaf:n foaf:name ame ?na ?name me . FILTER FILTER isLite isLiteral ral(?n (?name ame) ) . } OPTION OPT IONAL AL { ?X foaf:h foaf:home omepag page e ?url ?url . FILTER FILTER isURI( isURI(?ur ?url) l) . } OPTION OPT IONAL AL { ?X foaf:t foaf:titl itle e ?title ?title . FILTER FILTER isLite isLiteral ral(?t (?titl itle) e) . } }
1
Apache Jena: https://jena.apache https://jena.apache.org/download/ .org/download/
4.2 SPARQL Algebra & Evaluation
47
Solution 4.8 Yes. This is a valid SPARQL query. Though the query do not have a BGP before the first OPTIONAL pattern, it is correct according to SPARQL grammar. The SPARQL algebra would pretend that there is an empty BGP as the first pattern inside (table le unit) in the example) for the first LeftJoin. WHERE block and use this as identity ((tab Following is the corresponding SPARQL algebra:
(Project (?name (Project (?name ?url ?title) ?title) (LeftJoin (LeftJoin (LeftJoin (table (tab le unit), unit), (Bgp (?X foaf:nam foaf:name e ?name)), ?name)), (isLiteral ?name)), (Bgp (?X foaf:hom foaf:homepag epage e ?url)), ?url)), (isURI (isU RI ?url)), ?url)), (Bgp (?X foaf:titl foaf:title e ?title)), ?title)), (isLiteral ?title))))
whether the following following SPARQL SPARQL query is syntactically valid valid or not. If Exercise 4.10 Determine whether it is, write down the corresponding SPARQL algebra expression. If not, do a minimal correction. What would be the SPARQL algebra for the minimally corrected version?
PREFIX vCard: PREFIX foaf: SELECT SEL ECT ?name ?name ?url ?url ?title ?title WHERE { UNION UNI ON { ?X foaf:n foaf:name ame ?name . FILTER FILTER isLitera isLiteral(? l(?nam name) e) . } OPTIONAL OPTION AL { ?X foaf:h foaf:home omepag page e ?url ?url . FILTER FILTER isURI( isURI(?ur ?url) l) . } OPTION OPT IONAL AL { ?X foaf:t foaf:titl itle e ?title ?title . FILTER FILTER isLite isLiteral ral(?t (?titl itle) e) . } }
Solution 4.9 The SPARQL query is syntactically Solution syntactically invalid. A GroupGraphPa GroupGraphPattern ttern should be immediately preceding an UNION graph pattern. The minimal correction is as follows:
PREFIX vCard: PREFIX foaf: SELECT SEL ECT ?name ?name ?url ?url ?title ?title
48
Chapter 4. Querying Semantic Web
WHERE { {} UNION UNI ON { ?X foaf:n foaf:name ame ?name . FILTER FILTER isLitera isLiteral(? l(?nam name) e) . } OPTION OPT IONAL AL { ?X foaf:h foaf:home omepag page e ?url ?url . FILTER FILTER isURI( isURI(?ur ?url) l) . } OPTION OPT IONAL AL { ?X foaf:t foaf:titl itle e ?title ?title . FILTER FILTER isLite isLiteral ral(?t (?titl itle) e) . } } The SPARQL algebra for the minimally corrected version is:
(Project (?name (Project (?name ?url ?title) ?title) (LeftJoin (LeftJoin (Union (table (tab le unit), unit), (Filter (Fil ter (isLitera (isLiteral l ?name) ?name) (Bgp (?X foaf:nam foaf:name e ?name)))) ?name)))), , (Bgp (?X foaf:hom foaf:homepag epage e ?url)), ?url)), (isURI (isU RI ?url)), ?url)), (Bgp (?X foaf:titl foaf:title e ?title)), ?title)), (isLiteral ?title))))
following nested query. query. Write the SPARQL algebra expression. Exercise 4.11 Consider the following nested
PREFIX PREFIX PREFIX PREFIX
rdf: dbo: dbp: rdfs:
SELECT SELE CT distinct distinct ?authNam ?authName e ?influenc ?influenceeNa eeName me ?title ?title WHERE WHE RE CT { ?authNam { SELECT SELE ?authName e ?influen ?influencee cee WHERE WHE RE { ?author ?aut hor rdf:type rdf:type dbo:Write dbo:Writer r . ?author ?aut hor dbo:influ dbo:influence enced d ?influenc ?influencee ee . ?author ?aut hor dbp:name dbp:name ?authName ?authName . } LIMIT LIMIT 1000 1000 } ?influenc ?inf luencee ee dbo:nota dbo:notableW bleWork ork ?work . ?influenc ?inf luencee ee dbp:name dbp:name ?influen ?influenceeN ceeName ame . ?work ?wor k rdfs:labe rdfs:label l ?title ?title . FILTER (LANG(?title)="en"). (LANG(?title)="en"). }
4.2 SPARQL Algebra & Evaluation
49
Solution 4.10 Following is the SPARQL algebra expression:
(Distinct (Project (Pro ject (?authNa (?authName me ?influen ?influenceeNa ceeName me ?title) ?title) (Filte (Fi lter r (= (lang (lang ?title ?title) ) "en") "en") (Join (Slice (Sl ice _ 1000 1000 (Project (?authName ?influencee) (Bgp (?author (?au thor rdf:type rdf:type dbo:Write dbo:Writer) r) (?author dbo:influenced ?influencee) (?author (?au thor dbp:name dbp:name ?authName ?authName) ) ))) (Bgp (?influencee dbo:notableWork ?work) (?influencee dbp:name ?influenceeNa ?influenceeName) me) (?work (?wor k rdfs:labe rdfs:label l ?title) ?title) )))))
knowledge graph in graphical form, write SPARQL queries for a set of Exercise 4.12 Given a knowledge questions. Derive the results thourgh SPARQL algebra and its evaluation.
5. Description Logic
6. Web Ontology Language (OWL)
7. Ontology Rules
Wish you all the best, Plaban
View more...
Comments