CS计算机代考程序代写 prolog database CPSC 312 — Functional and Logic Programming

CPSC 312 — Functional and Logic Programming
Project #2 – should be underway….
Last class is next Wednesday!
If the proof of program correctness requires a very large number of different proof rules…. if the validity of a small part of the program depends on properties that can only be established by a scan of the program as a whole, then you know you’ve done a bad job as a language designer, and you don’t need your customers to tell you that. . . . In fact customers don’t tell you – it’s very easy to persuade your customers that anything that goes wrong is their fault and not yours.
Tony Hoare, Null References: The Billion Dollar Mistake, 2009
https://www.infoq.com/presentations/ Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/
CPSC 312 — Lecture 30 1 / 21
©D. Poole 2021

Plan
Last time difference lists
definite clause grammars
natural language interfaces to databases
computer algebra and calculus
Knowledge graphs, triples, reification, URI, RDF, triple store
To come…
Semantic web (today) Ontologies (today) Negation
Proofs
CPSC 312 — Lecture 30
2 / 21
©D. Poole 2021

Clicker Question
In the query
?- rdf(’http://www.wikidata.org/entity/Q34086’,
’http://www.wikidata.org/prop/direct/P25’,M),
rdf(M,’http://schema.org/name’,MN).
What is not a reason to use the constant ’http://www.wikidata.org/entity/Q34086’ instead of using his name ’Justin Bieber’
A the constant denotes the person, not the name
B it has a standard meaning and everyone who uses that
constant means the same thing
C there may be multiple people called ’Justin Bieber’ and the constant denotes a particular one
D the constant is easier for people to find and remember
E these are all reasons
©D. Poole 2021
CPSC 312 — Lecture 30 3 / 21

Knowledge Sharing
Idea: Let’s better represent an intended interpretation, so that computers as well as people can understand it.
A conceptualization is a map from the problem domain into the representation. A conceptualization specifies:
􏰌 What sorts of individuals are being modeled
􏰌 The vocabulary for specifying individuals, relations and
properties
􏰌 The meaning or intention of the vocabulary
If more than one person is building a knowledge base, they must be able to share the conceptualization.
−→ challenge: inter-operability of separately designed knowledge bases
An ontology is a specification of a conceptualization. An ontology specifies the meanings of the symbols in an information system.
CPSC 312 — Lecture 30 4 / 21
©D. Poole 2021

Mapping from a conceptualization to a symbol
©D. Poole 2021
CPSC 312 — Lecture 30 5 / 21

Semantic Web
Ontologies are published on the web (often in machine readable form).
Builders of knowledge bases or web sites adhere to and refer to a published ontology:
􏰌 a symbol defined by an ontology means the same thing across web sites that obey the ontology.
􏰌 if someone wants to refer to something not defined, they publish an ontology defining the terminology.
Others adopt the terminology by referring to the new ontology. In this way, ontologies evolve.
􏰌 Separately developed ontologies can have mappings between them published.
CPSC 312 — Lecture 30 6 / 21
©D. Poole 2021

Interoperability
How can we represent “David went to “Bean Around World” yesterday at 3:00pm”?
How can we ensure that this has meaning for other knowledge bases?
See http://schema.org/ArriveAction http://schema.org/CafeOrCoffeeShop See: http://schema.org/docs/full.html
©D. Poole 2021
CPSC 312 — Lecture 30 7 / 21

Clicker Question
To use schema.org ontology in an application you need to
A use the terms such as ’http://schema.org/ArriveAction’ consistently with the definitions
B Download the schema.org HTML and parse it in Prolog
C Create new definitions from the schema.org definitions
D You can’t use it in applications as none of the classes are actually defined.
©D. Poole 2021
CPSC 312 — Lecture 30 8 / 21

Challenges of building ontologies
They can be huge: finding the appropriate terminology for a concept may be difficult.
How one divides the world can depend on the application. Different ontologies describe the world in different ways.
People can fundamentally disagree about an appropriate structure.
Different knowledge bases can use different ontologies.
To allow KBs based on different ontologies to inter-operate, there must be mapping between ontologies.
It has to be in user’s interests to use an ontology.
The computer doesn’t understand the meaning of the symbols. The formalism can constrain the meaning, but can’t define it.
CPSC 312 — Lecture 30 9 / 21
©D. Poole 2021

Main Components of an Ontology
Individuals the things / objects in the world (not usually specified as part of the ontology)
Classes sets of individuals
Properties between individuals and their values
CPSC 312 — Lecture 30 10 / 21
©D. Poole 2021

Individuals
Individuals are things in the world that can be named. (Concrete, abstract, concepts, reified).
Unique names assumption (UNA): different names refer to different individuals.
The UNA is not an assumption we can universally make: “The Queen”, “Elizabeth Windsor”, etc.
Without the determining equality, we can’t count!
Joe’s mother was in the room. Sam’s cousin was there. Chris’s football coach was there. How many people were in the room?
In OWL we can specify:
rdf (i1, ’owl:SameIndividual’, i2)
rdf (i1, ’owl:DifferentIndividuals’, i3)
CPSC 312 — Lecture 30 11 / 21
©D. Poole 2021

Classes
A class is a set of individuals. E.g., house, building, officeBuilding
One class can be a subclass of another
rdf(house,’owl:SubClassOf’,building)
rdf(officeBuilding,’owl:SubClassOf’,building) (or ’rdfs:subClassOf’)
The most general class is ’owl:Thing’.
Classes can be declared to be the same or to be disjoint:
rdf(house,’owl:EquivalentClasses’,singleFamilyDwelling)
rdf(house,’owl:DisjointClasses’,officeBuilding) Different classes are not necessarily disjoint.
E.g., a building can be both a commercial building and a
residential building.
see http://www.cs.ubc.ca/~poole/cs312/2021/prolog/sem_ web_schema.pl
CPSC 312 — Lecture 30 12 / 21
©D. Poole 2021

Properties and Domains
A property relates an individual and a value. If we have rdf(I,P,V) then P is a property.
The domain of a property is the class of individuals that can be in the head (first element) of a triple with that property. rdf(I,P,V) implies I must be in the domain of property P.
% type(I,T) is true if I is of type T
type(I,T) :-
rdf(I,P,_),
rdf(P,’rdfs:domain’,T).
Example: The domain of property livesIn is person, so rdf (p123, livesIn, b52) implies p123 is a person.
rdf (livesIn, ’rdfs:domain’, person)
CPSC 312 — Lecture 30 13 / 21
©D. Poole 2021

Property Ranges
The range of a property is the class of individuals that can be in the tail (last element) of a triple with that property.
rdf(I,P,V) implies V must be in the range of property P.
The meaning can be defined by the rules:
type(V,T) :-
rdf(_,P,V),
rdf(P,’rdfs:range’,T).
Example: The range of livesIn is placeOfResidence: rdf (livesIn, ’rdfs:range’, placeOfResidence)
CPSC 312 — Lecture 30
14 / 21
©D. Poole 2021

Properties
An ObjectProperty is a property whose range is an individual. A DatatypeProperty is one whose range isn’t an individual,
e.g., is a number or string.
There can also be property hierarchies:
owl:subPropertyOf(livesIn, enclosure) owl:subPropertyOf(principalResidence, livesIn)
CPSC 312 — Lecture 30 15 / 21
©D. Poole 2021

Multiple Inheritance
An individual is usually a member of more than one class. For example, the same person may be a wine expert, a teacher, a football coach, and a mother.
The individual can inherit the properties of all of the classes it is a member of: multiple inheritance.
With default values,what is an individual inherits conflicting defaults from the different classes? multiple inheritance problem.
CPSC 312 — Lecture 30 16 / 21
©D. Poole 2021

Choosing Primitive and Derived Properties
Associate a property value with the most general class with that property value.
Don’t associate contingent properties of a class with the class. For example, if all of current computers just happen to be brown.
CPSC 312 — Lecture 30 17 / 21
©D. Poole 2021

Clicker Question
Suppose we are given the following facts as true:
prop(years_eligibility, ’rdfs:domain’, student).
prop(sam, years_eligibility, 3).
Which is the following can we infer
A Sam is a student
B Sam could a student (but maybe isn’t)
C All students have value 3 for years_eligibility
D We can infer nothing about whether Sam is a student
©D. Poole 2021
CPSC 312 — Lecture 30 18 / 21

Clicker Question
Suppose we are given the following facts as true:
prop(years_eligibility, ’rdfs:domain’, student).
prop(years_eligibility, ’rdfs:domain’, athlete).
prop(sam, years_eligibility, 3).
Which is the following is true
A Sam is both a student and an athlete.
B Sam could be either student or an athlete.
C We can infer nothing about whether Sam is an athlete or a student
D There are no student athletes.
E The facts are inconsistent, and couldn’t possible all be true
©D. Poole 2021
CPSC 312 — Lecture 30 19 / 21

Knowledge Sharing
One ontology typically imports and builds on other ontologies. OWL provides facilities for version control.
Tools for mapping one ontology to another allow inter-operation of different knowledge bases.
The semantic web promises to allow two pieces of information to be combined if
􏰌 they both adhere to an ontology
􏰌 these are the same ontology or there is a mapping between
them.
It is almost always better to use existing ontologies than to define a new one!
CPSC 312 — Lecture 30 20 / 21
©D. Poole 2021

Aristotelian definitions
Aristotle [350 B.C.] suggested the definition if a class C in terms of:
Genus: the super-class
Differentia: the attributes that make members of the class C
different from other members of the super-class
“If genera are different and co-ordinate, their differentiae are themselves different in kind. Take as an instance the genus ’animal’ and the genus ’knowledge’. ’With feet’, ’two-footed’, ’winged’, ’aquatic’, are differentiae of ’animal’; the species of knowledge are not distinguished by the same differentiae. One species of knowledge does not differ from another in being ’two-footed’.”
Aristotle, Categories, 350 B.C. CPSC 312 — Lecture 30 21 / 21
©D. Poole 2021