Maandag 24 november 2003 - PowerPoint PPT Presentation

1 / 193
About This Presentation
Title:

Maandag 24 november 2003

Description:

the opportunities of component based software development. How software can function with ... Tree of Porphyry. CoFfTeA seminarie. 26. What is an ontology? ... – PowerPoint PPT presentation

Number of Views:140
Avg rating:3.0/5.0
Slides: 194
Provided by: peterde4
Category:

less

Transcript and Presenter's Notes

Title: Maandag 24 november 2003


1
CoFfTeA seminarie
  • Maandag 24 november 2003

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

3
Agenda (2)
  • Koffie
  • Demonstratie
  • Discussie
  • Drink

4
Inleiding
  • CoFfTeA

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

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?

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

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?

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?

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.

11
Achtergrond
  • Raamwerk, ontologie en webgebaseerde
    datarepresentatietalen

12
Local search component
OpenTS
evaluation component
constraint component
Query model in RDQL and Jena API
Constraints in XML, generated by the GSCG Jena,
JDom, OilEd source, ..
XML D2R mapping file
(semi)-automatic generation of the D2R mapping
file
JWNL, WordNet, ontology for timetabling, OilEd
source, Jena, JDom,
Semantic mapping component
school database
13
Raamwerk
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 ()

15
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
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
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
Problem Domain, Application and Framework
  • Application

Framework
Problem Domain
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)

20
Ontologie
21
Pieter Brueghel, de oude de toren van Babel
(1563)
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

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

24
Aristotle's categories
25
Tree of Porphyry
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 someones head
  • Explicit this is called an ontology

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.

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

29
Formality
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

31
Communication between people
32
Purpose (Inter-operability)
L1
L2
L1
L2
T2
T1
interlingua
T3
T4
L4
L3
L4
L3
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

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 system
  • and provides a declarative specification of a
    software system

35
Purpose (4)
COMMUNICATION Between people organisations
INTER-OPERABILITY between systems
Reusable components
Reliability Specification SYSTEMS
ENGINEERING
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
37
Subject matter
  • Most common categories
  • Domain ontology (medicine, geology, finance,)
  • Task, method or problem solving ontology
  • Representation or meta-ontology

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.

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 beersspecific
    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
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
Webgebaseerde datarepresentatietalen
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

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

44
Architecture of the SW
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

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

47
XML an example
  • lt?xml version"1.0"?gt
  • ltarticlegt
  • lttitlegtUsing web standards for
    timetablinglt/titlegt
  • ltauthorgtSep Ducamaerckelt/authorgt
  • ltauthorgtPer Tedesemlt/authorgt
  • ltauthorgtVenghed Bangerlt/authorgt
  • ltaffiliationgtKaHo Sint-Lieven,Gentlt/affiliationgt
  • lt/articlegt

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,

49
Example of an XML Schema
  • lt?xml version"1.0""?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxselement name"article"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement name"title"
    type"xsstring"/gt
  • ltxselement name"author"
    type"xsstring" maxOccurs"unbounded"/
    gt
  • ltxselement name"affiliation"
    type"xsstring"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

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

51
Example
Object or the value of the property
Resource identified by an URI
Property characterises the resource
http//www.kahosl.be/articleX.xml
Sep Ducamaercke
creator
  • ArticleX has creator Sep Ducamaercke
  • RDF is just a model for representing metadata
  • Representation labeled graphs or translate to
    XML

ltrdfRDF xmlnsrdfhttp//www.w3.org/1999/02/22-r
df-syntax-ns xmlnshttp//sep.ducamaer
cke.net/rdfexamplesgt ltrdfDescription
abouthttp//www.kahosl.be/articleX.xmlgt
ltcreatorgtSep Ducamaerckelt/creatorgt
ltrdfDescriptiongt ltrdfRDFgt
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

53
Fourth layer Ontology language
  • Need of a language to express ontologies in
  • Newest languages use RDFS as a starting point
  • DAMLOIL 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,

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 gt 100 products ? person ?
    supersalesman club

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

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

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-tutorial/

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

