Top Banner
CoFfTeA seminarie 1 CoFfTeA seminarie Maandag 24 november 2003
193

CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

Dec 18, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 1

CoFfTeA seminarie

Maandag 24 november 2003

Page 2: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 2

Agenda (1)

Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker Achtergrond: Peter Demeester

Raamwerk Ontologie Webgebaseerde datarepresentatietalen

Gebruikte tools: Peter Demeester & Nele Custers OilEd WordNet JDom

Jena D2RMap OpenTS

Page 3: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 3

Agenda (2)

Koffie Demonstratie Discussie Drink

Page 4: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 4

Inleiding

CoFfTeA

Page 5: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 5

Goals

Offer software developers better insight in: needs of planning practice the opportunities of component based software

development How software can function with loosely

connected components A component model for timetabling

Page 6: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 6

Further expectations

Semantic Web Technology Suggested by members of the user committee Offers semantics, representation formats,

connectivity, interoperability, logic, … Can it support a development strategy?

Page 7: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 7

An example domain

Timetabling: Group has experience

PATAT, Nurse Rostering, TITAN … Links with the user committee

Planning, scheduling, rostering …

“Build a component framework for timetabling using concepts and tools taken from the semantic web context”

Page 8: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 8

Questions to answer or not

What is a framework? How to build a framework?

What is timetabling? How to incorporate users desires? How to understand the user? How to explain the results?

Page 9: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 9

Questions to answer

What does the semantic web to help? What is ontology? How can ontology speed up development? How can existing tools be used?

Page 10: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 10

Realisations

We developed An ontology for timetabling. A mapping tool for timetabling applications using this

ontology A constraint editor that can use our numbering techniques

developed elsewhere to allow the definition of constraints using the ontology and the results of the mapping

An application framework that is consistent with the ontology and that allows access to the OpenTS metaheuristics framework for optimisation of timetables.

Page 11: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 11

Achtergrond

Raamwerk, ontologie en webgebaseerde

datarepresentatietalen

Page 12: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 12school database

Frameworkevaluatio

n componen

t

constraint

component

Constraints in XML, generated by

the GSCG: Jena, JDom, OilEd source, ..

OpenTS

Jena model

XML D2R mapping

fileSemantic mapping compone

nt

JWNL, WordNet, ontology for timetabling, OilEd source, Jena, JDom,…

Query model in RDQL and Jena

API

Local search component

(semi)-automatic generation of the D2R mapping

file

Page 13: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 13

Raamwerk

Page 14: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 14

Why Component Framework

Conventional software reuse Copy & paste and OO class inheritance Details about implementation are needed (-)

Reusable components Provide software reuse Implementation details are not needed (+) Software development:

Software components as building blocks to develop applications

Software maintenance interchangeable components

Easier, quicker, cheaper development and maintenance (+)

Page 15: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 15

What Is a Component FrameworkOne preferred definition A component framework is a collection of collaborating

components designed for reuse in one or more problem domains

Component framework and class library In OO context, a component framework is often a class

library But a component framework is more than a class library:

target problem domain, between programming language toolkit and application

Page 16: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 16

Criteria for Good Components

Reusable content: generic Well-encapsulated: black-box components

are desired Well-defined interfaces What arguments need a method and what

will be the result? Ease of reuse: e.g. composable Independently deployed

Page 17: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 17

Criteria for Good Component Frameworks

Good individual components: not sufficient Good architecture: framework architecture affects the application

architecture Ease of learning and use

well-organised: layered, categorized for framework developers: to handle complexity of

framework for framework users: easy to find what they need

consistency between components: following conventions in implementation: how they expect

and return info, handle errors, affect environment, and so on

naming strategy: name of classes for domain entities: same as domain terms name of method: reflecting function services (ex. Getters

and setters methods)

Page 18: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 18

Problem Domain

FrameworkApplication

Require-ments

generic

solutions

solutions

Require-ments

Problem Domain, Application and Framework

Page 19: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 19

Component Models

Sun: J2EE language-specific (Java) and platform-independent

Microsoft: .NET Multi-language (but no support yet for Java) and

platform-specific (Windows, not really…)

Page 20: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 20

Ontologie

Page 21: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 21

Pieter Brueghel, de oude: de toren van Babel (1563)

Page 22: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 22

What is an ontology?

An ontology defines a common vocabulary for researchers who need to share information in a domain. It includes machine-interpretable definitions of basic concepts in the domain and relations among them

Page 23: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 23

What is an ontology?

Ontology (following the Oxford English Dictionary): “the science or study of being”

In other words: Theory about the nature of existence, of what types of things exist

The term ontology was introduced by philosophy but AI and Web researchers have co-opted the term for their own jargon

Next examples come from John F Sowa: http://www.jfsowa.com/ontology/ontoshar.htm

Page 24: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 24

Aristotle's categories

Page 25: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 25

Tree of Porphyry

Page 26: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 26

What is an ontology?

No universally agreed meaning for the term Possible definition [Uschold]:

Conceptualisation: a world view; a way of thinking about a domain. “Set of informal rules that constrain the structure of a piece of reality”.Typically: expressed as a set of concepts (entities, attributes, processes), their definitions and their inter-relationships.

Implicit: in someone’s headExplicit: this is called an ontology

Page 27: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 27

What is an ontology?

Ontology is an explicit account or representation of some part of a conceptualisation

Variety of forms: necessarily it will include a vocabulary of terms and some specification of their meaning

Manifestation of a shared understanding of a domain that is agreed between a number of parties.

Page 28: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 28

Kinds of ontologies

Formality: degree of formality by which a vocabulary is created and meaning is specified

Purpose: intended uses of the ontology Subject matter: nature of subject matter that

the ontology is characterising

Page 29: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 29

Formality

Highly informal

Structured informal

semi-formal

Highly formal

Expressed loosely in natural language

Expressed in a

restricted, structured

form of natural language

Expressed in an artificial formally defined language

Precise defined terms with formal semantics, theorems

Page 30: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 30

Purpose (1)

Communication between people: unambiguous (maybe informal) definition

Inter-operability among systems: achieved by translating between different modelling methods paradigms languages software tools

ontology is used as an interchange format

Page 31: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 31

Communication between people

Page 32: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 32

Purpose (Inter-operability)

L1

L4 L3

L2

L4L3

L1 L2

interlingua

T3 T4

T2 T1

Page 33: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 33

Purpose (2)

Systems engineering benefits: Reusability: ontology = basis for formal encoding

of entities, attributes, processes and their inter-relationships in the domain of interest. This may become a reusable/shared component

Knowledge acquisition: increase speed & reliability by using an existing ontology as basis for guiding knowledge acquisition

Page 34: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 34

Purpose (3)

Systems engineering benefits: Reliability: formal representation makes possible

the automation of consistency checking. Specification: ontology can assist in the process

of: identifying requirements of the system understanding the relationships among the

components of the systemand provides a declarative specification of a

software system

Page 35: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 35

Purpose (4)

COMMUNICATIONBetween people &

organisations

INTER-OPERABILITY between systems

Reusable components Reliability

Specification

SYSTEMS ENGINEERING

Page 36: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 36

Genericity (related with purpose)

Extent to which an ontology can/is intended to be reused in a range of different situations:

Upper-level models

Application ontologies

Very generic ontologies: organising portions of human knowledge

Designed for particular applications

Page 37: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 37

Subject matter

Most common categories:

1. Domain ontology (medicine, geology, finance,…)

2. Task, method or problem solving ontology

3. Representation or meta-ontology

Page 38: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 38

What is in an ontology?

An ontology is a formal explicit description of: concepts in a domain of discourse (classes), properties of each concept describing various features, attributes of the concepts (slots or roles or properties), and restrictions on slots (facets or role restrictions)

An ontology together with a set of individual instances of classes constitutes a knowledge base.

Page 39: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 39

What is in an ontology?

Classes are the focus of most ontologies Classes describes concepts in the domain Ex: class of beers represents all beers

specific beers are instances of this class A class can have subclasses that represent

concepts that are more specific than the superclass Ex: you can divide the class of all beers into: dark,

yellow, amber,…Alternatively we can divide the class into pils, kriek, trappist,…

Page 40: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 40

What is in an ontology?

Slots describe properties of classes and instances: Kriek Lindemans is produced by the brewery Lindemans

In practical terms, developing an ontology includes: Defining classes in the ontology Arranging the classes in a taxonomic (subclass-

superclass) hierarchy Defining slots and describing allowed values for these

slots Filling in the values for slots for instances

Page 41: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 41

