# Faculty of Engineering and Science

FACULTY OF ENGINEERING AND SCIENCE

E XAM

Course code: / IKT437
Course name: / Knowledge Engineering and Representation
Date: / 30November 2015
Duration: / 4 hours
Number of pages incl. front page / 10
Resources allowed: / Open book exam - all written materials allowed.
(This includes books, handwritten materials, etc., but no electronic equipment.)

Good Luck!

The following UML class diagram describes a way of representing tasks (i.e., exercises) as one may find it in a larger system for representing courses and course content. The model is somewhat limited, e.g., only textual descriptions of tasks are possible (see property hasTaskDescription in Figure 1).

Figure 1

a) Propose tables as you find them in a relational database corresponding to the class diagram above, i.e., give tables with coloum names.

b)Propose RDF triples to represent the class diagram in OWL use the Turtle notation. Have you lost some information when doing the mapping to OWL - give arguments for your view?

c)Do the same as in point b, but this time use the notation shown in Attachment 1, i.e., propose a visual model of the ontology.

d) Extend the model from point c with courses and topics thought in the courses (use the notation given in Attachment 1). Relate the tasks to the topics in some way. It must also be possible to store student solutions of the tasks together with correctness; the correctness is a percentage (set by some teacher), e.g., a task may have been answered 65 % correctly; also, register which student supplied theproposed solution. Which students that are following a course is also to be registered. Make your own assumptions if needed.

The following UML class diagram is given:

Figure 2

The model represents a very simple abstraction of persons who work or study at university.

Each person have onegrade and issupervised by another person. Furthermore, a person can be the supervisor of zero or many persons.

The class Grade specifies an academic grade a person could have. Eachgrade has a name and a value. For example, a grade could have the name'diploma' or 'doctor'. The value is an integer in interval 1-100, where the highest grades have the highest values.

See Attachment 2 for a summary of OCL constructs.

a) See Figure 2. The academic grade of a person’s supervisor must be greaterthan the academic grade of the supervised person.Write an OCL constraint that statesthis.

b)See Figure 2. Write an OCL constraint that statesthat the salary of an employee with grade 'diploma' must be higher than 370000 and if the grade is 'doctor' then the salary should be higher than 500000.

Consider an RDF document that contains information about bus companiesand bus routes. A prefix named bus: identifies a given namespace. The data uses the following classes in the given namespace:

BusCompanyfor representing bus companies (a bus company owns buses and operates bus routes).

BusStopfor representing bus stops along a bus route. Abus stop is a designated place where buses stop for passengers to board or leavea bus.

BusStationfor representing bus stations, which can be origin or target of bus routes.A bus station is a special kind of bus stop.

BusRoutefor representing bus routes. A route has an origin bus station and a target bus station.We assume bus routes have unique labels (i.e., names). We also assume that routes are “one way routes”, e.g., if one route starts in Grimstad and ends in Oslo, a route going from Oslo to Grimstad must have another label (i.e., it is a different route).

The following properties are also used:

rdfs:label links buss stations, bus stops, bus routes, etc., to their names

bus:isOperatedBy links bus route to the bus company that operates it.

bus:startBusStation links a bus route to the bus station where the route starts.

bus:endBusStation links a bus route to the bus station where the routeends.

See Attachment 3 for an example of a possible ontology. Imagine that we have data about many more bus routes, etc.Make your own assumptions if needed.

a)Make a SPARQL querythat lists all the bus routes (i.e., list the rdfs:labelsof the bus routes) together with the bus company that operates it. You are not required to write out the PREFIXdeclarations.

b)Make a SPARQL querythat lists all bus stops (i.e., list the rdfs:labels of the bus stops); avoid duplicates. Bus stations should not be listed. (You are not required to write out the PREFIXdeclarations.)

c)Make a SPARQL querythat lists all bus stops (i.e., list the rdfs:labels of the bus stops) of the bus routes. List in alphabetic order and avoid duplicates. All bus stops should be listed except the one with rdfs:label "Fevik Bus Stop"^^xsd:string.Bus stations should not be listed.(You are not required to write out the PREFIXdeclarations.)

d)Make a SPARQL querythat lists all the bus stops of bus route"Route 1 Kristiansand Arendal"^^xsd:string (this is the identifying label of the bus route) together with the bus company that operates it.The start and end bus stationsshould not be listed.(You are not required to write out the PREFIXdeclarations.)

e)Make a SPARQL querythat lists all the bus stops of bus route "Route 1 Kristiansand Arendal"^^xsd:string(this is the identifying label of the bus route) together with the bus company that operates it. The start and end bus stations should also be listed. (You are not required to write out the PREFIX declarations.)

d)As already mentioned, Attachment 3 describes an ontology for the bus routes. Extend this ontology with triples describing inverse properties of the existing ones where thisis natural.

e)See Attachment 3 which describes an ontology for the bus routes. Give Java Jena code for creating class bus:BusStop and class bus:BusStation. Only a code fragment showing the essentials of this is needed.

f) As already mentioned, Attachment 3 describes an ontology for the bus routes. Give Java Jena code (only a code fragment showing the essential of this is needed) for creating the following:
bus:FevikBusStop rdf:type bus:BusStop ,

owl:NamedIndividual ;

rdfs:label "Fevik Bus Stop"^^xsd:string .

g)How can you set up an ontology model in Jena to do automatic RDFS reasoning?

h) There is a need to calculate the total time a route will take for a bus. E.g., the time it takes to get from one bus stop to the next should be stored (we ignore rush hours, etc.; just a “standard time” is needed). Use OWL and model the information needed and give an example (this should be an extension of the ontology shown in Attachment 3). You may make a model using the syntax of Attachment 1 or you may supply RDF triples in the Turtle format.

