CPSC 312 — Functional and Logic Programming
Project #2 – should be underway….
Talk to a TA if you want to change your project, or it has drifted from what was originally proposed.
“Pascal [Java] is for building pyramids – imposing, breathtaking, static structures built by armies pushing heavy blocks into place. Lisp [Haskell/Prolog] is for building organisms – imposing, breathtaking, dynamic structures built by squads fitting fluctuating myriads of simpler organisms into place.
…
the pyramid must stand unchanged for a millennium; the organism must evolve or perish.”
– Alan J. Perlis, Foreword to “Structure and Interpretation of Computer Programs”, 1985, 1996
CPSC 312 — Lecture 29 1 / 13
©D. Poole 2021
Plan
Last time difference lists
definite clause grammars
natural language interfaces to databases computer algebra and calculus
Today
Knowledge graphs, triples, reification, URI, RDF, triple store Semantic web
Ontologies
CPSC 312 — Lecture 29 2 / 13
©D. Poole 2021
Knowledge Graphs and Ontologies
Is there a flexible way to represent relations?
How can knowledge bases be made to interoperate semantically?
CPSC 312 — Lecture 29 3 / 13
©D. Poole 2021
Choosing Individuals and Relations
How to represent: “Pen #7 is red.” red(pen7). It’s easy to ask “What’s red?”
Can’t ask “what is the color of pen7?”
color(pen7, red). It’s easy to ask “What’s red?” It’s easy to ask “What is the color of pen7?” Can’t ask “What property of pen7 has value red?”
prop(pen7, color, red). It’s easy to ask all these questions.
prop(Individual, Property, Value) is the only relation needed: called individual-property-value representation
or triple representation
CPSC 312 — Lecture 29 4 / 13
©D. Poole 2021
Universality of prop
To represent “a is a parcel”
prop(a, type, parcel), where type is a special property.
Then parcel is a class.
prop(a, parcel, true), where parcel is a Boolean property.
Here parcel is the characteristic function of the class.
CPSC 312 — Lecture 29 5 / 13
©D. Poole 2021
Reification
To represent scheduled(cs312, 101, 1200, dmp310). “section 101 of course cs312 is scheduled at 12:00 in room dmp310.”
Let b123 name the booking: prop(b123, course, cs312). prop(b123, section, 101). prop(b123, time, 1200). prop(b123, room, dmp310).
We have reified the booking.
Reify means: to make into an individual. What if we want to add the year?
What if we want to add the instructor?
CPSC 312 — Lecture 29
6 / 13
©D. Poole 2021
Semantic Networks / Knowledge Maps /
When you only have one relation, prop, it can be omitted without loss of information.
Logic:
prop(Individual, Property, Value) or
rdf(Individual,Property,Value) triple:
⟨Individual, Property, Value⟩ simple sentence:
Individual Property Value.
Subject Predicate Object. graphically:
Prop
Obj
Val
©D. Poole 2021
CPSC 312 — Lecture 29 7 / 13
An Example Semantic Network
building
room
building room
r107
comp_sci
lemon_laptop_10000
r117
ming
lemon_computer
craig
deliver_to owned_by
model
brand
comp_2347
lemon_disc
packing
weight size
logo color
cardboard_box
light
brown
medium
©D. Poole 2021
CPSC 312 — Lecture 29 8 / 13
Equivalent Logic Program
prop(comp 2347,owned by,craig). prop(comp 2347,deliver to,ming). prop(comp 2347,model,lemon laptop 10000). prop(comp 2347,brand,lemon computer). prop(comp 2347,logo,lemon disc). prop(comp 2347,color,brown).
prop(craig , room, r 107). prop(r107,building,comp sci).
.
©D. Poole 2021
CPSC 312 — Lecture 29 9 / 13
Semantic Web Technologies
XML the Extensible Markup Language provides generic syntax.
⟨tag …/⟩ or
⟨tag …⟩…⟨/tag⟩.
URI a Uniform Resource Identifier is a constant denoting an individual (resource). This name can be shared. Often in the form of a URL to ensure uniqueness.
E.g., https://www.w3.org/People/Berners-Lee/card#i http://www.cs.ubc.ca/~poole/foaf.rdf#david
RDF the Resource Description Framework is a language of triples
OWL the Web Ontology Language, defines some primitive properties that can be used to define terminology. (Doesn’t define a syntax).
CPSC 312 — Lecture 29 10 / 13
©D. Poole 2021
Triple Store
Triple store can be implemented very efficiently with eighthow many indexes.?
SWI Prolog can store 300,000,000 triples on a 64-bit machine with 64 Gb memory, and retrieve them efficiently.
Wikidata
https://www.wikidata.org/wiki/Wikidata:Main_Page
contains about 93 million triples. (Curated. Anyone can edit.) See http://www.cs.ubc.ca/~poole/cs312/2021/prolog/
sem_web.pl
Google’s Knowledge Graph, contains 70 billion triples. Much of the data is from marked-up web pages; see http://schema.org/.
Google’s Knowledge Vault contains 1.6 billion triples. (Learned).
CPSC 312 — Lecture 29
11 / 13
©D. Poole 2021
Clicker Question
What is not a reason for using triples as a representation for relations:
A They can be indexed efficiently, whereas arbitrary relations may require too many indexes or are restricted to index on given keys
B Extra arguments to the relation can be added simply
C They allow for more flexible queries
D These are all reasons
©D. Poole 2021
CPSC 312 — Lecture 29 12 / 13
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).
the reason to use the constant ’http://schema.org/name’ is:
A to make it look complicated and impressive
B it has a standard meaning and everyone who uses that
constant means the same thing
C because schema.org is sponsored by Google, Microsoft, Yahoo and Yandex, and they will be impressed if we use schema.org
D it is part of the semantic web, which is the future of the Internet
E there is no reason to use such a complicated constant when a simple one would do just as well.
©D. Poole 2021
CPSC 312 — Lecture 29 13 / 13