Webgebaseerde datarepresentatietalen

Page 42: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 42

Problem with ‘current’ web

Designed to improve the exchange of information between different people

Majority of data on the web today is that the form it is published in (HTML) is difficult to use on a large scale

Machines/software programs/agents have trouble processing this information

Need of languages that allow automatic interpretation of content

Page 43: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 43

What is the Semantic Web?

Goal of the SW: make info on the web machine-processable

Think of it as being an efficient way of representing data on the WWW (or as a globally linked database)

Semantic Web is invented by Tim Berners-Lee On a XML conference (XML 2000) in December

2000 T B-L introduced an architecture for the Semantic Web

Page 44: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 44

Architecture of the SW

Page 45: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 45

First layer: URI

items on the web are identified through the use of identifiers

Since each item is considered a resource: identifiers are called Uniform Resource Identifiers

URI can be given to anything Anything that has a URI can be said to be on the

web URI is the foundation of the web Best known URI is the URL

Page 46: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 46

Second layer: XML

XML: acronym for eXtensible Markup Language

Pro: Users can create documents using their own structure and syntax.

XML allows to invent tags suitable for a particular problem

In HTML: number of tags is limited

Page 47: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 47

XML: an example

<?xml version="1.0"?>

<article>

<title>Using web standards for timetabling</title>

<author>Sep Ducamaercke</author>

<author>Per Tedesem</author>

<author>Venghed Banger</author>

<affiliation>KaHo Sint-Lieven,Gent</affiliation>

</article>

Page 48: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 48

The need of a schema language

The freedom of inventing tags can lead to confusion Schemas determine how content should be

formatted XML Schema tells something about syntax Pro: exchange syntactically valid XML documents

between people, organisations,…

Page 49: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 49

Example of an XML Schema

<?xml version="1.0""?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="article"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"

maxOccurs="unbounded"/> <xs:element name="affiliation"

type="xs:string"/> </xs:sequence> </xs:complexType></xs:element>

</xs:schema>

Page 50: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 50

Third layer: RDF & RDF Schema

RDF is a means to make statements that are machine-processable

RDF: short for Resource Description Framework

Goal: add formal semantics to the web

Page 51: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 51

Example

ArticleX has creator Sep Ducamaercke RDF is just a model for representing

metadata Representation: labeled graphs or translate

to XML

http://www.kahosl.be/articleX.xml

Sep Ducamaerckecreator

Resource: identified by an

URIProperty:

characterises the resource

Object or the value of the property

<rdf:RDF xmlns:rdf=”http://www.w3.org/1999/02/22-rdf-syntax-ns#” xmlns=“http://sep.ducamaercke.net/rdfexamples”>

<rdf:Description about=“http://www.kahosl.be/articleX.xml”> <creator>Sep Ducamaercke</creator> <rdf:Description>

<rdf:RDF>

Page 52: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 52

RDF Schema

On top of RDF: OO type system, named RDF Schema

RDF Schema is a data typing system for RDF Difference between XML Schema and RDF Schema:

XML Schema is about syntax RDF Schema says something about the interpretation of

RDF statements

Page 53: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 53

Fourth layer: Ontology language

