题目
1. XML Rdf
Authoring guidelines:
- All elements must have an end tag. 标签有头有尾
- All elements must be cleanly nested (overlapping elements are not allowed). 所有元素必须不能重复
- All attribute values must be enclosed in quotation marks.
- Each document must have a unique first element, the root node.
- 大小写敏感
1 | <book> |
1 | <!--Typed Literals:--> |
- Naming conflicts exist in different XML documents
1 | XML document_1 |
- Solution
1 | XML document_1 |
- 2.Naming conflicts exist in different XML documents
1 | XML document_2 |
- answer
1 | XML document_2 |
- Does the datatype “德国” equals to “德国” @ zh ?
- Answer:不相同,因为他们位于的层次结构不同
- URI 英文字符 IRI任何编码
Equalities for Literals:
“0013^^xsd:integer =“13”^^xsd:integer
“123.0^^xsd:decimal= “00123”1^^xsd:integer (based on data type hierarchy)
Exercise
Does the datatype“德国”equals to“德国”@ zh ?
- 不一样
RDF表示N元关系
- 用一个节点中介
- 利用一个空节点
1 | @prefix sw: <http://www.semanticweb.org/ontology-9/> |
- Represent the following sentence graphically by means of the blank node:
Wikipedia said that Tolkien wrote Lord of the Rings.
- Please represent the following sentences graphically by means of blank nodes.
Jonathon says cherries taste sweet.
1月14日,国家药监局宣布酚酞片停止生产
- Given:
1 | ex:happilyMarriedWith rdfs:subPropertyOf ex:isMarriedTo . |
- 可推出:
1 | ex:pascal ex:isMarriedTo ex:lisa . |
- What can be inferred from the following triples using RDFS semantics?
1 | ex:Postgraduate_student rdfs:subClassOf ex:Student |
1 | ex:John rdf:type ex:Professor |
- What can be inferred from the following triples using RDFS semantics?
1 | ex:Undergraduate_student rdfs:subClassOf ex:Student . |
1 | ex:Professor rdfs:subClassOf ex: University_staff . |
1 | sw:John sw:is_a sw:professors . |
1 | sw:John sw:is_a sw:professors ; |
- Use a RDF graph to represent the sentence “John is working in a company located in Sydney” (bland node can be considered).
Does the datatype “3.14”^^xsd:string equal to “+03.14”^^xsd:string? If not, why?
Answer:不是;这是字符串形式,字符串要考虑每个character,明显两个字符串不一样。
2. OWL
Equivalence between classes, individuals, and properties: 一些等价关系
1 | exp:Athlete owl:equivalentClass exp:SportsPlayer . |
Disjointness between classes: 类别不相交关系
1 | exp:Man owl:disjointWith exp:Woman . |
Intersection of classes: 交集
1 | exp:Mother rdf:type owl:class ; |
- 这里括号里面可以有更多类别
Negation of a class: 类别取反
1 | exp:ABC rdf:type owl:class ; |
Property definitions: object property and data property.对属性的定义(谓词)
1 | ex:friendOf rdf:type owl:ObjectProperty . |
Transitive property: 传递性
1 | exp:ancestor rdf:type owl:TransitiveProperty . |
- Given triples
1 | exp:Thmoas exp:ancestor exp:Jimmy . |
- Then what can we infer from them?
1 | exp:Thmoas exp:ancestor exp:Michael . |
Functional property:
1 | exp:hasMother rdf:type owl:FunctionalProperty . |
Please explain using natural language:
Everyone has only one mother.谓词的函数特性表示他的range取值只能有一个
inverse functional property 具有反函数特性
1 | exp:postgraduateSupervisor rdf:type owl:InverseFunctionalProperty . |
- Please explain using natural language:
Each post-graduate student has only one supervisor.
- 这表示谓语的定义域只能有一个
Symmetric property
1 | exp:friendOf rdf:type owl:SymmetricProperty . |
- Given a triple
1 | exp:Thmoas exp:friendOf exp:Lisa . |
- Then what can we infer from it?
1 | exp:Lisa exp:friendOf exp:Thmoas . |
Inverse relations between properties
1 | exp:ancestor owl:inverseOf exp:descendant . |
- Given a triple
1 | exp:Thmoas exp:ancestor exp:Jimmy . |
- Then what can we infer from it?
1 | exp:Jimmy exp:descendant exp:Thmoas . |
Constraints on properties: universal quantifier ∀任意(谓词限定词)
1 | exp:Person rdf:type owl:Restriction ; |
- What do we know from the above triples?
- If the subject of exp:hasMother comes from the class exp:Person, then the object can be only from the class exp:Women
Constraints on properties: existential quantifier ∃ 存在
1 | exp:SemanticWebPapers rdf:type owl:Restriction ; |
- What do we know from the above triples?
If the subject of exp:publishedIn comes from the class exp:SemanticWebPapers, then the object may be (at least one) from the class exp:AAAIPapers.
A part of the Semantic Web papers were published in AAAI.
Constraints on properties: cardinalities
1 | exp:Person rdf:type owl:Restriction ; |
- Please explain using natural language:
Each person should have two parents.
cardinality也可以换成owl:maxCardinality/ owl:minCardinality,表示最多或者最少
Giraffe is a kind of animal which only eats leaves.
1 | @prefix sw: <http://semanticweb.org/> |
- Please write the corresponding RDF triples (in Turtle) of the following sentence: “Childless Persons are the persons who are not parents”. Note that classes “ChildlessPerson”, “Person”, “Parent” are defined in the namespace http://semanticweb.org/ with the prefix “SW”.
1 | _:x0 rdf:type owl:class; |
- Exercise 1:The father of each person should be a man
1 | exp:Person rdf:type owl:Restriction ; |
- Please useRDF triples (in Turtle) to represent the following sentence: “Each human has only one biological mother who should be a woman” with the classes: “Human”and “Women”, and the property“biologicalMotherOf ”. Each class or property can be defined in the namespace http://semanticweb.org/ with the prefix “SW”.
1 | @prefix sw: <http://semanticweb.org/> |
5) Please write the corresponding RDF triples (in Turtle) of the following sentence: “Grandpas are the men who are grandparents”. Specific classes are defined in the namespace
http://semanticweb.org/. Prefixes are given as follows:
@prefix sw: http://semanticweb.org/ .
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# .
@prefix owl: http://www.w3.org/2002/07/owl# .
1 | _:x rdf:type owl:class ; |
3. Propositional Logic
- Example: Natural Language: Nigiri is a type of Sushi which has ingredient Rice and Fish
- FOL:
∀x.[Nigiri(x) → Sushi(x) ∧ ∃y.[hasIngredient(x,y) ∧ Rice(y)] ∧
∃z.[hasIngredient(x,z) ∧ Fish(z)]] - Are the following valid OWL axioms? If not, why? (class: A,B,C,D, role: R)
- A⨅(B⨆ ∃R)
- (∀R.A⨆B)⨅A
- (A⨅B)¬C⨆D
- Everybody knowing some actor has only envious friends
例1:$\exists$knows.Actor $\subseteq$ $\forall$hasfriend.Envious
用一阶逻辑来改写:
All students that attend only master courses.
例2:Student ⊓∀attendsCourse.MasterCourse
用一阶逻辑改写:
∀x (Student(x) ∧ ∀y(attendsCourse(x,y) ∧ MasterCourse(y)))
例3:自然语言解释:
All students that attend at least one lecture.
Student ⊑∃Attend.Lecture
用一阶逻辑改写:
∀x (Student(x) → ∃y(Attend(x,y) ∧ Lecture(y)))
Example
(1) Any student must attend at least one lecture.
Student ⊑ ∃Attend.Lecture
(2) John is a brother of Mary.
Brother(John,Mary)
(3) Parents are exactly those who are mothers or fathers.
*Parent ≡ Mother ⊔ Father
- Exercise
- A Phd Student is a student who has a supervisor.
2.Animals are not vegetables.
- Express the following sentences in Description Logics.
Li is a student of SEU. Any person who is enrolled in a university is a college student.
- Example: ¬Feamale ⊓ ∃haschild.Human ⊑ Human
- Modify:
Exercise:
Give a model for the ontology:
- $\text{PhD}_\text{student} \sqsubseteq \text{Student}$
- $\text{Student} \sqsubseteq \neg\text{Employee}$, $\text{PhD}_\text{student}(\text{John})$
- $\text{Emploee}(\text{Lisa}),\text{Marriedto}(\text{John},\text{Lisa})$
Answer:
- $\Delta=\{jo,l\}$
- $I_I(\text{John})=jo$
- $I_I(\text{Lisa})=l$
- $I_C(\text{Emploee})={l}$
- $I_C(\text{PhD}_\text{student})={jo}$
- $I_C(\text{Student})={jo}$
- $I_R(\text{Marriedto})={
}$
Inconsistency is often caused by modeling errors. 如果不一致,常常都无法找到一个model
- Unicorn(beauty)
- Unicorn ⊑ Fictitious
- Unicorn ⊑ Animal
- Animal ⊑¬Fictitious
A knowledge base is incoherent if a named class is equivalent to ⊥.
It usually also points to a modeling error. 即通过构造空集可以证明model的错误
- Unicorn ⊑ Fictitious
- Unicorn ⊑ Animal
- Animal ⊓ Fictitious ⊑ ⊥
Express the following sentences in Description Logic.
- Every teacher must teach someone
Teacher $\subseteq \exists$ Teach. Human - Every finger is a bodypart and is a part-of hand.
Finger $\subseteq$ BodyPart $\cap \exists$ PartOf. Hand - Zhang is a teacher of SEU
Teacher (Zhang), TeachIn(Zhang,SEU)
Give a model of the following ontology:
PhD $_{\text {student }}$ U Undergraduatge $_{\text {student }} \sqsubseteq$ Student,
PhD $_{\text {student }}($ John $)$,
Undergraduatge $_{\text {student }}($ Jack $)$,
Sister $($ Lisa,Jack $)$,
Employee $($ Lisa $)$$I_{C}\left(\right.$ Undergraduatge $\left._{\text {student }}\right)=\{j a\}$
$I_{C}\left(\right.$ Phd $\left._{\text {student }}\right)=\{j o\}$
$I_{C}($ Student $)=\{j o, j a\}$
$I_{R}($ Sister $)=\{(l, j a)\}$Give a model of the following ontology
Professor⊑FacultyMember,
Professor(Guilin Qi),
hasAffiliation(Guilin Qi, SEU),
StudentOf(Zhang, Guilin Qi)
A model:
- ∆={a,b,c}
- I(Guilin Qi)=a, I(SEU)=b, I(Zhang)=c
- I( Professor)={a}, I(FacultyMember)={a},
- I(hasAffiliation)={(a,b)},
I(StudentOf)={(c,a)},
Give a model of the following ontology
Write the inferred axioms using description logic after conducting classification in forward reasoning on the following axioms.
Endocarditis $\sqsubseteq$ Heart Disease
Miocardial Infarction $\sqsubseteq$ Heart Disease
Heart Disease $\sqsubseteq$ Disease
Enterococcal Endocarditis $\sqsubseteq$ EndocarditisAnswer
Miocardial_Infarction $\sqsubseteq$ Disease
Endocarditis $\sqsubseteq$ Disease
Enterococcal_Endocarditis $\sqsubseteq$ Heart_Disease
Enterococcal_Endocarditis $\sqsubseteq$ Disease
4. Knowledge Graph Reasoning
Example1:
Example2:
- So what type of Endocarditis is?
Example1:
Classification is to compute all implicit subclass relations by applying rules on a TBox.
利用TBox的规则计算所有子类的依赖关系
Example2:
- Highvalue_Company ⊑ ∃beInvestedBy. Investment_Company
- 高价值公司由投资公司投资。
- Investment_Company ⊑ Financial_Institute
- 投资公司属于金融机构
- ∃beInvestedBy. Financial_Institute ⊑ Solvent_Company
- 借助金融机构投资的公司都是具备偿还能力的 企业。
Answer:
- Highvalue_Company ⊑ ∃beInvestedBy. Financial_Institute
- Highvalue_Company ⊑ Solvent_Company
Example1:
- Rule: If you are human, then you are mortal.
- Human(x)→Mortal(x)
- Question: Is Socrates a mortal?
- Solution: Check whether Mortal(Scorates) or Human(Scorates) is true.
Example2:
- Query: Find all patients with heart diseases, i.e., Heart_Disease(x)
- Rewriting: Endocarditis(x) ⋁ Miocardial_Infarction(x) ⋁ Coronary_disease(x)
可以理解成重写问题
Given the following KG, use query rewriting on the query Person(x) (this query is used for checking whether x is a person) .
Exercize:
Find all sports players with the following KG, i.e., rewrite the query Sports_Player(x).
- Query: Find all sports players
- Rewriting: SportsPlayer(x) ⋁ BasketballPlayer(x) ⋁ FootballPlayer(x) ⋁ TennisPlayer(x)
Example:
PhDStudent ⊑ Student,
PhDStudent ⊑ Employee,
Student ⊑ ¬ Employee
- 以上最终可以退出Student和Employee都是空集,所以找不到一个model
- Inconsistent ontology: ontology without a model.
Example:
PhDStudent ⊑ Student,
PhDStudent ⊑ Employee,
Student ⊑ ¬ Employee,
PhDStudent(John)
- 这里则产生了矛盾
Example: DICE ontology:
- Brain $\sqsubseteq$ CentralNervousSystem $\sqcap$ $\exists$systempart.NervousSystem $\sqcap$ BodyPart $\sqcap$ $\exists$ region.HeadAndNeck $\sqcap$ $\forall$ region.HeadAndNeck
- CentralNervousSystem $\sqsubseteq$ NervousSystem
- BodyPart $\sqsubseteq \neg$ NervousSystem or DisjointWith(BodyPart,NervousSystem)
- Reasoning:
- Brain $\sqsubseteq$ Bodypart $\sqsubseteq$ $\neg$ NervousSystem
- Brain $\sqsubseteq$ CentralNervousSystem $\sqsubseteq$ NervousSystem
- Brain = $\emptyset$
- Brain是空集
- Reasoning:
Example from Foaf:
- Person(timbl)
- Homepage(timbl, http://w3.org/)
- Homepage(w3c, http://w3c.org/)
- Organization(w3c)
- InverseFunctionalProperty(Homepage) (Homepage的domain只有一个值,所以矛盾)
- DisjointWith(Organization, Person)
Example from OpenCyc:
- ArtifactualFeatureType(PopulatedPlace)
- ExistingStuffType(PopulatedPlace)
- DisjointWith(ExistingobjectType,ExistingStuffType)
ArtifactualFeatureType $\sqsubseteq$ ExistingObjectType
ExistingObjectType与ExistingStuddType不相交,但是却拥有相同的实例,所以矛盾
Exercise:
The following ontology is inconsistent, and remove one axiom or assertion in it to make it consistent.
- $\text { Student } \sqsubseteq \neg \text { Employee }$ or $\text { Employee(John)}$ or $\text { PhD }_{\text {student }} \text { (John) }$
1 | %%Facts |
Exercise
Rule:fatherinlawOf(X,Z) :- wifeOf(X,Y), fatherOf(Y,Z)
Fact: wifeOf (YaoMing,YeLi)
Fact: fatherOf (YeLi,YeFa)
Who is the father-in-law of Yao Ming?
fatherinlawOf(YaoMing, YeFa)
5. Knowledge Graph Construction
1 | @base <http://foo.example/DB/> . |
- Please use direct mapping to map the following two relational tables to RDF triples with the base IRI http://foo.example/DB/ and prefix rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns# .
1 | @base <http://foo.example/DB/> . |
Example: database view
1 | Example: |
- Set of RDF triples
1 | <http://data.example.com/employee/7369> rdf:type ex:Employee. |
- R2RML
1 | @prefix rr: <http://www.w3.org/ns/r2rml#>. |
1 | <#TriplesMap2> |
- Please write the R2RML triples map to map the following relational database to RDF triples with prefix rr: http://www.w3.org/ns/r2rml# and prefix ex: http://example.com/ns#(for classes and properties).
- RDF Triples
1 | <http://data.example.com/student/001> ex:name "Zhang". <http://data.example.com/student/002> ex:name "Wang". |
1 | @prefix rr:<http://www.w3.org/ns/r2rml#> . |
Please use direct mapping to map the following three relational tables to RDF triples,
Given:
@base http://foo.example/DB/ .
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#.
1 | Answer: |
\2) Given a relational database and RDF triples, please write corresponding R2RML triples maps which can map the given RDB to RDF.
RDF Triples
1 | <http://data.example.com/student/001> rdf:type ex:Student ; |
1 | Answer: |
- Given a relational database and RDF triples, please write corresponding R2RML triples maps which can map the given RDB to RDF.
1 | <http://data.example.com/student/001> rdf:type ex:Student ; |
6. Triple Extraction from Relational Web Tables
Exercise
- Compute the Levenshtein distance between “kitten” and “sitting”.
- 1+1+1=3
- Compute the Jaccard similarity between “University of California, Davis” and “University of California, Berkeley”in word level.
- Compute the Jaccard similarity between “English”and “England”based on character-level trigrams.
- Please compute the Levenshtein distance between two strings “Saturday” and “Sunday”.
Answer:
Saturday→Sturday (delete a)
Sturday→Surday (delete t)
Surday→Sunday (replace r with n)
Thus, the Levenshtein distance is 3.
- Please compute the Jaccard similarity between “French” and “France” based on character-level bi-grams.
Answer:
Segment “French” and “France” into bi-grams as follows:
French: {Fr, re, en, nc, ch}
France: {Fr, ra, an, nc, ce}
JaccardSimilarity=2/8=0.25
- Please tell the difference between local disambiguation and global disambiguation in entity linking.
Answer:
Local disambiguation does not consider the effects of other referent entities in the same table/ document. With semantic associations between candidate referent entities, global disambiguation can correct mistakes of local disambiguation.
- Why do we need candidate generation in entity linking?
Answer:
Candidate generation can significantly reduce the number of comparison between mentions and entities so that we no longer require to iterate through all entities in the knowledge base for each mention. It does improve the efficiency of entity linking.
7. Knowledge Graph Construction from Semi-Structured Data
- subject: the article entity
- Qiang Yang
- predicate: the target relation
- birthOnDate
- object: the string captured by the brackets of the regular expression
- 1964 births
- 提取完之后需要做property
- Note: Domain and Range checking is necessary.
- In the Wikipedia article page of “Mo Yan”, the categories as follows. Please extract facts from them in turtle using YAGO category maps without domain and range checking, and clarify the subsequent validation steps on the extracted fact.
- YAGO category maps
1 | @prefix expr: <http://www.example.org/resource/> |
- 需要check property的 range和domain
type inference
Given the Wikipedia article page of “IntelliJ IDEA”, including the first sentence, categories, and the infobox. Please write correct types from them (directly use plain strings).
- 第一句话:integrated development environment(IDE)
- categories:Free integrated development environments,Integrated development environments, Java development tools,Products, software
- Infobox:Software
Please extract a taxonomy from the following sentence (denote the answer as A is-a B):
- IBM, AMD, and Intel are High-tech companies using nanotechnology for several years.
- IBM is-a High-tech company
- AMD is-a High-tech company
- Intel is-a High-tech company
- High-tech company is-a company
- IBM is-a company
- AMD is-a company
- Intel is-a company
8. Unstructured Data
- Assuming word with higher TF value and higher IDF value is more relevant to domain.
- TF: Term frequency.
- IDF: Inverse document frequency
Exercise——TF-IDF
- Suppose there are 100 words in a document, and the word “cow” appears three times. The word “cow” has appeared in 1,000 documents, and the total number of documents is 10,000,000. What is the TF-IDF score of the word “cow”?
- 例:假定《亚洲的网络技术》一文长度为1000个词,“亚洲”、“网络”、“技术”各出现20次,则这三个词的“词频”(TF)都为0.02。 然后,搜索Google发现,包含“的”字的网页共有250亿张(假定这就是中文网页总数),包含“亚洲”的网页共有62.3亿张,包含“网络”的网页为0.484亿张,包含“技术”的网页为0.973亿张。计算“亚洲”、“网络”、“技术”的TF-IDF值.
9. Knowledge Graph Alignment
Example:
- trigrams(nikon) $=\{$ nik, iko, kon $\}$
- trigrams(nike) $=\{$ nik, ike $\}$
- $\operatorname{sim}($ nikon, nike $)=1 / 4$
Compute the trigram based similarity between two strings University and Universe
trigrams(University)={Uni,niv,ive,ver,ers,rsi,sit,ity}
trigrams(Universe)={Uni,niv,ive,ver,ers,rse}
$\text{sim(University,Universe)}=5/8$
Compute the Jaccard similarity between the first-order neighbor classes of the classes Car and Automobile from different ontologies.
- StringSimilarity
- len(book)=4,len(Textbook)=8
- substring(book, Textbook)=book
- len(substring)=4
- strIngSimilarity(book, Textbook)=4/4=1
- strIngSimilarity(Textbook, book)=4/8=1/2
- Neighbor Class Set Similarity
- Neighbor(book)={literature,volume}
- Neighbor(Textbook)={volume,Engineering,Science}
- Neighbor Class Set Similarity(book, Textbook)=1/2
- Neighbor Class Set Similarity(Textbook, book)=1/3
- Instance Set Similarity
- Instance(book)={Red Sorghum,Introduction to Algorithm}
- Instance(Textbook)={Red Sorghum}
- Instance Set Similarity(book, Textbook)=1/2
- Instance Set Similarity(Textbook, book)=1
Question: now we have String Similarity, Neighbor Class Set Similarity, Textual Context Similarity, and Instance Set Similarity, please tell which one belongs to the element-level matching techniques? Which one is a structure-level matching technique?
String Similarity,Textual Context Similarity element-level matching techniques
Neighbor Class Set Similarity, Instance Set Similarity structure-level matching technique
Compute the Jaccard similarity between the instance set of class “Book” and that of class “Textbook”.
- $A\cup B$:{Red Sorghum, The Republic of Wine, Data Structure, Introduction to Algorithm, Operation System}
- $A\cap B$:{Data Structure, Introduction to Algorithm}
Jaccard = $\frac{|A\cap B|}{|A\cup B|}=\frac{2}{5}$
Please tell the differences between the
rdf:type
relation and the generalis-a
relation.- general is-a relation be inter-class.
Given the Wikipedia article page of “NumPy”, including the first sentence, categories, and the infobox. Please write correct types from them (directly use plain strings).
Answer
- library, software, Free mathematics software, Free science software, Numerical analysis software for Linux, Numerical analysis software for MacOS, Numerical analysis software for Windows, Numerical programming languages, Python (programming language) scientific libraries, Software using the BSD license.
In the Wikipedia article page of “Tim Berners-Lee”, the categories are as follows. Please extract facts from them in turtle using YAGO category maps and the following prefixes without domain and range checking, and clarify the subsequent validation steps on the extracted fact.
Answer
Extract facts
1
2
3
4
5
6expr:Tim Berners-Lee expp:bornOnDate "1955" ;
expp:hasWonPrize expr:Turing Award ;
expp:hasWonPrize expr:Roval Medal ;
expp:hasWonPrize expr:Medal ;
expp:hasWonPrize expr:Webby Award ;
expp:hasWonPrize expr:Award ;Validation
- Check if
expr:Tim Berners-Lee
is in the domain ofexpp:bornOnDate
and if"1955"
is in the range ofexpp:bornOnDate
; - Check if
expr:Tim Berners-Lee
is in the domain ofexpp:hasWonPrize
and ifexpr:Turing Award
expr:Roval Medal
expr:Medal
expr:Webby Award
expr:Award
is in the range ofexpp:hasWonPrize
.
- Check if
Extract is-a relations form the following sentence, and derive all is-a relations using the transitivity of the is-a relation (in RDF Triple)
- We have rules for keeping animals, such as horses and other farm animals, especially cows and chickens.
- Answer
- farm animal $\to$ animal
- horse $\to$ animal
- cow $\to$ animal
- chicken $\to$ animal
- cow $\to$ farm animal
- chicken $\to$ animal
Compute the TF-IDF values of
knowledge
,AI
,Engineering
with the statistics in the following tables, and rank them (Computing IDF using Ig).Answer
- Doc 1
Doc 2
Doc 3
Please compute the Levenshtein distance between two strings
Saturday
andSunday
.Answer
- Please compute the Jaccard similarity between “French” and “France” based on character-level bi-grams.
- Answer
- $\text{French} = \{Fr,re,en,nc,ch\}$
- $\text{French} = \{Fr,ra,an,nc, ce\}$
- $\text{Jaccard Similarity} = \frac{2}{5}$
- Please tell the difference between local disambiguation and global disambiguation in entity linking.
- Local Disambiguation (局部消歧)
- Only use the contextual information of the given mention and target entity for disambiguation without considering the effects of other referent entities in the same table.
- Global (Collective) Disambiguation (联合消歧)
- Leverage the semantic associations between candidate referent entities to jointly disambiguate all entities for the mentions in a table.
- Local Disambiguation (局部消歧)
- Why do we need candidate generation in entity linking?
- Identifying candidate referent entities of each string mention in table cells when given a knowledge base.
- Select Top k entities for further disambiguation to accelerate.
10. Knowledge Graph Querying
- Please rewrite the following triple pattern by using the same subject only once.
1 | ?a int:number 123789 . |
1 | ?a int:number 123789; |
- Please rewrite the following triple pattern by using the same subject and predicate only once.
1 | ?a string:name ‘Bob’. |
1 | ?a string:name ‘Bob’,’Bobby’,‘Boob’,‘Bob_’. |
Exercise
Given the dataset and the SPARQL query as follows, please write the query results.
1 | # Graph: http://example/addresses |
1 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
name | family |
---|---|
“Bill” | “McKinley” |
“Bill” | “Taft” |
“Bill” | “Clinton” |
- Given the dataset and the SPARQL query as follows, please write the query results.
1 | # Graph: http://example/addresses |
1 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
name | family |
---|---|
“Bill” | “McKinley” |
“Marry” | “Clinton” |
- Matching RDF literals
1 | @prefix dt: <http://example.org/datatype#> . |
- 第一种是找不到结果的,因为不加@是不一样的意义
name | family |
---|---|
“Bill” | “McKinley” |
- Exercise
- Given the dataset and the SPARQL query as follows, please write the query results.
- Answer
name | family |
---|---|
“Bill” | “McKinley” |
“Bob” | |
“Marry” |
- Please write the SPARQL query on “list all volcanos located in Italy or Norway” given the following data.
1 | depedia:Mount_Etna rdf:type umbel-sc:Volcano; |
- Answer
1 | SELECT ?volcano rdf:type umbel-sc:Volcano. |
Exercise
- Given the dataset and the SPARQL query as follows, please write the query results.
- Dataset
1 | # Default graph (stored at http://example.org/dft.ttl) |
- SPARQL query
- FROMNAMD可以省略,因为标明了GRAPH ?g
1 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
- Answer:
who | g | mbox |
---|---|---|
“Bob Hacker” | \http://example.org/bob | \bob@oldcorp.example.org\ |
“Alice Hacker” | \http://example.org/alice |
- Given the dataset and the SPARQL query as follows, please write the query results.
Q1
1 | @prefix org: <http://example.com/ns#> . |
1 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
- 删除后:
1 | _:a org:employeeName "Alice" . |
2. Q2
1 | @prefix org: <http://example.com/ns#> . |
1 | PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
1 | @prefix org: <http://example.com/ns#> . |
- Order the results.
- ASC for ascending (default) and DESC (e.g., DESC(?name)) for descending.
LIMIT
- limits the number of result:
- 只返回5个
OFFSET
- position/index of the first reported results:
- Order of the result should be predictable (combine with ORDER BY)
BINDINGS
VALUE
- add data to the query directly.
- 增加限制
AGGREGATES
- Question: Please use natural language to explain this SPARQL query!
- 查选课人数超过5人的课
- Question: Please use natural language to explain the above SPARQL queries!
Translate the following natural language sentences into SPARQL.
What are all the countries and their capitals in Africa?
1
2
3
4
5# Given
http://dbpedia.org/property/continent,
http://dbpedia.org/resource/Africa,
http://dbpedia.org/ontology/Country,
http://dbpedia.org/ontology/capital.1
2
3
4
5
6
7
8
9PREFIX dbp: <http://dbpedia.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?x ?y
WHERE{
?x rdf:type dbp:ontology/Country .
?x dbp:property/continent dbp:resource/Africa .
?x dbp:ontology/capital ?y .
}What are the devices whose manufacturers are in Korea or Japan?
1
2
3
4
5
6#Given
http://dbpedia.org/property/locationCountry,
http://dbpedia.org/resource/Korea,
http://dbpedia.org/resource/Japan,
http://dbpedia.org/ontology/manufactury,
http://dbpedia.org/ontology/Device.1
2
3
4
5
6
7
8
9
10PREFIX dbp: <http://dbpedia.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?device
WHERE{
?device rdf:type dbp:ontology/Device .
?device dbp:ontology/manufacturer ?location .
{?location dbp:property/locationCountry dbp:resource/Japan .}
UNION {?location dbp:property/locationCountry dbp:resource/Korea .}
}
From the following RDF triples and the result of query, construct a SPARQL query.
1
2
3
4
5
6
7
8
9@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
_:a rdf:type foaf:Person .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@example.com> .
_:a foaf:mbox <mailto:alice@work.example> .
_:b rdf:type foaf:Person .
_:b foaf:name "Bob" .| name | mbox |
| :——— | :——————————————————————————- |
| “Alice” | mailto:alice@example.com |
| “Alice” | mailto:alice@work.example |
| “Bob” | |Answer
1
2
3
4
5
6
7
8
9PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name, ?mbox
WHERE{
?x rdf:type foaf:Person ;
foaf:name ?name .
OPTIONAL {?x foaf:mbox ?mbox .}
}
Given the dataset and query results as follows, please write the corresponding SPARQL Query.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16# Dataset
dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" ;
p:location dbpedia:Italy .
dbpedia:Mount_Xiqiao rdf:type umbel-sc:Volcano ;
rdfs:label "Mount_Xiqiao" ;
p:location dbpedia:China .
dbpedia:Beerenberg rdf:type umbel-sc:Volcano .
rdfs:label "Beerenberg"@en ;
p:location dbpedia:Norway .
# SPARQL Results
dbpedia:Mount_Etna rdfs:label "Etna" ;
rdf:type myTypes:VolcanosOutsideChina.
dbpedia:Beerenberg rdfs:label "Beerenberg"@en;
rdf:type myTypes:VolcanosOutsideChina.Answer TODO
1
2
3
4
5
6
7
8
9
10
11CONSTRUCT {
?v rdfs:label ?name ;
rdf:type myTypes:VolcanosOutsideChina .
}
WHERE {
?v rdf:type umbel-sc:Volcano;
rdfs:label ?name.
OPTIONAL {
?v p:location ?l . FILTER (?l = dbpedia:China)
} FILTER (!BOUND(?l))
}From the following RDF triples and the result of query, construct a SPARQL query.
@prefix foaf: http://xmlns.com/foaf/0.1/ .
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# .
_:a rdf:type foaf:Person .
_:a foaf:name “Alice” .
_:a foaf:mbox alice@example.com .
_:a foaf:mbox alice@work.example .
_:b rdf:type foaf:Person .
_:b foaf:name “Bob” .
10. Cypher
1 | CREATE( |
- Create the relationship using cypher.
1 | CREATE |
- 查询所有节点
1 | MATCH (n) |
- 查询所有电影title
1 | MATCH (movie:Movie) |
- 名叫Oliver Stone相关联的事物标题
1 | MATCH (director {name: 'Oliver Stone'})--(movie) |
- 与人物Oliver Stone相关联的电影标题
1 | MATCH (:Person {name: 'Oliver Stone'})--(movie:Movie) |
- 与人物Oliver Stone相关联的关系类型
1 | MATCH (:Person {name: 'Oliver Stone'})-[r]-(movie) |
- 出演名为‘Wall Street’电影的演员姓名
1 | MATCH (wallstreet:Movie {title: 'Wall Street'})<-[:ACTED_IN]-(actor) |
- 参演或导演名为Wall Street的电影的所有人物
1 | MATCH (wallstreet:Movie {title: 'Wall Street'})<-[:ACTED_IN|:DIRECTED]-(person:Person) |
- 名为Wall Street的电影的中所有的角色
1 | MATCH (wallstreet:Movie {title: 'Wall Street'})<- |
- when nodes already exist, we can use MATCH first, then CREATE
1 | MATCH |
- 查询参演名为‘The American President’的所有演员姓名
1 | MATCH |
- 查询包含角色’Card Fox’的电影名
1 | MATCH |
- 删除名为UNKNOWN的节点
1 | MATCH (n:Person {name: 'UNKNOWN’}) DELETE n |
- 删除数据库中所有节点及与其相连的关系
1 | MATCH (n) DETACH DELETE n |
- 删除名为Andy的节点和与其相连的所有关系
1 | MATCH (n {name: 'Andy’}) DETACH DELETE n |
- 删除Andy的所有KNOWS关系
1 | MATCH (n {name: 'Andy'})-[r:KNOWS]->() DELETE r |
- 删除人物年龄为34岁的所有关系
1 | MATCH (person:Person {age:34})-[r]->() |
- Update a property
1 | MATCH (n {name: 'Andy'}) |
1 | MATCH (n {name: 'Andy'}) |
1 | MATCH (p {name: 'Peter'}) |
- 更新George的年龄为28
1 | MATCH (p {name:'George'}) |
- Write cypher to get the second graph
1 | MATCH |
- Query all relationship types connected by actor Anthony Hopkins
1 | MATCH |
- Given the dataset and natural language query as follows, please write the corresponding Cypher Query.
- Return the movie name containing the role “Bud Fox”
Answer
1
2MATCH (actor) - [:ACTED_IN {role:'Bud Fox'}] -> (movie:Movie)
RETURN movie.title
Delete all the relationships on the person who is 34 years old using Cypher.
Answer
1
2MATCH (n:Person {age: 34}) - [r] -> ()
DELETE r