59
Gebruikte Tools
60
Developing ontologies with OilEd
  • Crash course in using OilEd
  • http//oiled.man.cs.uk

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/p
    ublications/ontology_development/ontology101-noy-m
    cguinness.html)
  • Warning Above paper uses Protégé instead of OilEd

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)

63
OilEd short
  • Creating classes (super and subclasses
    (taxonomy))
  • Creating properties (super, inverse and
    subproperties)
  • subClassOf and sameClassAs
  • Reasoner
  • Axioms (disjoint subclass)
  • Creating restrictions

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

65
Create classes
  • Make the superclass animal
  • Add the subclasses cat, sheep, cow, giraffe
  • Add mad cow as subclass of cow

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)

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)

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

69
Individuals
  • Add class heavenly body
  • Select tab Individuals
  • Add Individual sun (is an instance of heavenly
    body)
  • Add moon and mars

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

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

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

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?

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)

75
Restriction types
  • Restriction types ? logical quantifiers
  • Has-class ? ?
  • To-class ? ?

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

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

78
Developed ontologies
  • Developed 2 ontologies (in OilEd NotePad)
  • School timetabling ontology (loosely based on
    OZONE)
  • Ontology for events (loosely based on iCalendar)

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/rf
    c2445.txt)

80
WordNet JWNL
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

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

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,
    args0)            IndexWord W2
    Dictionary.getInstance().getIndexWord
    (POS.NOUN, args1)               
    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
  • int commonParentIndex
  • ((AsymmetricRelationship)l
    ist.get(0)).getCommonParentIndex()           
    PointerTargetNode ptn
    (PointerTargetNode) ptnl.get(commonParentIndex) 
               Synset synset ptn.getSynset()      
          for(int i0 iltsynset.getWordsSize()
    i)                           
    System.out.print(synset.getWord(i).getLemma() "
    ")                        System.out.println()
                    catch(Exception e)       
                e.printStackTrace()           
    System.exit(-1)            

85
Output
  • C\ gt java Relation ear noseRelationship between
    ear and nosesense_organ sensory_receptor
    receptor
  • C\ gt java Relation nurse teacherRelationship
    between nurse and teacherprofessional
    professional_person

86
Manipulating XML documents
  • JDOM
  • http//jdom.org

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

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

89
JDOM references
  • Java XML, Brett McLaughlin, OReilly (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/x
    mljava/
  • Simplify XML programming with JDOM, Wes Biggs and
    Harry Evans, IBM DeveloperWorks
    (http//www-106.ibm.com/developerworks/java/librar
    y/j-jdom/)

90
JDOM was used for
  • Creating the constraints in XML

91
Document class
  • Documents are in the package org.jdom.Document
  • From scratchDocument doc new Document(new
    Element(root))

92
Create a document element
  • Create simple document in JDOMDocument doc
    new Document()Element e new
    Element(root)e.setText(This is the
    root)doc.addContent(e)
  • Or more compactDocument doc new Document (new
    Element(root).setText(This is the root))

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)

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

95
Attribute class
  • Elements may have attributesltaddress
    streetGebr.Desmetstraat 1 cityGent
    zip9000gtlt/addressgt
  • Get attributeString street address.getAttribut
    eValue(street)int zip address.getAttribute(
    zip).getIntValue()
  • Set attributeaddress.setAttribute(country,
    Belgium)
  • Remove attributeaddress.removeAttribute(country
    )

96
Element content
  • Element may have text contentltcitygtGentlt/citygt
  • To get the contentString city
    element.getText()This returns \n Gent\n
  • String city element.getTextTrim()returns Gent
  • To change the text contentelement.setText(A
    new description)

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.setNewline
    s(true)outp.output(doc, System.out)

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 lt 5
    i) Element fibonacci new
    Element("fibonacci") fibonacci.setAttribute("
    index",String.valueOf(i)) fibonacci.setText(l
    ow.toString()) root.addContent(fibonacci)

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.setNew
    lines(true) serializer.output(doc,
    System.out)
  • catch (IOException e)
  • System.err.println(e)
  • Demo