Need of a language to express ontologies in Newest languages use RDFS as a starting point DAML+OIL or OWL (http://www.w3.org/2001/sw/WebOnt/) These language provide methods of saying things

such as inverses, unambiguous properties, unique properties, lists, restrictions, cardinalities, pair wise disjoint lists, datatypes,…

Page 54: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 54

Fifth layer: Logic

This part & the following parts have not been developed yet

Logic layer permits to state any logical principle and permits the computer to reason (by inference) using things from the lower layers

Ex: person sells > 100 products person supersalesman club

Page 55: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 55

Sixth layer: Proof

Once we have systems that follow logic it makes sense to use them to prove things

People around the world could write logic statements

The machine could follow these Semantic “links” to construct proofs

Page 56: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 56

Seventh layer: Trust

Not a real physical layer When the lower layers are ready there will be

trust Metaphor: tells that received data on the SW

can be trusted To reach trust: people should attach a digital

signature

Page 57: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 57

RDF(S) References

http://www.w3.org/TR/rdf-primer/ http://www.cs.vu.nl/~marta/wbkr/slides/wbkr_

c4.pdf http://www710.univ-lyon1.fr/~champin/rdf-tuto

rial/

Page 58: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 58

More info about the Semantic Web

T. Berners-Lee, James Hendler and Ora Lassila, The Semantic Web, Scientific American, May 2001. (http://www.scientificamerican.com/2001/0501issue/0501berners-lee.html)

S. B. Palmer, The Semantic Web, Taking Form. (http://infomesh.net/2001/06/swform/)

http://ingenieur.kahosl.be/projecten/swa2002

Page 59: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 59

Gebruikte Tools

Page 60: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 60

Developing ontologies with OilEd

Crash course in using OilEd

http://oiled.man.cs.uk

Page 61: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 61

References

Tutorial on OilEd: http://oiled.man.ac.uk/tutorial/ Ontology Development 101: A Guide to Creating

Your First Ontology (http://protege.stanford.edu/publications/ontology_development/ontology101-noy-mcguinness.html)

Warning: Above paper uses Protégé instead of OilEd

Page 62: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 62

OilEd was used for…

Creating our ontology Representing the ontology in a JTree (we

adapted some of the classes of OilEd) in the mapping component (see later)

Page 63: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 63

OilEd: short

Creating classes (super and subclasses (taxonomy))

Creating properties (super, inverse and subproperties)

subClassOf and sameClassAs Reasoner Axioms (disjoint & subclass) Creating restrictions

Page 64: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 64

An ontology for animals

To get acquainted with OilEd: a little exercise (taken from http://oiled.man.ac.uk/tutorial/)

We will make an ontology of animals

Page 65: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 65

Create classes

Make the superclass animal Add the subclasses cat, sheep, cow, giraffe Add mad cow as subclass of cow

Page 66: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 66

Properties

View class hierarchy: right click on one of the classes and select show hierarchy

Add properties to our classes: therefore define properties

Define the properties: eats and eaten by Eats is inverse property of eaten by Domain of eats is animal, range of eaten by is

animal Describe classes with the assistance of

properties (restrictions)

Page 67: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 67

Restrictions

Restriction is made up of Property along which the class is restricted Type of filler for property Filler for the property

Select animal, add restriction along eats, select filler of Thing

Add 2 extra classes: dog and bone (no subclass of animal)

Select dog and add restriction along eats (type filler = class bone)

Page 68: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 68

Reasoner

Start the reasoner Verify the model View the hierarchy model What is the result? Discard changes Verify the model again Commit changes

Page 69: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 69

Individuals

Add class heavenly body Select tab Individuals Add Individual sun (is an instance of

heavenly body) Add moon and mars

Page 70: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 70

Sets

Add property: howls at Add class: wolf (no superclass) Add restriction along howls at Filler type: set, choose moon

Page 71: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 71

SubclassOf vs SameClassAs

SubclassOf descriptions are necessary conditions. In other words: necessary for class membership, not sufficient to describe membership

SameClassAs descriptions are necessary and sufficient conditions. In other words: necessary for class membership, and sufficient to describe membership

SameClassAs defined description (complete definition)

SubclassOf primitive description

Page 72: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 72

SubclassOf vs SameClassAs

Add class person (no superclass) Add class werewolf (subclass of person) Add restriction to werewolf (property of howls at,

filler type set (moon)) Verify! View class hierarchy! Comment? Change Property setting from SubclassOf to

SameClassAs (of the class Wolf) Verify model and view class hierarchy

Page 73: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 73

Restriction type (has-class & to-class) Until now: only used has-class Example with other kinds of restrictions Add class plant with subclass grass Add vegetarian (subclass of animal and defined as

SameClassAs) Property restriction: eats, filler plant Change superclass of cow to vegetarian Add new disjoint axiom: plant & animal are disjoint Add property restriction eats with filler sheep to mad cow Verify model! Remarks?

Page 74: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 74

To-class

Vegetarians eat only plants (change restriction to to-class)

Select vegetarian, select restriction, change type to to-class

Verify model Inconsistency (mad cow)

Page 75: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 75

Restriction types

Restriction types logical quantifiers Has-class To-class

Page 76: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 76

Restriction type - cardinality

This allows us to define the number of fillers a slot may have

Example: Add new subclass of animal called biped Set SameClassAs property and add property

restriction on has foot with filler foot Change restriction to exact cardinality 2 Select person class

Page 77: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 77

Restriction type - cardinality

Create restriction on has foot with filler foot Change cardinality of restriction to exact 2 Verify model! Person should appear under biped

Page 78: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 78

Developed ontologies

Developed 2 ontologies (in OilEd & …NotePad) School timetabling ontology (loosely based on

OZONE) Ontology for events (loosely based on iCalendar)

Page 79: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 79

iCalendar

iCalendar : document-based format for describing events, to-do lists and journals.

Includes also times, dates, people, events, locations

Used in calendaring and scheduling applications of most major desktop and PDA personal information managers.

Initiative to share calendars on the Internet Described in IETF 2445 (

http://www.ietf.org/rfc/rfc2445.txt)

Page 80: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 80

WordNet & JWNL

Page 81: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 81

WordNet

Dictionary with knowledge of a native English speaker

English nouns, verbs, adjectives and adverbs are organized into synonym sets

Different relations link the synonym sets

Page 82: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 82

JWNL (Java WordNet Library)

Java API for accessing WordNet net.didion.jwnl.data all data objects that contain

information from the dictionary net.didion.jwnl.data.list objects that hold the

results of relationship operations net.didion.jwnl.data.relationship Tools for finding

pointer relationships between two words. net.didion.jwnl.dictionary interface into the

dictionary, contains all the methods needed for looking up words

Page 83: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 83

import net.didion.jwnl.*;import net.didion.jwnl.dictionary.*;import net.didion.jwnl.data.*;import net.didion.jwnl.data.list.*;import net.didion.jwnl.util.*;import java.io.*;

public class Example{

public static void main(String [] args){     try{            JWNL.initialize(new FileInputStream("C:\\jwnl\\file_properties.xml"));            IndexWord W1 = Dictionary.getInstance().getIndexWord(POS.NOUN, args[0]);            IndexWord W2 = Dictionary.getInstance().getIndexWord(POS.NOUN, args[1]);                RelationshipList list =                 Relationship.findRelationships(W1.getSense(1), W2.getSense(1), PointerType.HYPERNYM);            System.out.println("Relationship between " + W1.getLemma() + " and " + W2.getLemma() + ":");            PointerTargetNodeList ptnl = ((Relationship)list.get(0)).getNodeList();           

Page 84: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 84

int commonParentIndex = ((AsymmetricRelationship)list.get(0)).getCommonParentIndex();

            PointerTargetNode ptn = (PointerTargetNode) ptnl.get(commonParentIndex);            Synset synset = ptn.getSynset();            for(int i=0; i<synset.getWordsSize(); i++)            {                System.out.print(synset.getWord(i).getLemma() + " ");            }            System.out.println();        }        catch(Exception e)        {            e.printStackTrace();            System.exit(-1);        }     }}

Page 85: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 85

Output

C:\ > java Relation ear noseRelationship between ear and nose:sense_organ sensory_receptor receptor

C:\ > java Relation nurse teacherRelationship between nurse and teacher:professional professional_person

Page 86: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 86

Manipulating XML documents

JDOM

http://jdom.org

Page 87: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 87

JDOM

What? Open source, tree-based API for processing/manipulating/parsing/creating XML data/documents with Java

JDOM represents an XML document as tree composed of elements, attributes, comments, processing instructions, text nodes, CDATA,…

Entire tree is available at any time If document is loaded into memory, the document

can be modified by JDOM

Page 88: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 88

JDOM

JDOM tree is fully read-write All parts of tree can be moved, deleted, and

added to After finishing working in memory: serialise it

back to disk or onto a stream

Page 89: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 89

JDOM references

Java & XML, Brett McLaughlin, O’Reilly (ISBN : 0-596-00197-5)

Processing XML with Java, Elliotte Rusty Harold, Addison-Wesley Pub Co (ISBN: 0201771861), also available on-line: http://cafeconleche.org/books/xmljava/

Simplify XML programming with JDOM, Wes Biggs and Harry Evans, IBM DeveloperWorks (http://www-106.ibm.com/developerworks/java/library/j-jdom/)

Page 90: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 90

JDOM was used for…

Creating the constraints in XML

Page 91: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 91

Document class Documents are in the package org.jdom.Document From scratch

Document doc = new Document(new Element(“root”));

Page 92: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 92

Create a document & element

Create simple document in JDOM:Document doc = new Document();Element e = new Element(“root”);e.setText(“This is the root”);doc.addContent(e);

Or more compact:Document doc = new Document (new Element(“root”).setText(“This is the root”));

Page 93: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 93

Element class

Get root element

Element root = doc.getRootElement(); list of all child elements

List allChildren = root.getChildren(); get those elements that have this given name

List namedChildren = root.getChildren(“name”); get 1st element with a given name

Element child = root.getChild(“name”);

Page 94: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 94

Well-Formedness

Element constructor check if the element is legal (ex. No forbidden characters)

Add/remove method checks structure: No loops in the tree Exactly one root Consistent namespaces

Page 95: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 95

Attribute class Elements may have attributes:

<address street=“Gebr.Desmetstraat 1” city=“Gent” zip=“9000”></address>

Get attribute:String street = address.getAttributeValue(“street”);int zip = address.getAttribute(“zip”).getIntValue();

Set attribute:address.setAttribute(“country”, “Belgium”);

Remove attributeaddress.removeAttribute(“country”);

Page 96: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 96

Element content

Element may have text content:<city>Gent</city>

To get the content:String city = element.getText();

This returns “\n Gent\n” String city = element.getTextTrim();

returns Gent To change the text content:

element.setText(“A new description”);

Page 97: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 97

XMLOutputter Class

Different kinds of outputDocument doc = new Document(…);XMLOutputter outp = new XMLOutputter(); Rawoutp.output(doc, fileOutputStream);

compactoutp.setTextTrim(true);outp.output(doc, socket.getOutputStream());

pretty outputoutp.setIndent(“ “);outp.setNewlines(true);outp.output(doc, System.out);

Page 98: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 98

Writing XML documents

import org.jdom.*; import org.jdom.output.XMLOutputter; import java.math.BigInteger; import java.io.IOException; public class FibonacciJDOM {

public static void main(String[] args) { Element root = new

Element("Fibonacci_Numbers"); BigInteger low = BigInteger.ONE; BigInteger high = BigInteger.ONE; for (int i = 1; i <= 5; i++) { Element fibonacci = new

Element("fibonacci"); fibonacci.setAttribute("index",String.valueOf(i));

fibonacci.setText(low.toString()); root.addContent(fibonacci);

Page 99: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 99

Writing XML documents

BigInteger temp = high; high = high.add(low); low = temp;

} Document doc = new Document(root); // serialize it onto System.out try {

XMLOutputter serializer = new XMLOutputter(); serializer.setIndent(“ “);

serializer.setNewlines(true);serializer.output(doc, System.out);

} catch (IOException e) {

System.err.println(e); }

} }

•Demo

Page 100: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 100

DTD Suppose the DTD of the previous XML file looks

like:<!ELEMENT Fibonacci_Numbers (fibonacci*)><!ELEMENT fibonacci (#PCDATA)><!ATTLIST fibonacci index CDATA #IMPLIED>

DocType class represents DTDsDocType type = new DocType("Fibonacci_Numbers", "fibonacci.dtd");

Add to the previous JDOM program the following lines:DocType type = new DocType("Fibonacci_Numbers", "fibonacci.dtd"); Document doc = new Document(root, type);

Page 101: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 101

Navigating JDOM Trees

Everything is an object: cast to right type Done by instanceof getChildren() returns only elements (everything else

is missed) -> returns a java.util.List To get everything: use getContent() -> returns a

java.util.List

In this case: not everything is Element

Page 102: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 102

Reading an XML File

import org.jdom.*; import org.jdom.input.SAXBuilder; import java.io.IOException; import java.util.*; public class NodeLister {

public static void main(String[] args) { if (args.length == 0) { System.out.println("Usage: java NodeLister URL"); return;

} SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(args[0]); listNodes(doc, 0);

}

Page 103: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 103

Big example

// indicates a well-formedness error catch (JDOMException e) {

System.out.println(args[0] + " is not well-formed.");

System.out.println(e.getMessage()); } catch (IOException e) {

System.out.println(e); }

} public static void listNodes(Object o, int depth) {

printSpaces(depth); if (o instanceof Element) {

Element element = (Element) o; System.out.println("Element: " + element.getName());

List children = element.getContent(); Iterator iterator = children.iterator(); while (iterator.hasNext()) {

Object child = iterator.next();listNodes(child, depth+1);

} }

Page 104: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 104

Big example

else if (o instanceof Document) {System.out.println("Document"); Document doc = (Document) o; List children = doc.getContent(); Iterator iterator = children.iterator(); while (iterator.hasNext()) {

Object child = iterator.next();listNodes(child, depth+1);

} } else if (o instanceof Comment) {

System.out.println("Comment"); } else if (o instanceof CDATA) {

System.out.println("CDATA section"); // CDATA is a subclass of Text so this test must come // before the test for Text.

} else if (o instanceof Text) {

System.out.println("Text"); } else if (o instanceof EntityRef) {

System.out.println("Entity reference"); }

Page 105: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 105

Big example

else if (o instanceof ProcessingInstruction) {System.out.println("Processing Instruction");

} else {

// This really shouldn't happenSystem.out.println("Unexpected type: "+o.getClass());

}

}

private static void printSpaces(int n) { for (int i = 0; i < n; i++) {

System.out.print(' ');

}

}

}

•Demo

Page 106: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 106

What JDOM does not do

JDOM cannot handle docs larger than the available memory

JDOM treats the doc as logical whole (ex. is the character literally input or input via character reference, or parsing a doc with JDOM and writing it out can create little differences)

JDOM does not provide any real model of the DTD No standard solution to traverse a tree

Page 107: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 107

Introduction to the JENA RDF API

Page 108: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 108

Jena was used for…

Querying the mapped RDF data file

Page 109: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 109

JENA description “Jena is a Java framework for building Semantic

Web applications. It provides a programmatic environment for RDF, RDFS and OWL, including a rule-based inference engine.”*

Valid since version 2.0 (appeared summer 2003) “The Jena Framework includes:

A RDF API Reading and writing RDF in RDF/XML, N3 and N-Triples An OWL API In-memory and persistent storage RDQL – a query language for RDF”*

*Taken from the Jena website

Page 110: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 110

Semantic weblayers

RDF, RDFS, DAML+OIL, OWL, Jena (HP)

XML, XML Schema,DOM, JDOM, SAX,…

Page 111: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 111

JENA

JENA: Full-featured Java API for RDF Open source API Accessible at Source Forge (http://

jena.sourceforge.net) also avaliable at http://www.hpl.hp.com/semweb/jena.htm

Page 112: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 112

JENA interfaces

Vocabulary: Model : A set of statements Statement : A triple of {R, P, O}

Resource : Subject, named by a URI Property : characterises resource Object : May be a resource or a literal

Literal : Non-nested “object” Container : Special resource, collection of things:

BAG : Unordered collection SEQ : Ordered collection ALT : Unordered collection except first element

Page 113: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 113

<< interface >>RDFNode

<< interface >>Resource

<< interface >>Literal

<< interface >>Property

<< interface >>Statement

<< interface >>Container

<< interface >>Bag

<< interface >>Seq

<< interface >>Alt

Page 114: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 114

Model

StatementResource

Property

LiteralProperty

Resource

Resource

Nov. 24, 2003 CoFfTeA

@yahoo

@kahosl

peter

SeminarDC:title

DC:dateTut:tutor

Tut:name

Tut:email

Tut:email

Page 115: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 115

Structure of RDF data (Model)

SESSION

SESSION-GROUP

ATTENDEE

LOCATION

DATE

TEACHER-GROUP

TIMESLOTvalue

value

value

value

value

value

value

value

value

NAME

SESSION_ID

TIMESLOT_ID

DTSTART

DTEND

LOCATION_ID

NAME

value

value

value

value

NAME

DAY

WEEKNR

DATE_ID

SESSIONGROUP_ID

STUDENTGROUP_ID(>=1)

TEACHERGROUP_ID

TEACHER_ID(>=1)

value

value

valueNUMBER_OF_PEOPLE

valueHAS_CAPACITY

Page 116: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 116

JENA Examples

Ex 1 : Building simple RDF Graph with Jena Ex 2 : “Blank node” example Ex 3 : List the statements in the graph Ex 4 : Writing RDF Ex 5 : Reading RDF to a Model object Ex 6 : Navigating Model object Ex 7 : Querying a Model object 1 Ex 8 : Querying a Model object 2 Ex 9 : Using containers

Page 117: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 117http://somewhere/JohnSmith John Smith

vcard.FN

import com.hp.hpl.jena.rdf.model.*;import com.hp.hpl.jena.vocabulary.*;import java.io.PrintWriter;

public class Example_1_new extends Object { // Some definitions static String personURI = "http://somewhere/JohnSmith"; static String fullName = "John Smith";

public static void main (String args[]) { try { // Create an empty graph Model model = ModelFactory.createDefaultModel();

// Create the resource Resource johnSmith = model.createResource(personURI);

// Add the property johnSmith.addProperty(VCARD.FN, fullName);

// Print RDF/XML of model to system output model.write(new PrintWriter(System.out)); } catch (Exception e) { System.out.println("Failed: " + e); } }}

Ex 1: Building a simple RDF Graph with Jena

Page 118: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 118

John Smith

vcard.FN

John Smith

http://somewhere/JohnSmith

vcard.N

vcard.Given vcard.Family

// Some definitionsString personURI = "http://somewhere/JohnSmith";String givenName = "John";String familyName = "Smith";String fullName = givenName + " " + familyName;

// Create an empty ModelModel model = ModelFactory.createDefaultModel();

// Create the resource and add the properties cascading styleResource johnSmith = model.createResource(personURI) .addProperty(VCARD.FN, fullName) .addProperty(VCARD.N, model.createResource() .addProperty(VCARD.Given, givenName) .addProperty(VCARD.Family, familyName) );

Ex 2: “Blank node” example

Page 119: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 119

List statements

// List the statements in the ModelStmtIterator iter = model.listStatements();

// Print out the predicate, subject and object of each statement while (iter.hasNext()) {

Statement stmt = iter.nextStatement(); Resource subject = stmt.getSubject(); // Get the subject Property predicate = stmt.getPredicate(); // Get the predicate RDFNode object = stmt.getObject(); // Get the object System.out.print(subject.toString()); System.out.print(" " + predicate.toString() + " "); if (object instanceof Resource) { System.out.print(object.toString()); } else { // object is a literal System.out.print(" \"" + object.toString() + "\""); } System.out.println(" ."); }

Ex 3: List the statements in the graph

Object can be an instance of a resource or

a literal

Object can be an instance of a resource or

a literal

Page 120: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 120

List statements / Result:

http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N anon:14df86:ecc3dee17b:-7fff .

anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Family "Smith" .

anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-rdf/3.0#Given "John" .

http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN "John Smith" .

Ex 3

John Smith

vcard.FN

John Smith

http://somewhere/JohnSmith

vcard.N

vcard.Given vcard.Family

Page 121: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 121

Reading RDF

InputStream in = Example_5_new.class.getClassLoader() .getResourceAsStream(inputFileName);model.read(new InputStreamReader(in), "");

Writing RDF / RDF XML form

model.write(new PrintWriter(System.out));

Writing RDF / RDF XML abbreviated syntax

model.write(new PrintWriter(System.out), "RDF/XML-ABBREV");

Writing RDF / N-Triples specification

model.write(new PrintWriter(System.out), "N-TRIPLE");

Ex 4 + 5: writing and reading RDF

Page 122: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 122

Navigating a Model / 1

// Read the RDF/XML filemodel.read(new InputStreamReader(in), "");

// Retrieve the John Smith vcard resource from the modelResource vcard = model.getResource(johnSmithURI);

// Retrieve the value of the N propertyResource name = (Resource) vcard.getProperty(VCARD.N).getObject();

// Retrieve the given name propertyString fullName = vcard.getProperty(VCARD.FN).getString();

// Add two nick name properties to vcardvcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman");

Ex 6

Page 123: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 123

Navigating a Model / 2

// Read the RDF/XML filemodel.read(new InputStreamReader(in), "");

// Retrieve the John Smith vcard resource from the modelResource vcard = model.getResource(johnSmithURI);

// Retrieve the value of the N propertyResource name = (Resource) vcard.getProperty(VCARD.N).getObject();

// Retrieve the given name propertyString fullName = vcard.getProperty(VCARD.FN).getString();

// Add two nick name properties to vcardvcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman");

Ex 6

John Smith

John

Smith

http://somewhere/JohnSmith/

vcard:FN

vcard:Nvcard:Given

vcard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vcard:FN

vcard:Nvcard: Given

vcard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vcard:FN

vcard:Nvcard: Given

vcard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vcard:FN

vcard:Nvcard: Given

vcard: Family

Page 124: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 124

Navigating a Model / 3

// Read the RDF/XML filemodel.read(new InputStreamReader(in), "");

// Retrieve the John Smith vcard resource from the modelResource vcard = model.getResource(johnSmithURI);

// Retrieve the value of the N propertyResource name = (Resource) vcard.getProperty(VCARD.N).getObject();

// Retrieve the given name propertyString fullName = vcard.getProperty(VCARD.FN).getString();

// Add two nick name properties to vcardvcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman");

Ex 6

John Smith

vcard.FN

John Smith

http://somewhere/JohnSmith

vcard.N

vcard.Given vcard.Family

vcard

Page 125: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 125

Navigating a Model / 4

// Read the RDF/XML filemodel.read(new InputStreamReader(in), "");

// Retrieve the John Smith vcard resource from the modelResource vcard = model.getResource(johnSmithURI);

// Retrieve the value of the N propertyResource name = (Resource) vcard.getProperty(VCARD.N).getObject();

// Retrieve the given name propertyString fullName = vcard.getProperty(VCARD.FN).getString();

// Add two nick name properties to vcardvcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman");

Ex 6

John Smith

vcard.FN

John Smith

http://somewhere/JohnSmith

vcard.N

vcard.Given vcard.Family

name

vcard

Page 126: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 126

Navigating a Model / 5

// Read the RDF/XML filemodel.read(new InputStreamReader(in), "");

// Retrieve the John Smith vcard resource from the modelResource vcard = model.getResource(johnSmithURI);

// Retrieve the value of the N propertyResource name = (Resource) vcard.getProperty(VCARD.N).getObject();

// Retrieve the given name propertyString fullName = vcard.getProperty(VCARD.FN).getString();

// Add two nick name properties to vcardvcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman");

Ex 6

John Smith

vcard.FN

John Smith

http://somewhere/JohnSmith

vcard.N

vcard.Given vcard.Family

fullname

vcard

name

Page 127: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 127

RDQL query language

RDQL: Provides a way to specify a graph pattern RDQL yields a set of matches It results a set of bindings

Binding = set of name-value pairs

Page 128: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 128

RDQL query language

RDQL Syntax (clauses) SQL Syntax: SELECT: Identifies the variables to be returned to the

application FROM: Specifies the model by URI WHERE: Specifies the graph pattern as a list of triple

patterns AND: Specifies the boolean expressions USING: A way to shorten the length of URIs

Page 129: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 129

RDQL query language examples

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

Page 130: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 130

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?x

WHERE (?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith")

Page 131: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 131

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?x

WHERE (?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith")

Result:x

=============================

<http://somewhere/JohnSmith/>

Result:x

=============================

<http://somewhere/JohnSmith/>

Page 132: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 132

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?x, ?fname

WHERE (?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> ?fname)

Page 133: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 133

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?x, ?fname

WHERE (?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> ?fname)

Result:x | fname

================================================

<http://somewhere/JohnSmith/> | "John Smith"

<http://somewhere/RebeccaSmith/> | "Becky Smith"

<http://somewhere/SarahJones/> | "Sarah Jones"

<http://somewhere/MattJones/> | "Matt Jones"

Result:x | fname

================================================

<http://somewhere/JohnSmith/> | "John Smith"

<http://somewhere/RebeccaSmith/> | "Becky Smith"

<http://somewhere/SarahJones/> | "Sarah Jones"

<http://somewhere/MattJones/> | "Matt Jones"

Page 134: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 134

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?givenName

WHERE (?y <http://www.w3.org/2001/vcard-rdf/3.0#Family> "Smith")

(?y <http://www.w3.org/2001/vcard-rdf/3.0#Given> ?givenName)

Page 135: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 135

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?givenName

WHERE (?y <http://www.w3.org/2001/vcard-rdf/3.0#Family> "Smith")

(?y <http://www.w3.org/2001/vcard-rdf/3.0#Given> ?givenName)

Result:givenName

=========

"John"

"Rebecca"

Result:givenName

=========

"John"

"Rebecca"

Page 136: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 136

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?resource ?givenName

WHERE (?resource <http://www.w3.org/2001/vcard-rdf/3.0#N> ?z),

(?z <http://www.w3.org/2001/vcard-rdf/3.0#Given> ?givenName)

Page 137: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 137

John Smith

John

Smith

http://somewhere/JohnSmith/

vCard:FN

vCard:NvCard:Given

vCard:Family

Sarah Jones

Sarah

Jones

http://somewhere/SarahJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Matt Jones

Matthew

Jones

http://somewhere/MattJones/

vCard:FN

vCard:NvCard: Given

vCard: Family

Becky Smith

Rebecca

Smith

http://somewhere/RebeccaSmith/

vCard:FN

vCard:NvCard: Given

vCard: Family

SELECT ?resource ?givenName

WHERE (?resource <http://www.w3.org/2001/vcard-rdf/3.0#N> ?z),

(?z <http://www.w3.org/2001/vcard-rdf/3.0#Given> ?givenName)

Result:resource | givenName

============================================

<http://somewhere/JohnSmith/> | "John"

<http://somewhere/RebeccaSmith/> | "Rebecca"

<http://somewhere/SarahJones/> | "Sarah"

<http://somewhere/MattJones/> | "Matthew"

Result:resource | givenName

============================================

<http://somewhere/JohnSmith/> | "John"

<http://somewhere/RebeccaSmith/> | "Rebecca"

<http://somewhere/SarahJones/> | "Sarah"

<http://somewhere/MattJones/> | "Matthew"

Page 138: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 138

RDQL query language examples

Other features: USING ClauseSELECT ?resource WHERE (?resource info:age ?age) AND ?age >= 24USING info FOR http://somewhere/peopleInfo#

Querying for PropertiesSELECT ?propWHERE (<http://somewhere/JohnSmith/> , ?prop, "John Smith")

Page 139: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 139

SELECT ?SESSION_ID, ?NUMBER_OF_PEOPLE, ?TIMESLOT_ID, ?DTSTART, ?DTEND, ?SessionGroup_ID, ?DATE_ID, ?Day, ?LOCNAME, ?LOCATION_ID, ?has_capacity, ?COURSE, ?WeekNr, ?WKDY, ?StudentGroup_ID, ?Teacher_ID, ?TeacherGroup_ID

WHERE (?x, <hybrid:SESSION_ID>, ?SESSION_ID),(?x, <hybrid:NAME>, ?COURSE),(?x, <hybrid:NUMBER_OF_PEOPLE>, ?NUMBER_OF_PEOPLE),(?x, <hybrid:timeslot>, ?z),(?z, <hybrid:TIMESLOT_ID>, ?TIMESLOT_ID),(?z, <hybrid:DTSTART>, ?DTSTART),(?z, <hybrid:DTEND>, ?DTEND),(?x, <hybrid:location>, ?v),(?v, <hybrid:LOCATION_ID>, ?LOCATION_ID),(?v, <hybrid:NAME>, ?LOCNAME),(?v, <hybrid:HAS_CAPACITY>, ?has_capacity),(?x, <hybrid:date>, ?r),(?r, <hybrid:DATE_ID>, ?DATE_ID),(?r, <hybrid:DAY>, ?Day),(?r, <hybrid:WEEKNR>, ?WeekNr),(?r, <hybrid:NAME>, ?WKDY),(?x, <hybrid:attendee>, ?m),(?m, <hybrid:sessiongroup>, ?n),(?n, <schooltimetabling:SESSIONGROUP_ID>, ?SessionGroup_ID),(?n, <schooltimetabling:STUDENTGROUP_ID>, ?StudentGroup_ID),(?m, <hybrid:teachergroup>, ?p),(?p, <schooltimetabling:TEACHERGROUP_ID>, ?TeacherGroup_ID),(?p, <schooltimetabling:TEACHER_ID>, ?Teacher_ID)

USING hybrid FOR <http://project.kahosl.be/cofftea/2003/01/hybrid.daml#>,schooltimetabling FOR <http://project.kahosl.be/cofftea/2003/01/schooltimetabling.daml#>

SESSION

SESSIONGROUP

ATTENDEE

LOCATION

DATE

TEACHERGROUP

TIMESLOTvalue

value

value

value

value

value

value

value

value

NAME

SESSION_ID

TIMESL

OT_ID

DTSTART

DTEND

LOCATI

ON_ID

NAME

value

value

value

value

NAME

DAY

WEEKNR

DATE_ID

SESSIO

NGROUP_

ID

STUDENTGROUP_ID(>=1)

TEACHERG

ROUP

_IDTEACHER_ID(>=1)

value

value

valueNUMBER_OF_PEOPLE

valueHAS_CAPACITY

Page 140: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 140

Using RDQL from JAVA

Key classes: Query : The query itself QueryExection : The execution algorithm interface QueryEngine : The local execution algorithm QueryResults : The results iterator ResultBinding : One collection of variable bindings

Page 141: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 141

Using RDQL from JAVA

JAVA code:

String queryString = "SELECT ?x, ?fname "+"WHERE (?x, <http://www.w3.org/2001/vcard-rdf/3.0#FN>, ?fname)";

Query query = new Query(queryString);query.setSource(model);QueryExecution qe = new QueryEngine(query);

QueryResults results = qe.exec();for ( Iterator iter = results ; iter.hasNext();) {

ResultBinding res = (ResultBinding)iter.next() ;Object x = res.get("x") ;Object fname = res.get("fname") ;System.out.println("x = "+x+" fname = "+fname) ;

}results.close() ;

Page 142: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 142

References

Practical RDF, Shelley Powers: http://safari.oreilly.com/?XmlId=0-596-00263-7

Jena Tutorial: http://jena.sourceforge.net/tutorial/

Page 143: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 143

Database to RDF Mapping Language

and Processor

D2R Map

Page 144: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 144

References

D2R MAP - A Database to RDF Mapping Language, Chris Bizer (http://www.wiwiss.fu-berlin.de/suhl/bizer/d2rmap/www2003-D2R-Map.pdf

) D2R language specification, Chris Bizer (

http://www.wiwiss.fu-berlin.de/suhl/bizer/d2rmap/D2R_language%20specification.pdf

)

Page 145: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 145

Why D2R Map?

If you want to use data (stored in DB) on the Semantic Web: map it into RDF (this is the format for the Semantic Web)

Map relational database model to graph-based RDF data model

D2R Map: XML-based language to describe these mappings

Flexible mapping (no change of existing relational database schema)

Adding SQL statements directly in the mapping rules

Page 146: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 146

The Language

For each class in ontology: ClassMap element is used

DataTypePropertyBridge elements for literal properties (with XML datatypes)

References to external resources: ObjectPropertyBridge element

Page 147: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 147

Example

<d2r:ClassMap d2r:type="hybrid:SESSION" d2r:sql="SELECT * FROM ((Session INNER JOIN TimeSlot ON Session.TimeSlotID=TimeSlot.TimeSlotID) INNER JOIN Room ON Session.RoomID=Room.RoomID) INNER JOIN TimeDate ON TimeDate.TimeDateID=Session.TimeDateID" d2r:groupBy="Session.SessionID">

<d2r:DatatypePropertyBridge d2r:property="hybrid:SESSION_ID" d2r:column="Session.SessionID"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:NUMBER_OF_PEOPLE_ID" d2r:column="Session.SGroupID"/>

<d2r:ObjectPropertyBridge d2r:property="hybrid:timeslot“ d2r:referredClass="hybrid:TIMESLOT“ d2r:referredGroupBy="TimeSlot.TimeSlotID"/>

<d2r:ObjectPropertyBridge d2r:property="hybrid:location“ d2r:referredClass="hybrid:LOCATION“ d2r:referredGroupBy="Room.RoomID"/>

<d2r:ObjectPropertyBridge d2r:property="hybrid:date“ d2r:referredClass="hybrid:DATE“ d2r:referredGroupBy="TimeDate.TimeDateID"/>

<d2r:ObjectPropertyBridge d2r:property="hybrid:attendee“ d2r:referredClass="hybrid:ATTENDEE“ d2r:referredGroupBy="Session.SessionID"/>

</d2r:ClassMap>

Page 148: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 148

ClassMap

Used to map the result of a SQL query to a class or to a group of similar classes

2 (required) attributes: sql statement (select data from the DB) and groupBy attribute (columnlist to group the rows of the ResultSet)

Page 149: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 149

ClassMap example

<d2r:ClassMap d2r:type=“goods:Product” d2r:sql=“SELECT * from Products;” d2r:groupBy=“goods.SNr” d2r:uriPattern=“http://example.org/goods#@@Products.SerialNR@@”><d2r:DatatypePropertyBridge d2r:property=“goods:name” d2r:column=“Products.Product_Name”/><d2r:DatatypePropertyBridge d2r:property=“goods:hasKeyword” d2r:column=“Products.Keyword”/>

</d2r:ClassMap>

SerialNR Product_Name Keyword

Q8GR2 Dell Dimension V400 256 MB RAM

Q8GR2 Dell Dimension V400 19” monitor

<rdf:RDF><goods:Product rdf:about=“http://example.org/goods#Q8GR2” goods:name=“Dell Dimension V400”>

<goods:hasKeyword>256 MB RAM</goods:hasKeyword><goods:hasKeyword>19” monitor</goods:hasKeyword>

</rdf:RDF>

D2R Map Fragment

RDF result

Table: Products

Page 150: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 150

Reference to a d2r:ClassMap

Property Mappings

Define bridges between columns of the result set and instance properties

2 different kinds: DatatypePropertyBridge: defines bridge between column of

result set and literal property of instances<d2r:DatatypePropertyBridge d2r:property="hybrid:SESSION_ID"

d2r:column="Session.SessionID"/> ObjectPropertyBridge:

defines bridge between column of result set and object property of instances

<d2r:ObjectPropertyBridge d2r:property="hybrid:location“ d2r:referredClass="hybrid:LOCATION“ d2r:referredGroupBy="Room.RoomID"/>

Page 151: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 151

Elaborated example

<?xml version="1.0" encoding="UTF-8"?><d2r:Map xmlns:d2r="http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RMap/0.1#"

d2r:versionInfo="$Id: AtlasMap.d2r,xml, v 0.1 2003/01/27 Peter Exp $"><d2r:ProcessorMessage d2r:outputFormat="RDF/XML-ABBREV"/><d2r:DBConnection d2r:jdbcDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver" d2r:jdbcDSN="jdbc:microsoft:sqlserver://HAWKING:1433;User=AtlasUser2;Password=gmatlas;db=Atlas" d2r:login="AtlasUser2" d2r:password="gmatlas"/><d2r:Namespace d2r:prefix="hybrid" d2r:namespace="http://project.kahosl.be/cofftea/2003/01/hybrid.daml#"/><d2r:Namespace d2r:prefix="daml" d2r:namespace="http://www.daml.org/2001/03/daml+oil#"/><d2r:Namespace d2r:prefix="rdf" d2r:namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/><d2r:Namespace d2r:prefix="schooltimetabling" d2r:namespace="http://project.kahosl.be/cofftea/2003/01/schooltimetabling.daml#"/>

Page 152: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 152

Elaborated example

<d2r:ClassMap d2r:type="hybrid:SESSION" d2r:sql="SELECT * FROM ((Session INNER JOIN TimeSlot ON Session.TimeSlotID=TimeSlot.TimeSlotID) INNER JOIN Room ON Session.RoomID=Room.RoomID) INNER JOIN TimeDate ON TimeDate.TimeDateID=Session.TimeDateID" d2r:groupBy="Session.SessionID">

<d2r:DatatypePropertyBridge d2r:property="hybrid:SESSION_ID" d2r:column=

"Session.SessionID"/><d2r:DatatypePropertyBridge

d2r:property="hybrid:NUMBER_OF_PEOPLE_ID" d2r:column="Session.SGroupID"/><d2r:ObjectPropertyBridge d2r:property="hybrid:timeslot" d2r:referredClass="hybrid:TIMESLOT" d2r:referredGroupBy="TimeSlot.TimeSlotID"/><d2r:ObjectPropertyBridge d2r:property="hybrid:location" d2r:referredClass="hybrid:LOCATION" d2r:referredGroupBy="Room.RoomID"/><d2r:ObjectPropertyBridge d2r:property="hybrid:date"

d2r:referredClass="hybrid:DATE" d2r:referredGroupBy="TimeDate.TimeDateID"/><d2r:ObjectPropertyBridge d2r:property="hybrid:attendee" d2r:referredClass="hybrid:ATTENDEE" d2r:referredGroupBy="Session.SessionID"/>

</d2r:ClassMap>

Page 153: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 153

Elaborated example

<d2r:ClassMap d2r:type="hybrid:DATE" d2r:sql="SELECT * FROM TimeDate" d2r:groupBy="TimeDate.TimeDateID">

<d2r:DatatypePropertyBridge d2r:property="hybrid:DATE_ID" d2r:column="TimeDate.TimeDateID"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:Day" d2r:column="TimeDate.TDate"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:WeekNr" d2r:column="TimeDate.WeekNR"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:NAME" d2r:column="TimeDate.WeekDay"/>

</d2r:ClassMap>

<d2r:ClassMap d2r:type="hybrid:TIMESLOT" d2r:sql="SELECT * FROM TimeSlot" d2r:groupBy="TimeSlot.TimeSlotID">

<d2r:DatatypePropertyBridge d2r:property="hybrid:TIMESLOT_ID" d2r:column="TimeSlot.TimeSlotID"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:DTSTART" d2r:column="TimeSlot.StartTime"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:DTEND" d2r:column="TimeSlot.EndTime"/>

</d2r:ClassMap>

Page 154: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 154

Elaborated example

<d2r:ClassMap d2r:type="hybrid:ATTENDEE" d2r:sql="SELECT * FROM Session" d2r:groupBy="Session.SessionID">

<d2r:ObjectPropertyBridge d2r:property="hybrid:sessiongroup" d2r:referredClass="hybrid:SESSIONGROUP" d2r:referredGroupBy="Session.SGroupID"/>

<d2r:ObjectPropertyBridge d2r:property="hybrid:teachergroup" d2r:referredClass="hybrid:TEACHERGROUP" d2r:referredGroupBy="Session.TGroupID"/></d2r:ClassMap>

<d2r:ClassMap d2r:type="hybrid:SESSIONGROUP" d2r:sql="SELECT * FROM SGroup" d2r:groupBy="SGroup.SGroupID">

<d2r:DatatypePropertyBridge d2r:property="schooltimetabling:sessiongroup_id" d2r:column="SGroup.SGroupID"/></d2r:ClassMap>

<d2r:ClassMap d2r:type="hybrid:TEACHERGROUP" d2r:sql="SELECT * FROM Teacher INNER JOIN TGroup ON TGroup.TeacherID=Teacher.TeacherID" d2r:groupBy="TGroup.TGroupID">

<d2r:DatatypePropertyBridge d2r:property="schooltimetabling:teachergroup_id" d2r:column="TGroup.TGroupID"/>

<d2r:DatatypePropertyBridge d2r:property="schooltimetabling:teacher_id" d2r:column="Teacher.TeacherID"/></d2r:ClassMap>

Page 155: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 155

Elaborated example

<d2r:ClassMap d2r:type="hybrid:LOCATION" d2r:sql="SELECT * FROM Room" d2r:groupBy="Room.RoomID">

<d2r:DatatypePropertyBridge d2r:property="hybrid:LOCATION_ID" d2r:column="Room.RoomID"/>

<d2r:DatatypePropertyBridge d2r:property="hybrid:NAME" d2r:column="Room.RoomNR"/><d2r:DatatypePropertyBridge

d2r:property="hybrid:has_capacity" d2r:column="Room.TeachingCap"/></d2r:ClassMap>

</d2r:Map>

Page 156: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 156

The OpenTS framework

Page 157: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 157

OpenTS references

OpenTS: http://www-124.ibm.com/developerworks/opensource/coin/OpenTS/index.html

Page 158: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 158

OpenTS description OpenTS is a Java Tabu Search framework that helps

implementing the popular tabu search meta-heuristic in a well-defined, object-oriented design.

OpenTS Framework description: Possibility to define basic elements common to all tabu searches:

a solution structure an objective function a tabu list a move a movemanager ~ defines neighbourhoods

OpenTS uses these basic elements to search the solution space Possible to add dynamic tabu search techniques eg. Reactive tabu lists

thanks to the event handling capabilities (new current solution, new best solution, unimproving move made, …)

Page 159: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 159

Tabu SearchGiven a feasible solution x* with objective function value z*, let x := x* with

z(x) = z*.Iteration:while stopping criterion is not fulfilled do

begin(1) Select best admissible move that transforms x into x' with objective function value z(x‘)(2) Perform tabu list management: compute moves (or attributes) to be set tabu, i.e., update the tabu list(3) Perform exchanges: x := x', z(x) = z(x');

if z(x) < z* then z* := z(x), x* := x endif

endwhile

Result: x* is the best of all determined solutions, with objective function value z*.

After predefined number of iterations

Experimentation No better solution is found

since x iterations

Page 160: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 160

Tabu Search: tabu list

Memory technique that prevents cycling in local minima

Page 161: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 161

Tabu Search Pros Cons

PROS Tabu search yields relatively good solutions to

awkward/previously intractable problems Tabu search is not bounded by linearity Tabu search provides comparable solutions to other

optimisation techniques in a relative short computation time

Page 162: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 162

Tabu Search Pros Cons

CONS Tabu search does not guarantee optimality Tabu search assumes fast performance evaluation

Page 163: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 163

An iteration in OpenTS

New currentsolution

New currentsolution

MoveMangergenerates moves

MoveMangergenerates moves

Objective function

Evaluates moves

Objective function

Evaluates moves

Best non-tabu moveis picked (incl.

aspiration)

Best non-tabu moveis picked (incl.

aspiration)

Move operates on the

current solution

Move operates on the

current solution

Initialsolution

Initialsolution

Page 164: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 164

OpenTS and Tabu Search Moves = Transitions between solutions

Define your neighbourhood. The tabu list reflects the recent move history of the search

+ implements intensification and diversification strategiesTabu tenure = number of iterations a tabu move is considered to remain tabu

A candidate set: Are not tabu Fulfil the aspiration criterion

A candidate is tabu if it is characterized by a predicate on the tabu list The move can not be chosen unless it fulfils the aspiration criteria.

Aspiration criteria = Accepting an improving solution even if generated by a tabu move

Evaluation function (Objective function) denotes the quality of your solution

Page 165: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 165

The OpenTS programming interface

OpenTS requires very little of the objects you give it Methods (“The contract”)

Solution get/setValue()

clone()

toString()

TabuList setTabu(solution, move)

isTabu(solution, move)

MoveManager getAllMoves(solution)

Move operateOn(solution)

hashCode()

ObjectiveFunction evaluate(solution, move)

Page 166: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 166

OpenTSFramework

MySolutionMyTabuLis

t

MyMoveManager_2

MyObjectiveFunction

MyMoveManager_1

MyMoveManager_3

MyMove_1 MyMove_3MyMove_2

Page 167: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 167

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

Page 168: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 168

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

1. Starts with the initial solution

1

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

Page 169: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 169

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

1. Starts with the initial solution

2. The Movemanager generates all possible moves, starting from the given solution

1

2

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

Page 170: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 170

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

1. Starts with the initial solution

2. The Movemanager generates all possible moves, starting from the given solution

3. OpenTS uses the ObjectiveFunction to evaluate each move

Tabu ValueTabu Value

setTabu()

1

2

3

TabuList

TabuList

isTabu()

Page 171: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 171

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

4. OpenTS picks the best move, consulting the tabulist

4

1

2

3

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

Page 172: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 172

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

4. OpenTS picks the best move, consulting the tabulist

5. Places characteristics of current solution in the tabulist

4

1

2

3

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

5

Page 173: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 173

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

4. OpenTS picks the best move, consulting the tabuList

5. Places characteristics of current solution in the tabulist

6. Chosen move operates on the current solution

4

6

1

2

3

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

5

Page 174: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 174

An iteration in OpenTS

Initial solutionInitial

solution

Solution

Solution

Move A

Move A

Move B

Move BMove C

Move CMove D

Move D

getAllMoves() getBestMove()Move

BMove

B

operateOn()

4. OpenTS picks the best move, consulting the tabuList

5. Places characteristics of current solution in the tabulist

6. Chosen move operates on the current solutionIf current solution better than the best one setBestMove

4

6

1

2

3

setTabu()

TabuList

TabuList

isTabu()

Tabu ValueTabu Value

5

Page 175: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 175

OpenTS and Tabu Search Reactive Tabu Search Adjust the length of the tabu list based on

the productivity of the search

Intensification: Explore more thoroughly some parts of the solution space

Diversification: Radical move to another part of the solution space

Page 176: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 176

OpenTS and Tabu Search

Objects can respond to events

Solution

Solution

TabuList

TabuList

MoveManager

MoveManager

ObjectiveFunction

ObjectiveFunction

OpenTSTabuSearch

OpenTSTabuSearch

TabuSearchListener: improvingMoveMade(TabuSearchEvent evt) newBestSolutionFound(TabuSearchEvent evt) newCurrentSolutionFound(TabuSearchEvent evt) noChangeInValueMoveMade(TabuSearchEvent evt) tabuSearchStarted(TabuSearchEvent evt) tabuSearchStopped(TabuSearchEvent evt) unimprovingMoveMade(TabuSearchEvent evt)

implements

TabuSearchEvent

Page 177: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 177

A generic timetabling framework

What to do? Writing a data structure, optimised for fast evaluation Building timetabling-specific components above the standard

OpenTS framework. Neighbourhood implementations

Move objects MoveManager objects Switching between neighbourhoods

TabuList-implementation Evaluation component

Writing handlers to parse RDF and XML data to: read and write scheduling data read constraints data XML & RDF Wrappers

Page 178: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 178

Start

Read the constraints file (XML) and determine which concepts are

necessary for the evaluation

Build the solution space using the mapped data in RDF format

Read the constraints, and put in memory

Initialise the local search algorithm:loads the dimensions, scheduling object,

boundaries of the solution space, …

Init

ialis

ing

Page 179: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 179

Read the constraints file (XML) and determine which concepts are

necessary for the evaluation

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE constraints [

<!ENTITY weekend SYSTEM "weekend.xml">]><constraints> <constraint ID="1" name="constr1" type="Conflict"> <numerator operator=""> <meta metaname="http://project.kahosl.be/cofftea/2003/01/schooltimetabling.daml#STUDENTGROUP"> <STUDENTGROUP_ID/> </meta> </numerator> <denominator logical_operator="AND"> <meta metaname="TIMESLOT"><TIMESLOT_ID/></meta> <meta metaname="DATE"><DATE_ID/></meta> </denominator> <mathematical_operator>LESS_OR_EQUAL_THAN</mathematical_operator> <value>1</value> </constraint>…

Page 180: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 180

Start

Read the constraints file (XML) and determine which concepts are

necessary for the evaluation

Build the solution space using the mapped data in RDF format

Read the constraints, and put in memory

Initialise the local search algorithm:loads the dimensions, scheduling object,

boundaries of the solution space, …

Init

ialis

ing

Page 181: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 181

Build the solution space using the mapped data in RDF format

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:hybrid="http://project.kahosl.be/cofftea/2003/01/hybrid.daml#" xmlns:schooltimetabling="http://project.kahosl.be/cofftea/2003/01/schooltimetabling.daml#"><rdf:Description rdf:nodeID="A6"> <rdf:type rdf:resource="http://project.kahosl.be/cofftea/2003/01/hybrid.daml#SESSION"/> <hybrid:SESSION_ID>4</hybrid:SESSION_ID> <hybrid:timeslot rdf:nodeID="A4"/> <hybrid:location rdf:nodeID="A5"/> <hybrid:date rdf:nodeID="A7"/> <hybrid:attendee rdf:nodeID="A8"/> <hybrid:NAME>Digitale technieken</hybrid:NAME> <hybrid:NUMBER_OF_PEOPLE>13</hybrid:NUMBER_OF_PEOPLE> </rdf:Description> <rdf:Description rdf:nodeID="A8"> <rdf:type rdf:resource="http://project.kahosl.be/cofftea/2003/01/hybrid.daml#ATTENDEE"/> <hybrid:SESSIONGROUP rdf:nodeID="A2"/> <hybrid:TEACHERGROUP rdf:nodeID="A33"/> </rdf:Description> <rdf:Description rdf:nodeID="A2"> <rdf:type rdf:resource="http://project.kahosl.be/cofftea/2003/01/hybrid.daml#SESSIONGROUP"/> <schooltimetabling:SESSIONGROUP_ID>2</schooltimetabling:SESSIONGROUP_ID> <schooltimetabling:STUDENTGROUP_ID>3</schooltimetabling:STUDENTGROUP_ID> <schooltimetabling:STUDENTGROUP_ID>4</schooltimetabling:STUDENTGROUP_ID> <schooltimetabling:STUDENTGROUP_ID>5</schooltimetabling:STUDENTGROUP_ID> </rdf:Description>…

Date

Location

Timeslot Assign

Sessions

Page 182: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 182

Build the solution space using the mapped data in RDF format

Date

Location

Timeslot

Sessions

sessions

Session

Jena API

Mapped data in RDF format

Studentgroup

Lecturer

5 2 7

7 6

Page 183: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 183

Start

Read the constraints file (XML) and determine which concepts are

necessary for the evaluation

Build the solution space using the mapped data in RDF format

Read the constraints and put them in memory

Initialise the local search algorithm:load the dimensions, scheduling object,

boundaries of the solution space, …

Init

ialis

ing

Page 184: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 184

Read the constraints and put them in memory

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE constraints [

<!ENTITY weekend SYSTEM "weekend.xml">]><constraints>

<constraint ID="1" name="constr1" type="Conflict"><numerator operator="">

<meta metaname="http://project.kahosl.be/cofftea/2003/01/schooltimetabling.daml#STUDENTGROUP"><STUDENTGROUP_ID/>

</meta></numerator><denominator logical_operator="AND">

<meta metaname="TIMESLOT"><TIMESLOT_ID/>

</meta><meta metaname="DATE">

<DATE_ID/></meta>

</denominator><mathematical_operator>LESS_OR_EQUAL_THAN</mathematical_operator><value>1</value>

</constraint><constraint ID="3" name="constr3" type="Conflict">

<numerator operator="MAX"><meta metaname="SESSION">

<SESSION_ID/></meta>

</numerator><denominator logical_operator="AND">

<meta metaname="TIMESLOT"><TIMESLOT_ID/>

</meta><meta metaname="DATE">

<DATE_ID/></meta><meta metaname="LOCATION">

<LOCATION_ID/></meta>

</denominator><mathematical_operator>LESS_OR_EQUAL_THAN</mathematical_operator><value>1</value>

</constraint><constraint ID="5" name="constr5" type="Conflict">

<numerator operator="MAX"><meta metaname="SESSION">

<SESSION_ID/></meta>

</numerator><denominator logical_operator="AND">

<meta>&weekend;</meta></denominator><mathematical_operator>LESS_THAN</mathematical_operator><value>1</value>

</constraint><constraint ID="6" name="constr6" type="Soft">

<numerator operator="MAX"><meta metaname="SESSION">

<SESSION_ID/></meta>

</numerator><denominator logical_operator="AND">

<meta metaname="DATE"><DATE_ID>1</DATE_ID>/>

</meta><meta metaname="LOCATION">

<LOCATION_ID>1</LOCATION_ID>/></meta>

</denominator><mathematical_operator>LESS_OR_EQUAL_THAN</mathematical_operator><value>1</value>

</constraint></constraints>

Parameters…Type = 31ID = 1

Parameters…Type = 12ID = 2

Parameters…Type = 32ID = 3

List of constraints

An appropriate evaluation method is called for each constraint

The evaluation function sums the violations of the constraints

memory

XML parsing(DOM and JDOM)

Page 185: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 185

Start

Read the constraints file (XML) and determine which concepts are

necessary for the evaluation

Build the solution space using the mapped data in RDF format

Read the constraints and put them in memory

Initialise the local search algorithm:load the dimensions, scheduling object,

boundaries of the solution space, …

Init

ialis

ing

Page 186: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 186

Consider the actual schedule as the initial solution

Calc

ula

tin

g

Load the first neighbourhood parameters

Initialise the proper ‘Movemanager’;The ‘Movemanager’ determines the neighbourhood

solutions for a given schedule

OpenTS explores the neighbourhood and selects the best move

Stopcriterionsatisfied

Stop

Yes

No

Load new neighbourhood

Next iteration

Page 187: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 187

Overview of neighbourhoods

1a

1b

Translation neighbourhood

Full translation neighbourhood

2a

2b

Swap neighbourhood

Full swap neighbourhood

3 Shift neighbourhood

Date

Location

Timeslot

Date

Location

Timeslot

Date

Location

Timeslot

Date

Location

Timeslot

SchedulingObject

Page 188: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 188

The Movemanager determines which moves are possiblein a given situation

Date

Timeslot

Location

Date

Timeslot

Location

Date

Timeslot

Location

= Move

Page 189: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 189

Pauze

Koffie in de instuif

Page 190: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 190

Demonstratie

Page 191: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 191

Demo

Demo of the mapping component Demo of the constraint component Demo of the timetabling framework

Page 192: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 192

Discussie

Page 193: CoFfTeA seminarie1 Maandag 24 november 2003. CoFfTeA seminarie2 Agenda (1) Welkom: Chris Van Keer (departementsbestuur) Inleiding: Patrick De Causmaecker.

CoFfTeA seminarie 193

Einde

Drink in de instuif