Attachment 1

Attachment 2

The following is a list of some of the OCL constructs; this is meant as help when doing the OCL tasks.

OCL Summary
From:

Operations of any OCL type:

• =, >
• oclIsKindOf(OclType) : boolean – true if the object is of type OclType or a subclass
• oclIsTypeOf(OclType) : boolean – true if the object is of type OclType

Operations of any user-deﬁned class:

• allInstances() : Set(user-deﬁned-class) – returns all instances of a given class in a set

Boolean:

• not
• if .. then .. else .. endif
• =, >
• or, and, xor
• implies

Integer and Real:

• .abs(), .max(), .min()
• For Integers: .div(), .mod()
• For Reals: .ﬂoor(), .ceil(), .round(positive position)
• - (negation)
• *, /
• +, -
• <, >, <=, >=
• =, >

Operations on Collections: (applied using the -> operator)

• size() : Natural – returns the number of elements
• isEmpty() : Boolean
• notEmpty() : Boolean
• count(object) : natural – returns the number of occurrences of object in the collection
• includes(object) : Boolean – true if object is an element of the collection
• includesAll(collection) : Boolean – true if collection is a subset of the current collection
• excludes(object) : Boolean – true if object is not an element of the collection
• excludesAll(collection) : Boolean – true if none of the objects in collection is in the currentcollection
• any(boolean expression) : Object – selects one object that satisﬁes the expression at random
• sum() : Real – calculates the sum of all elements in the collection
• = – true if all elements in the two collections are the same. For two bags, the number oftimes an elementis present must also be the same. For two sequences, the order of elements must also be the same.
• union(collection) : Collection
• intersection(collection) : Collection
• including(object) : Collection – returns a collection that includes object
• excluding(object) : Collection – returns a collection where all occurrences of object have been removed
• exists(boolean expression) : Boolean – true if expression is true for at least one element of the collection
• one(boolean expression) : Boolean – true if expression is true for exactly one element of the collection
• isUnique(expression) : Boolean – true if expression is unique for each element in collection
• select(boolean expression) : Collection – returns all elements of the collection that satisfyexpression
• reject(boolean expression) : Collection – returns all elements of the collection that do not satisfy expression
• collect(expression) : Bag – computes expression for each element, and puts all results in abag (or in asequence, if applied to a sequence)
• forAll(boolean expression) : Boolean – true if for all elements in the collection expression istrue
• asSet() : Set – transforms the collection into a set
• asBag() : Bag – transforms the collection into a bag
• sortedBy() : Sequence – produces a sorted sequence containing the elements of the original set

Attachment 3

@prefix bus: < .

@prefix owl: < .

@prefix rdf: < .

@prefix xml: < .

@prefix xsd: < .

@prefix rdfs: < .

# Object Properties

bus:endBusStation rdf:type owl:ObjectProperty .

bus:isOperatedBy rdf:type owl:ObjectProperty ;

rdfs:domain bus:BusCompany ;

rdfs:range bus:BusRoute .

bus:startBusStation rdf:type owl:ObjectProperty .

bus:stopsAtBusStop rdf:type owl:ObjectProperty .

# Classes

bus:BusCompany rdf:type owl:Class .

bus:BusRoute rdf:type owl:Class .

bus:BusStation rdf:type owl:Class ;

rdfs:subClassOf bus:BusStop .

bus:BusStop rdf:type owl:Class .

# Individuals

bus:AgderExpressen rdf:type bus:BusCompany ,

owl:NamedIndividual ;

rdfs:label "Agder Expressen"^^xsd:string .

bus:ArendalBusStation rdf:type bus:BusStation ,

owl:NamedIndividual ;

rdfs:label "Arendal Bus Station"^^xsd:string .

bus:FevikBusStop rdf:type bus:BusStop ,

owl:NamedIndividual ;

rdfs:label "Fevik Bus Stop"^^xsd:string .

owl:NamedIndividual ;

bus:KristiansandBusStation rdf:type bus:BusStation ,

owl:NamedIndividual ;

rdfs:label "Kristiansand Bus Station"^^xsd:string .

bus:Route_191_Skien_Kristiansand rdf:type bus:BusRoute ,

owl:NamedIndividual ;
rdfs:label "Route 191 Skien Kristiansand"^^xsd:string ;

bus:stopsAtBusStop bus:FevikBusStop ,

bus:endBusStation bus:KristiansandBusStation ;

bus:startBusStation bus:SkienBusStation ;

bus:isOperatedBy bus:TelemarkExpressen .

bus:Route_1_Kristiansand_Arendal rdf:type bus:BusRoute ,

owl:NamedIndividual ;
rdfs:label "Route 1 Kristiansand Arendal"^^xsd:string ;
bus:isOperatedBy bus:AgderExpressen ;

bus:endBusStation bus:ArendalBusStation ;

bus:stopsAtBusStop bus:FevikBusStop ,

bus:startBusStation bus:KristiansandBusStation .

bus:Route_2_Arendal_Kristiansand rdf:type bus:BusRoute ,

owl:NamedIndividual ;

rdfs:label "Route 2 Arendal Kristiansand"^^xsd:string ;

bus:isOperatedBy bus:AgderExpressen ;

bus:startBusStation bus:ArendalBusStation ;

bus:endBusStation bus:KristiansandBusStation .

bus:SkienBusStation rdf:type bus:BusStation ,

owl:NamedIndividual ;

rdfs:label "Skien Bus Station"^^xsd:string .

bus:TelemarkExpressen rdf:type bus:BusCompany ,

owl:NamedIndividual ;
rdfs:label "Telemark Expressen"^^xsd:string .

1