100
DTD
  • Suppose the DTD of the previous XML file looks
    likelt!ELEMENT Fibonacci_Numbers
    (fibonacci)gtlt!ELEMENT fibonacci
    (PCDATA)gtlt!ATTLIST fibonacci index CDATA
    IMPLIEDgt
  • DocType class represents DTDsDocType type new
    DocType("Fibonacci_Numbers", "fibonacci.dtd")
  • Add to the previous JDOM program the following
    linesDocType type new DocType("Fibonacci_Numbe
    rs", "fibonacci.dtd") Document doc new
    Document(root, type)

101
Navigating JDOM Trees
  • Everything is an object cast to right type
  • Done by instanceof
  • getChildren() returns only elements (everything
    else is missed) -gt returns a java.util.List
  • To get everything use getContent() -gt returns a
    java.util.List
  • In this case not everything is Element

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(args0)
    listNodes(doc, 0)

103
Big example
  • // indicates a well-formedness error
  • catch (JDOMException e)
  • System.out.println(args0 " 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(c
    hild, depth1)

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(c
    hild, depth1) else if (o instanceof
    Comment) System.out.println("Comment")
    else if (o instanceof CDATA) System.out.printl
    n("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("Entit
    y reference")

105
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 lt n i) System.out.print('
    ')
  • Demo

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

107
Introduction to the JENA RDF API


108
Jena was used for
  • Querying the mapped RDF data file

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

110
Semantic weblayers
RDF, RDFS, DAMLOIL, OWL, Jena (HP)
XML, XML Schema,DOM, JDOM, SAX,
111
JENA
  • JENA
  • Full-featured Java API for RDF
  • Open source API
  • Accessible at Source Forge (http//jena.sourceforg
    e.net) also avaliable at http//www.hpl.hp.com/sem
    web/jena.htm

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

113
ltlt interface gtgt RDFNode
ltlt interface gtgt Resource
ltlt interface gtgt Literal
ltlt interface gtgt Property
ltlt interface gtgt Statement
ltlt interface gtgt Container
ltlt interface gtgt Bag
ltlt interface gtgt Seq
ltlt interface gtgt Alt
114
(No Transcript)
115
Structure of RDF data (Model)
value
NAME
SESSION
SESSION_ID
value
value
value
NUMBER_OF_PEOPLE
TIMESLOT_ID
value
DTSTART
DTEND
value
TIMESLOT
value
LOCATION_ID
value
NAME
LOCATION
value
HAS_CAPACITY
value
DATE_ID
value
DAY
DATE
WEEKNR
value
value
value
NAME
SESSIONGROUP_ID
SESSION-GROUP
value
STUDENTGROUP_ID(gt1)
ATTENDEE
value
TEACHERGROUP_ID
TEACHER-GROUP
TEACHER_ID(gt1)
value
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

117
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.addProper
ty(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)

vcard.FN
http//somewhere/JohnSmith
John Smith
Ex 1 Building a simple RDF Graph with Jena
118
// 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(pe
rsonURI)
.addProperty(VCARD.FN, fullName)
.addProperty(VCARD.N, model.createResourc
e()
.addProperty(VCARD.Given, givenName)
.addProperty(VCARD.Family,
familyName) )
http//somewhere/JohnSmith
vcard.FN
vcard.N
John Smith
vcard.Given
vcard.Family
John
Smith
Ex 2 Blank node example
119
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(" .")
Object can be an instance of a resource or a
literal
Ex 3 List the statements in the graph
120
List statements / Result http//somewhere/JohnSm
ith http//www.w3.org/2001/vcard-rdf/3.0N
anon14df86ecc3dee17b-7fff . anon14df86ecc3de
e17b-7fff http//www.w3.org/2001/vcard-rdf/3.0Fa
mily "Smith" . anon14df86ecc3dee17b-7fff
http//www.w3.org/2001/vcard-rdf/3.0Given "John"
. http//somewhere/JohnSmith http//www.w3.org/20
01/vcard-rdf/3.0FN "John Smith" .
http//somewhere/JohnSmith
vcard.FN
vcard.N
John Smith
vcard.Given
vcard.Family
John
Smith
Ex 3
121
Reading RDF InputStream in Example_5_new.class.
getClassLoader()
.getResourceAsStream(inputFileName) model.read(ne
w 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
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").a
ddProperty(VCARD.NICKNAME, "Adman")
Ex 6
123
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").a
ddProperty(VCARD.NICKNAME, "Adman")


Ex 6
124
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").a
ddProperty(VCARD.NICKNAME, "Adman")
vcard
Ex 6
125
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").a
ddProperty(VCARD.NICKNAME, "Adman")
vcard
name
Ex 6
126
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").a
ddProperty(VCARD.NICKNAME, "Adman")
vcard
fullname
name
Ex 6
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

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

129
RDQL query language examples
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
130
SELECT ?x WHERE (?x lthttp//www.w3.org/2001/vcard
-rdf/3.0FNgt "John Smith")
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
131
SELECT ?x WHERE (?x lthttp//www.w3.org/2001/vcard
-rdf/3.0FNgt "John Smith")
Result x
lthttp//somewhere/J
ohnSmith/gt
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
132
SELECT ?x, ?fname WHERE (?x lthttp//www.w3.org/20
01/vcard-rdf/3.0FNgt ?fname)
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
133
SELECT ?x, ?fname WHERE (?x lthttp//www.w3.org/20
01/vcard-rdf/3.0FNgt ?fname)
Result x fname

lthttp//somewhere/JohnSmith/gt "John
Smith" lthttp//somewhere/RebeccaSmith/gt "Becky
Smith" lthttp//somewhere/SarahJones/gt "Sarah
Jones" lthttp//somewhere/MattJones/gt "Matt
Jones"
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
134
SELECT ?givenName WHERE (?y lthttp//www.w3.org/20
01/vcard-rdf/3.0Familygt "Smith") (?y
lthttp//www.w3.org/2001/vcard-rdf/3.0Givengt
?givenName)
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
135
SELECT ?givenName WHERE (?y lthttp//www.w3.org/20
01/vcard-rdf/3.0Familygt "Smith") (?y
lthttp//www.w3.org/2001/vcard-rdf/3.0Givengt
?givenName)
Result givenName "John" "Rebecca"
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
136
SELECT ?resource ?givenName WHERE (?resource
lthttp//www.w3.org/2001/vcard-rdf/3.0Ngt ?z),
(?z lthttp//www.w3.org/2001/vcard-rdf/3.0Givengt
?givenName)
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
137
SELECT ?resource ?givenName WHERE (?resource
lthttp//www.w3.org/2001/vcard-rdf/3.0Ngt ?z),
(?z lthttp//www.w3.org/2001/vcard-rdf/3.0Givengt
?givenName)
Result resource
givenName
lthttp//somewhere/JohnSmith/gt "John"
lthttp//somewhere/RebeccaSmith/gt
"Rebecca" lthttp//somewhere/SarahJones/gt
"Sarah" lthttp//somewhere/MattJones/gt
"Matthew"
vCardFN
John Smith
http//somewhere/JohnSmith/
vCardGiven
John
vCardN
vCardFamily
Smith
vCardFN
Sarah Jones
http//somewhere/SarahJones/
vCard Given
Sarah
vCardN
vCard Family
Jones
vCardFN
Matt Jones
http//somewhere/MattJones/
vCard Given
Matthew
vCardN
vCard Family
Jones
vCardFN
Becky Smith
http//somewhere/RebeccaSmith/
vCard Given
Rebecca
vCardN
vCard Family
Smith
138
RDQL query language examples
  • Other features
  • USING Clause
  • SELECT ?resource WHERE (?resource infoage
    ?age) AND ?age gt 24USING info FOR
    http//somewhere/peopleInfo
  • Querying for PropertiesSELECT ?propWHERE
    (lthttp//somewhere/JohnSmith/gt , ?prop, "John
    Smith")

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, lthybridSESSION_IDgt, ?SESSION_ID),
  • (?x, lthybridNAMEgt, ?COURSE),
  • (?x, lthybridNUMBER_OF_PEOPLEgt,
    ?NUMBER_OF_PEOPLE),
  • (?x, lthybridtimeslotgt, ?z),
  • (?z, lthybridTIMESLOT_IDgt, ?TIMESLOT_ID),
  • (?z, lthybridDTSTARTgt, ?DTSTART),
  • (?z, lthybridDTENDgt, ?DTEND),
  • (?x, lthybridlocationgt, ?v),
  • (?v, lthybridLOCATION_IDgt, ?LOCATION_ID),
  • (?v, lthybridNAMEgt, ?LOCNAME),
  • (?v, lthybridHAS_CAPACITYgt, ?has_capacity),
  • (?x, lthybriddategt, ?r),
  • (?r, lthybridDATE_IDgt, ?DATE_ID),
  • (?r, lthybridDAYgt, ?Day),
  • (?r, lthybridWEEKNRgt, ?WeekNr),
  • (?r, lthybridNAMEgt, ?WKDY),
  • (?x, lthybridattendeegt, ?m),
  • (?m, lthybridsessiongroupgt, ?n),

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

141
Using RDQL from JAVA
  • JAVA code
  • String queryString "SELECT ?x, ?fname ""WHERE
    (?x, lthttp//www.w3.org/2001/vcard-rdf/3.0FNgt,
    ?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
References
  • Practical RDF, Shelley Powers http//safari.oreil
    ly.com/?XmlId0-596-00263-7
  • Jena Tutorial http//jena.sourceforge.net/tutoria
    l/

143
Database to RDF Mapping Language and Processor
  • D2R Map

144
References
  • D2R MAP - A Database to RDF Mapping Language,
    Chris Bizer (http//www.wiwiss.fu-berlin.de/suhl/b
    izer/d2rmap/www2003-D2R-Map.pdf)
  • D2R language specification, Chris Bizer
    (http//www.wiwiss.fu-berlin.de/suhl/bizer/d2rmap/
    D2R_language20specification.pdf)

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

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

147
Example
  • ltd2rClassMap d2rtype"hybridSESSION"
    d2rsql"SELECT FROM ((Session INNER JOIN
    TimeSlot ON Session.TimeSlotIDTimeSlot.TimeSlotI
    D) INNER JOIN Room ON Session.RoomIDRoom.RoomID)
    INNER JOIN TimeDate ON TimeDate.TimeDateIDSessi
    on.TimeDateID" d2rgroupBy"Session.SessionID"gt
  • ltd2rDatatypePropertyBridge d2rproperty"hybrid
    SESSION_ID" d2rcolumn"Session.SessionID"/gt
  • ltd2rDatatypePropertyBridge d2rproperty"hybrid
    NUMBER_OF_PEOPLE_ID" d2rcolumn"Session.SGroupID
    "/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridti
    meslot d2rreferredClass"hybridTIMESLOT
    d2rreferredGroupBy"TimeSlot.TimeSlotID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridlo
    cation d2rreferredClass"hybridLOCATION
    d2rreferredGroupBy"Room.RoomID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridda
    te d2rreferredClass"hybridDATE
    d2rreferredGroupBy"TimeDate.TimeDateID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridat
    tendee d2rreferredClass"hybridATTENDEE
    d2rreferredGroupBy"Session.SessionID"/gt
  • lt/d2rClassMapgt

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)

149
ClassMap example
Table Products
  • D2R Map Fragment
  • ltd2rClassMap d2rtypegoodsProduct
    d2rsqlSELECT from Products
    d2rgroupBygoods.SNr d2ruriPatternhttp//ex
    ample.org/goods_at__at_Products.SerialNR_at__at_gtltd2rDatat
    ypePropertyBridge d2rpropertygoodsname
    d2rcolumnProducts.Product_Name/gtltd2rDatatype
    PropertyBridge d2rpropertygoodshasKeyword
    d2rcolumnProducts.Keyword/gt
  • lt/d2rClassMapgt
  • RDF result

ltrdfRDFgtltgoodsProduct rdfabouthttp//example
.org/goodsQ8GR2 goodsnameDell Dimension
V400gt ltgoodshasKeywordgt256 MB
RAMlt/goodshasKeywordgt ltgoodshasKeywordgt19
monitorlt/goodshasKeywordgt lt/rdfRDFgt
150
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
  • ltd2rDatatypePropertyBridge d2rproperty"hybridS
    ESSION_ID" d2rcolumn"Session.SessionID"/gt
  • ObjectPropertyBridgedefines bridge between
    column of result set and object property of
    instances
  • ltd2rObjectPropertyBridge d2rproperty"hybridloc
    ation d2rreferredClass"hybridLOCATION
    d2rreferredGroupBy"Room.RoomID"/gt

Reference to a d2rClassMap
151
Elaborated example
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • ltd2rMap xmlnsd2r"http//www.wiwiss.fu-berlin.de
    /suhl/bizer/D2RMap/0.1" d2rversionInfo"Id
    AtlasMap.d2r,xml, v 0.1 2003/01/27 Peter Exp "gt
  • ltd2rProcessorMessage d2routputFormat"RDF/XML-A
    BBREV"/gt
  • ltd2rDBConnection d2rjdbcDriver"com.microsoft.j
    dbc.sqlserver.SQLServerDriver" d2rjdbcDSN"jdbcm
    icrosoftsqlserver//HAWKING1433UserAtlasUser2
    PasswordgmatlasdbAtlas" d2rlogin"AtlasUser2"
    d2rpassword"gmatlas"/gt
  • ltd2rNamespace d2rprefix"hybrid"
    d2rnamespace"http//project.kahosl.be/cofftea/20
    03/01/hybrid.daml"/gt
  • ltd2rNamespace d2rprefix"daml"
    d2rnamespace"http//www.daml.org/2001/03/damloi
    l"/gt
  • ltd2rNamespace d2rprefix"rdf"
    d2rnamespace"http//www.w3.org/1999/02/22-rdf-sy
    ntax-ns"/gt
  • ltd2rNamespace d2rprefix"schooltimetabling"
    d2rnamespace"http//project.kahosl.be/cofftea/20
    03/01/schooltimetabling.daml"/gt

152
Elaborated example
  • ltd2rClassMap d2rtype"hybridSESSION"
    d2rsql"SELECT FROM ((Session INNER JOIN
    TimeSlot ON Session.TimeSlotIDTimeSlot.TimeSlotI
    D) INNER JOIN Room ON Session.RoomIDRoom.RoomID)
    INNER JOIN TimeDate ON TimeDate.TimeDateIDSession
    .TimeDateID" d2rgroupBy"Session.SessionID"gt
  • ltd2rDatatypePropertyBridge d2rproperty"hybri
    dSESSION_ID" d2rcolumn "Session.SessionID"/gt
  • ltd2rDatatypePropertyBridge d2rproperty"hybri
    dNUMBER_OF_PEOPLE_ID" d2rcolumn "Session.SGrou
    pID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridt
    imeslot" d2rreferredClass"hybridTIMESLOT"
    d2rreferredGroupBy "TimeSlot.TimeSlotID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridl
    ocation" d2rreferredClass"hybridLOCATION"
    d2rreferredGroupBy "Room.RoomID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybridd
    ate" d2rreferredClass"hybridDATE"
    d2rreferredGroupBy "TimeDate.TimeDateID"/gt
  • ltd2rObjectPropertyBridge d2rproperty"hybrida
    ttendee" d2rreferredClass"hybridATTENDEE"
    d2rreferredGroupBy "Session.SessionID"/gt
  • lt/d2rClassMapgt

153
Elaborated example
  • ltd2rClassMap d2rtype"hybridDATE"
    d2rsql"SELECT FROM TimeDate"
    d2rgroupBy"TimeDate.TimeDateID"gt
  • ltd2rDatatypePropertyBridge d2rproperty"hybrid
    DATE_ID" d2rcolumn"Time
Write a Comment
User Comments (0)
About PowerShow.com