Download presentation
Presentation is loading. Please wait.
1
CoFfTeA seminarie1 Maandag 24 november 2003
2
CoFfTeA seminarie2 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
3
CoFfTeA seminarie3 Agenda (2) Koffie Demonstratie Discussie Drink
4
CoFfTeA seminarie4 Inleiding CoFfTeA
5
CoFfTeA seminarie5 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
6
CoFfTeA seminarie6 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?
7
CoFfTeA seminarie7 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”
8
CoFfTeA seminarie8 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?
9
CoFfTeA seminarie9 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?
10
CoFfTeA seminarie10 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.
11
CoFfTeA seminarie11 Achtergrond Raamwerk, ontologie en webgebaseerde datarepresentatietalen
12
CoFfTeA seminarie12 school database Framework evaluation component constraint component Constraints in XML, generated by the GSCG: Jena, JDom, OilEd source,.. OpenTS Jena model XML D2R mapping file Semantic mapping component 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
13
CoFfTeA seminarie13 Raamwerk
14
CoFfTeA seminarie14 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 (+)
15
CoFfTeA seminarie15 What Is a Component Framework One 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
16
CoFfTeA seminarie16 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
17
CoFfTeA seminarie17 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)
18
CoFfTeA seminarie18 Problem Domain Framework Application Require- ments generic solutions Require- ments Problem Domain, Application and Framework
19
CoFfTeA seminarie19 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…)
20
CoFfTeA seminarie20 Ontologie
21
CoFfTeA seminarie21 Pieter Brueghel, de oude: de toren van Babel (1563)
22
CoFfTeA seminarie22 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
23
CoFfTeA seminarie23 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 http://www.jfsowa.com/ontology/ontoshar.htm
24
CoFfTeA seminarie24 Aristotle's categories
25
CoFfTeA seminarie25 Tree of Porphyry
26
CoFfTeA seminarie26 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 head Explicit: this is called an ontology
27
CoFfTeA seminarie27 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.
28
CoFfTeA seminarie28 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
29
CoFfTeA seminarie29 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
30
CoFfTeA seminarie30 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
31
CoFfTeA seminarie31 Communication between people
32
CoFfTeA seminarie32 Purpose (Inter-operability) L1 L4L3 L2 L4L3 L1L2 interlingua T3T4 T2T1
33
CoFfTeA seminarie33 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
34
CoFfTeA seminarie34 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 system and provides a declarative specification of a software system
35
CoFfTeA seminarie35 Purpose (4) COMMUNICATION Between people & organisations INTER-OPERABILITY between systems Reusable components Reliability Specification SYSTEMS ENGINEERING
36
CoFfTeA seminarie36 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
37
CoFfTeA seminarie37 Subject matter Most common categories: 1. Domain ontology (medicine, geology, finance,…) 2. Task, method or problem solving ontology 3. Representation or meta-ontology
38
CoFfTeA seminarie38 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.
39
CoFfTeA seminarie39 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,…
40
CoFfTeA seminarie40 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
41
CoFfTeA seminarie41 Webgebaseerde datarepresentatietalen
42
CoFfTeA seminarie42 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
43
CoFfTeA seminarie43 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
44
CoFfTeA seminarie44 Architecture of the SW
45
CoFfTeA seminarie45 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
46
CoFfTeA seminarie46 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
47
CoFfTeA seminarie47 XML: an example Using web standards for timetabling Sep Ducamaercke Per Tedesem Venghed Banger KaHo Sint-Lieven,Gent
48
CoFfTeA seminarie48 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,…
49
CoFfTeA seminarie49 Example of an XML Schema
50
CoFfTeA seminarie50 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
51
CoFfTeA seminarie51 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 Ducamaercke creator Resource: identified by an URI Property: characterises the resource Object or the value of the property Sep Ducamaercke
52
CoFfTeA seminarie52 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
53
CoFfTeA seminarie53 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/ ) 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,…
54
CoFfTeA seminarie54 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
55
CoFfTeA seminarie55 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
56
CoFfTeA seminarie56 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
57
CoFfTeA seminarie57 RDF(S) References http://www.w3.org/TR/rdf-primer/ http://www.cs.vu.nl/~marta/wbkr/slides/wbkr_ c4.pdf http://www.cs.vu.nl/~marta/wbkr/slides/wbkr_ c4.pdf http://www710.univ-lyon1.fr/~champin/rdf- tutorial/ http://www710.univ-lyon1.fr/~champin/rdf- tutorial/
58
CoFfTeA seminarie58 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)http://www.scientificamerican.com/2001/0501issue/ 0501berners-lee.html S. B. Palmer, The Semantic Web, Taking Form. (http://infomesh.net/2001/06/swform/)http://infomesh.net/2001/06/swform/ http://ingenieur.kahosl.be/projecten/swa2002
59
CoFfTeA seminarie59 Gebruikte Tools
60
CoFfTeA seminarie60 Developing ontologies with OilEd Crash course in using OilEd http://oiled.man.cs.uk
61
CoFfTeA seminarie61 References Tutorial on OilEd: http://oiled.man.ac.uk/tutorial/http://oiled.man.ac.uk/tutorial/ Ontology Development 101: A Guide to Creating Your First Ontology (http://protege.stanford.edu/publications/ontology_d evelopment/ontology101-noy-mcguinness.html)http://protege.stanford.edu/publications/ontology_d evelopment/ontology101-noy-mcguinness.html Warning: Above paper uses Protégé instead of OilEd
62
CoFfTeA seminarie62 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)
63
CoFfTeA seminarie63 OilEd: short Creating classes (super and subclasses (taxonomy)) Creating properties (super, inverse and subproperties) subClassOf and sameClassAs Reasoner Axioms (disjoint & subclass) Creating restrictions
64
CoFfTeA seminarie64 An ontology for animals To get acquainted with OilEd: a little exercise (taken from http://oiled.man.ac.uk/tutorial/)http://oiled.man.ac.uk/tutorial/ We will make an ontology of animals
65
CoFfTeA seminarie65 Create classes Make the superclass animal Add the subclasses cat, sheep, cow, giraffe Add mad cow as subclass of cow
66
CoFfTeA seminarie66 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)
67
CoFfTeA seminarie67 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)
68
CoFfTeA seminarie68 Reasoner Start the reasoner Verify the model View the hierarchy model What is the result? Discard changes Verify the model again Commit changes
69
CoFfTeA seminarie69 Individuals Add class heavenly body Select tab Individuals Add Individual sun (is an instance of heavenly body) Add moon and mars
70
CoFfTeA seminarie70 Sets Add property: howls at Add class: wolf (no superclass) Add restriction along howls at Filler type: set, choose moon
71
CoFfTeA seminarie71 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
72
CoFfTeA seminarie72 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
73
CoFfTeA seminarie73 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?
74
CoFfTeA seminarie74 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)
75
CoFfTeA seminarie75 Restriction types Restriction types logical quantifiers Has-class To-class
76
CoFfTeA seminarie76 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
77
CoFfTeA seminarie77 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
78
CoFfTeA seminarie78 Developed ontologies Developed 2 ontologies (in OilEd & …NotePad) School timetabling ontology (loosely based on OZONE) Ontology for events (loosely based on iCalendar)
79
CoFfTeA seminarie79 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)http://www.ietf.org/rfc/rfc2445.txt
80
CoFfTeA seminarie80 WordNet & JWNL
81
CoFfTeA seminarie81 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
82
CoFfTeA seminarie82 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
83
CoFfTeA seminarie83 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();
84
CoFfTeA seminarie84 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); } } }
85
CoFfTeA seminarie85 Output C:\ > java Relation ear nose Relationship between ear and nose: sense_organ sensory_receptor receptor C:\ > java Relation nurse teacher Relationship between nurse and teacher: professional professional_person
86
CoFfTeA seminarie86 Manipulating XML documents JDOM http://jdom.org
87
CoFfTeA seminarie87 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
88
CoFfTeA seminarie88 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
89
CoFfTeA seminarie89 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/ 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/)http://www- 106.ibm.com/developerworks/java/library/j-jdom/
90
CoFfTeA seminarie90 JDOM was used for… Creating the constraints in XML
91
CoFfTeA seminarie91 Document class Documents are in the package org.jdom.Document From scratch Document doc = new Document(new Element(“root”));
92
CoFfTeA seminarie92 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”));
93
CoFfTeA seminarie93 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 1 st element with a given name Element child = root.getChild(“name”);
94
CoFfTeA seminarie94 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
95
CoFfTeA seminarie95 Attribute class Elements may have attributes: Get attribute: String street = address.getAttributeValue(“street”); int zip = address.getAttribute(“zip”).getIntValue(); Set attribute: address.setAttribute(“country”, “Belgium”); Remove attribute address.removeAttribute(“country”);
96
CoFfTeA seminarie96 Element content Element may have text content: Gent 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”);
97
CoFfTeA seminarie97 XMLOutputter Class Different kinds of output Document doc = new Document(…); XMLOutputter outp = new XMLOutputter(); Raw outp.output(doc, fileOutputStream); compact outp.setTextTrim(true); outp.output(doc, socket.getOutputStream()); pretty output outp.setIndent(“ “); outp.setNewlines(true); outp.output(doc, System.out);
98
CoFfTeA seminarie98 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);
99
CoFfTeA seminarie99 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
100
CoFfTeA seminarie100 DTD Suppose the DTD of the previous XML file looks like: DocType class represents DTDs DocType 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);
101
CoFfTeA seminarie101 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
102
CoFfTeA seminarie102 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); }
103
CoFfTeA seminarie103 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); } }
104
CoFfTeA seminarie104 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"); }
105
CoFfTeA seminarie105 Big example else if (o instanceof ProcessingInstruction) { System.out.println("Processing Instruction"); } else { // This really shouldn't happen System.out.println( "Unexpected type: "+o.getClass() ); } } private static void printSpaces(int n) { for (int i = 0; i < n; i++) { System.out.print(' '); } Demo
106
CoFfTeA seminarie106 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
107
CoFfTeA seminarie107 Introduction to the JENA RDF API
108
CoFfTeA seminarie108 Jena was used for… Querying the mapped RDF data file
109
CoFfTeA seminarie109 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
110
CoFfTeA seminarie110 Semantic weblayers RDF, RDFS, DAML+ OIL, OWL, Jena (HP) XML, XML Schema, DOM, JDOM, SAX,…
111
CoFfTeA seminarie111 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.htmhttp://jena.sourceforge.net http://www.hpl.hp.com/semweb/jena.htm
112
CoFfTeA seminarie112 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
113
CoFfTeA seminarie113 > RDFNode > Resource > Literal > Property > Statement > Container > Bag > Seq > Alt
114
CoFfTeA seminarie114 Model Statement Resource Property Literal Property Resource Nov. 24, 2003CoFfTeA @yahoo @kahosl peter Seminar DC:title DC:date Tut:tutor Tut:name Tut:email
115
CoFfTeA seminarie115 Structure of RDF data (Model) SESSION SESSION- GROUP ATTENDEE LOCATION DATE TEACHER- GROUP TIMESLOT value NAME SESSION_ID TIMESLOT_ID DTSTART DTEND LOCATION_ID NAME value NAME DAY WEEKNR DATE_ID SESSIONGROUP_ID STUDENTGROUP_ID (>=1) TEACHERGROUP_ID TEACHER_ID (>=1) value NUMBER_OF_PEOPLE value HAS_CAPACITY
116
CoFfTeA seminarie116 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
117
CoFfTeA seminarie117 http://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
118
CoFfTeA seminarie118 John Smith vcard.FN JohnSmith http://somewhere/JohnSmith vcard.N vcard.Givenvcard.Family // Some definitions String personURI = "http://somewhere/JohnSmith"; String givenName = "John"; String familyName = "Smith"; String fullName = givenName + " " + familyName; // Create an empty Model Model model = ModelFactory.createDefaultModel(); // Create the resource and add the properties cascading style Resource 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
119
CoFfTeA seminarie119 List statements // List the statements in the Model StmtIterator 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
120
CoFfTeA seminarie120 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 JohnSmith http://somewhere/JohnSmith vcard.N vcard.Givenvcard.Family
121
CoFfTeA seminarie121 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
122
CoFfTeA seminarie122 Navigating a Model / 1 // Read the RDF/XML file model.read(new InputStreamReader(in), ""); // Retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // Retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // Retrieve the given name property String fullName = vcard.getProperty(VCARD.FN).getString(); // Add two nick name properties to vcard vcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman"); Ex 6
123
CoFfTeA seminarie123 Navigating a Model / 2 // Read the RDF/XML file model.read(new InputStreamReader(in), ""); // Retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // Retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // Retrieve the given name property String fullName = vcard.getProperty(VCARD.FN).getString(); // Add two nick name properties to vcard vcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman"); Ex 6 John Smith John Smith http://somewhere/JohnSmith/ vcard:FN vcard:N vcard:Given vcard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vcard:FN vcard:N vcard: Given vcard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vcard:FN vcard:N vcard: Given vcard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vcard:FN vcard:N vcard: Given vcard: Family
124
CoFfTeA seminarie124 Navigating a Model / 3 // Read the RDF/XML file model.read(new InputStreamReader(in), ""); // Retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // Retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // Retrieve the given name property String fullName = vcard.getProperty(VCARD.FN).getString(); // Add two nick name properties to vcard vcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman"); Ex 6 John Smith vcard.FN JohnSmith http://somewhere/JohnSmith vcard.N vcard.Givenvcard.Family vcard
125
CoFfTeA seminarie125 Navigating a Model / 4 // Read the RDF/XML file model.read(new InputStreamReader(in), ""); // Retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // Retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // Retrieve the given name property String fullName = vcard.getProperty(VCARD.FN).getString(); // Add two nick name properties to vcard vcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman"); Ex 6 John Smith vcard.FN JohnSmith http://somewhere/JohnSmith vcard.N vcard.Givenvcard.Family name vcard
126
CoFfTeA seminarie126 Navigating a Model / 5 // Read the RDF/XML file model.read(new InputStreamReader(in), ""); // Retrieve the John Smith vcard resource from the model Resource vcard = model.getResource(johnSmithURI); // Retrieve the value of the N property Resource name = (Resource) vcard.getProperty(VCARD.N).getObject(); // Retrieve the given name property String fullName = vcard.getProperty(VCARD.FN).getString(); // Add two nick name properties to vcard vcard.addProperty(VCARD.NICKNAME,"Smithy").addProperty(VCARD.NICKNAME, "Adman"); Ex 6 John Smith vcard.FN JohnSmith http://somewhere/JohnSmith vcard.N vcard.Givenvcard.Family fullname vcard name
127
CoFfTeA seminarie127 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
128
CoFfTeA seminarie128 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
129
CoFfTeA seminarie129 RDQL query language examples John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family
130
CoFfTeA seminarie130 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?x WHERE (?x "John Smith")
131
CoFfTeA seminarie131 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?x WHERE (?x "John Smith") Result: x ============================= Result: x =============================
132
CoFfTeA seminarie132 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?x, ?fname WHERE (?x ?fname)
133
CoFfTeA seminarie133 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?x, ?fname WHERE (?x ?fname) Result: x | fname ================================================ | "John Smith" | "Becky Smith" | "Sarah Jones" | "Matt Jones" Result: x | fname ================================================ | "John Smith" | "Becky Smith" | "Sarah Jones" | "Matt Jones"
134
CoFfTeA seminarie134 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?givenName WHERE (?y "Smith") (?y ?givenName)
135
CoFfTeA seminarie135 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?givenName WHERE (?y "Smith") (?y ?givenName) Result: givenName ========= "John" "Rebecca" Result: givenName ========= "John" "Rebecca"
136
CoFfTeA seminarie136 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?resource ?givenName WHERE (?resource ?z), (?z ?givenName)
137
CoFfTeA seminarie137 John Smith John Smith http://somewhere/JohnSmith/ vCard:FN vCard:N vCard:Given vCard:Family Sarah Jones Sarah Jones http://somewhere/SarahJones/ vCard:FN vCard:N vCard: Given vCard: Family Matt Jones Matthew Jones http://somewhere/MattJones/ vCard:FN vCard:N vCard: Given vCard: Family Becky Smith Rebecca Smith http://somewhere/RebeccaSmith/ vCard:FN vCard:N vCard: Given vCard: Family SELECT ?resource ?givenName WHERE (?resource ?z), (?z ?givenName) Result: resource | givenName ============================================ | "John" | "Rebecca" | "Sarah" | "Matthew" Result: resource | givenName ============================================ | "John" | "Rebecca" | "Sarah" | "Matthew"
138
CoFfTeA seminarie138 RDQL query language examples Other features: USING Clause SELECT ?resource WHERE (?resource info:age ?age) AND ?age >= 24 USING info FOR http://somewhere/peopleInfo# Querying for Properties SELECT ?prop WHERE (, ?prop, "John Smith")
139
CoFfTeA seminarie139 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,, ?SESSION_ID), (?x,, ?COURSE), (?x,, ?NUMBER_OF_PEOPLE), (?x,, ?z), (?z,, ?TIMESLOT_ID), (?z,, ?DTSTART), (?z,, ?DTEND), (?x,, ?v), (?v,, ?LOCATION_ID), (?v,, ?LOCNAME), (?v,, ?has_capacity), (?x,, ?r), (?r,, ?DATE_ID), (?r,, ?Day), (?r,, ?WeekNr), (?r,, ?WKDY), (?x,, ?m), (?m,, ?n), (?n,, ?SessionGroup_ID), (?n,, ?StudentGroup_ID), (?m,, ?p), (?p,, ?TeacherGroup_ID), (?p,, ?Teacher_ID) USING hybrid FOR, schooltimetabling FOR SESSION SESSIONGROU P ATTENDE E LOCATION DATE TEACHERGROU P TIMESLOT value NAME SESSION_ID TIMESLOT_ID DTSTART DTEND LOCATION_ID NAME value NAME DAY WEEKNR DATE_ID SESSIONGROUP_ID STUDENTGROUP_ ID (>=1) TEACHERGROUP _ID TEACHER_ID (>=1) value NUMBER_OF_PEOPLE value HAS_CAPACITY
140
CoFfTeA seminarie140 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
141
CoFfTeA seminarie141 Using RDQL from JAVA JAVA code: String queryString = "SELECT ?x, ?fname "+"WHERE (?x,, ?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() ;
142
CoFfTeA seminarie142 References Practical RDF, Shelley Powers: http://safari.oreilly.com/?XmlId=0-596-00263-7 http://safari.oreilly.com/?XmlId=0-596-00263-7 Jena Tutorial: http://jena.sourceforge.net/tutorial/ http://jena.sourceforge.net/tutorial/
143
CoFfTeA seminarie143 Database to RDF Mapping Language and Processor D2R Map
144
CoFfTeA seminarie144 References D2R MAP - A Database to RDF Mapping Language, Chris Bizer ( http://www.wiwiss.fu- berlin.de/suhl/bizer/d2rmap/www2003-D2R-Map.pdf ) 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 ) http://www.wiwiss.fu- berlin.de/suhl/bizer/d2rmap/D2R_language%20specification.pdf
145
CoFfTeA seminarie145 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
146
CoFfTeA seminarie146 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
147
CoFfTeA seminarie147 Example
148
CoFfTeA seminarie148 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)
149
CoFfTeA seminarie149 ClassMap example SerialNRProduct_NameKeyword Q8GR2Dell Dimension V400256 MB RAM Q8GR2Dell Dimension V40019” monitor 256 MB RAM 19” monitor D2R Map Fragment RDF result Table: Products
150
CoFfTeA seminarie150 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 ObjectPropertyBridge: defines bridge between column of result set and object property of instances
151
CoFfTeA seminarie151 Elaborated example
152
CoFfTeA seminarie152 Elaborated example
153
CoFfTeA seminarie153 Elaborated example
154
CoFfTeA seminarie154 Elaborated example
155
CoFfTeA seminarie155 Elaborated example
156
CoFfTeA seminarie156 The OpenTS framework
157
CoFfTeA seminarie157 OpenTS references OpenTS: http://www- 124.ibm.com/developerworks/opensource/coi n/OpenTS/index.htmlhttp://www- 124.ibm.com/developerworks/opensource/coi n/OpenTS/index.html
158
CoFfTeA seminarie158 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, …)
159
CoFfTeA seminarie159 Tabu Search Given 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
160
CoFfTeA seminarie160 Tabu Search: tabu list Memory technique that prevents cycling in local minima
161
CoFfTeA seminarie161 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
162
CoFfTeA seminarie162 Tabu Search Pros Cons CONS Tabu search does not guarantee optimality Tabu search assumes fast performance evaluation
163
CoFfTeA seminarie163 An iteration in OpenTS New current solution New current solution MoveManger generates moves MoveManger generates moves Objective function Evaluates moves Objective function Evaluates moves Best non-tabu move is picked (incl. aspiration) Best non-tabu move is picked (incl. aspiration) Move operates on the current solution Move operates on the current solution Initial solution Initial solution
164
CoFfTeA seminarie164 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 strategies Tabu 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
165
CoFfTeA seminarie165 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)
166
CoFfTeA seminarie166 OpenTS Framework MySolution MyTabuList MyMoveManager_2 MyObjectiveFunction MyMoveManager_1MyMoveManager_3 MyMove_1MyMove_3MyMove_2
167
CoFfTeA seminarie167 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move B operateOn() setTabu() TabuList isTabu() Tabu Value
168
CoFfTeA seminarie168 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move B operateOn() 1.Starts with the initial solution 1 setTabu() TabuList isTabu() Tabu Value
169
CoFfTeA seminarie169 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move B operateOn() 1.Starts with the initial solution 2.The Movemanager generates all possible moves, starting from the given solution 1 2 setTabu() TabuList isTabu() Tabu Value
170
CoFfTeA seminarie170 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move 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 Value setTabu() 1 2 3 TabuList isTabu()
171
CoFfTeA seminarie171 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move B operateOn() 4.OpenTS picks the best move, consulting the tabulist 4 1 2 3 setTabu() TabuList isTabu() Tabu Value
172
CoFfTeA seminarie172 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move 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 isTabu() Tabu Value 5
173
CoFfTeA seminarie173 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move 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 isTabu() Tabu Value 5
174
CoFfTeA seminarie174 An iteration in OpenTS Initial solution Solution Move A Move B Move C Move D getAllMoves()getBestMove() Move 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 If current solution better than the best one setBestMove 4 6 1 2 3 setTabu() TabuList isTabu() Tabu Value 5
175
CoFfTeA seminarie175 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
176
CoFfTeA seminarie176 OpenTS and Tabu Search Objects can respond to events Solution TabuList MoveManager ObjectiveFunction OpenTS TabuSearch OpenTS TabuSearch TabuSearchListener: improvingMoveMade(TabuSearchEvent evt) newBestSolutionFound(TabuSearchEvent evt) newCurrentSolutionFound(TabuSearchEvent evt) noChangeInValueMoveMade(TabuSearchEvent evt) tabuSearchStarted(TabuSearchEvent evt) tabuSearchStopped(TabuSearchEvent evt) unimprovingMoveMade(TabuSearchEvent evt) implements TabuSearchEvent
177
CoFfTeA seminarie177 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
178
CoFfTeA seminarie178 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, … … Initialising
179
CoFfTeA seminarie179 Read the constraints file (XML) and determine which concepts are necessary for the evaluation <!DOCTYPE constraints [ ]> LESS_OR_EQUAL_THAN 1 …
180
CoFfTeA seminarie180 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, … … Initialising
181
CoFfTeA seminarie181 Build the solution space using the mapped data in RDF format 4 Digitale technieken 13 2 3 4 5 … Date Location Timeslot Assign Sessions
182
CoFfTeA seminarie182 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 527 76 …
183
CoFfTeA seminarie183 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, … … Initialising
184
CoFfTeA seminarie184 Read the constraints and put them in memory <!DOCTYPE constraints [ ]> LESS_OR_EQUAL_THAN 1 LESS_OR_EQUAL_THAN 1 &weekend; LESS_THAN 1 1 /> 1 /> LESS_OR_EQUAL_THAN 1 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)
185
CoFfTeA seminarie185 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, … … Initialising
186
CoFfTeA seminarie186 Consider the actual schedule as the initial solution Calculating 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 Stopcriterion satisfied Stop Yes No Load new neighbourhood Next iteration
187
CoFfTeA seminarie187 Overview of neighbourhoods 1a1a 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 Scheduling Object
188
CoFfTeA seminarie188 The Movemanager determines which moves are possible in a given situation Date Timeslot Location Date Timeslot Location Date Timeslot Location = Move
189
CoFfTeA seminarie189 Pauze Koffie in de instuif
190
CoFfTeA seminarie190 Demonstratie
191
CoFfTeA seminarie191 Demo Demo of the mapping component Demo of the constraint component Demo of the timetabling framework
192
CoFfTeA seminarie192 Discussie
193
CoFfTeA seminarie193 Einde Drink in de instuif
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.