CMP2020M – Workshop Knowledge Representations
Frames and OOP
In the lecture the analogy between “Frames” and object-oriented programming had been highlighted.
1. Translate the above semantic network into a representation of frames as started in the lecture. Draw them on a piece of paper or sketch them on the computer.
2. Translate the above semantic network into a Frames representation and think of a class structure in your favourite OOP language (C#, C++, Python, Java,…) to represent this knowledge in a class hierarchy. Make sure you consider the difference between objects and classes.
a. How do you represent the slots?
b. Can you write a very simple program that uses your representations to
print to the screen that Clyde is grey?
c. What are the limitations of your implementation? Where does the
analogy between frames and OOP end?
d. Can you represent the fact that the instance (i.e. object) Nellie likes
apples? If no, why not? If yes, how?
3. Casting the above semantic network into a static class structure obviously limits
the use of it: No knowledge can be added at runtime, and also the class structure wouldn’t scale to thousands of concepts. Thinking further, Frames have a unique identifier (e.g. “elephant”), and then a number of slots to fill with knowledge.
a. Can you implement a simple, but extensible representation of Frames in your favourite programming language? Hint: think about the Dictionary data type in C# and C++, or the data type Map in Java.
b. Insert the above knowledge into your Map of Dictionary-based representation and think about how you would access and search for everything that is grey.
Semantic Network in Prolog:
A simple way to represent a semantic network in Prolog had been shown in the lecture.
instance(nellie, elephant).
instance(clyde, elephant).
subclass(elephant, mammal).
subclass(mammal, animal).
subclass(reptile, animal).
colour(elephant, grey).
size(elephant, large).
likes(nellie, apples).
haspart(mammal, head).
While we are not doing a lot of Prolog programming yet, you can start getting to know the Prolog environment. Open the prolog webservice at http://lcas.lincoln.ac.uk/swish/.
1. Click “Create a Program based on empty” to get started, and copy and paste the
above knowledge (the facts) into the program.
2. Type a query on the right-hand side (“Type your query here”):
colour(X,grey).
Prolog searches its database for true assignments to the variable X, hence it should
return X=elephant
3. Now query for subclass(A,B) (you will have probably seen now that variable
in Prolog are Upper Case, literals are lower case)
SPARQL
Head over to http://dbpedia.org/snorql/. In the lecture, the following query was tried: PREFIX dbo:
SELECT ?name ?birth ?death ?person WHERE {
?person dbo:birthPlace :Ulm .
?person dbo:birthDate ?birth .
?person foaf:name ?name .
?person dbo:deathDate ?death .
FILTER (?birth < "1900-01-01"^^xsd:date) .
FILTER (?death > “1900-01-01″^^xsd:date) .
}
ORDER BY ?name
1. Try something else! Modify the search parameters! This requires to know the right “slots” to search for, Check http://dbpedia.org/ontology/ to see what exists within the dbo: prefix.
2. Read more about dbpedia at http://wiki.dbpedia.org/ and read about the “Web Ontology Language” (OWL), the basis for the so-called semantic web, e.g. here: https://www.w3.org/2001/sw/wiki/OWL
As usual: As soon as you have accomplished your tasks, call for a demonstrator to discuss the solution with them!