Download presentation
Presentation is loading. Please wait.
Published byDavid Elliott Modified over 9 years ago
1
Tools & Frameworks for the Semantic Web Semantic Web - Fall 2005 Computer Engineering Department Sharif University of Technology
2
Outline Jena A Semantic Web framework Sesame An architecture for storing and querying RDF data. Protégé An environment for creating and editing ontologies and knowledge bases.
3
Jena
4
Introduction Jena is a Java framework for building Semantic Web applications. Jena is open source software developed in HP Labs. 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 support
5
Jena Versions Two versions: Jena 1 Expressive support for RDF Limited reasoning facilities (RDQL) Jena 2 Ontology API included Support for OWL included
6
RDF Model Resource: Anything that can be described with an RDF expression. Property: Trait, attribute or relation used to describe a resource. Literal: Simple data type (String, Integer, etc). Statement: Resource, united with the property and its associated value. An RDF Model is a set of statements.
7
RDF API of Jena Allows creating and manipulating RDF Models from Java applications. Provides Java classes to represent: Models. Resources. Properties. Literals. Statements.
8
Example: vcards
9
Create an RDF Model String personURI = "http://somewhere/JohnSmith"; String givenName = "John"; String familyName = "Smith"; String fullName = givenName + " " + familyName; // create an empty model Model model = ModelFactory.createDefaultModel(); Resource johnSmith = model.createResource(personURI); johnSmith.addProperty(VCARD.FN, fullName); johnSmith.addProperty(VCARD.N, model.createResource().addProperty(VCARD.Given, givenName).addProperty(VCARD.Family, familyName));
10
Writing and Reading the Model To serialize the model in XML: model.write(System.out); To load a model in the memory: Model model = ModelFactory.createDefaultModel(); model.read(“file:c:/example.owl”);
11
Navigating the Model Getting information via the URI of the resource: // retrieve the resource John Smith String johnSmithURI = "http://somewhere/JohnSmith"; Resource jSmith = model.getResource(johnSmithURI); // retrieve the value of the property N Resource name = (Resource) jSmith.getProperty(VCARD.N).getObject(); // retrieve the value of the property FN String fullName = (String) jSmith.getProperty(VCARD.FN).getObject();
12
Referring to a Model Searching information in a model: // retrieve all the resources of the type vcard // (assuming that all such resources have a property FN) ResIterator it = model.listSubjectsWithProperty(VCARD.FN); while (it.hasNext()) { Resource r = it.nextResource(); System.out.println(r); } More advanced querying: Use of construction listStatements(Selector s). Use of RDQL.
13
Operations on Models A model is a set of statements. Support of the following operations: Union. Intersection. Difference. // reading the RDF models model1.read(new InputStreamReader(in1), ""); model2.read(new InputStreamReader(in2), ""); // unifying RDF models Model model = model1.union(model2);
14
Ontology API of Jena Supports RDF Schema, DAML, DAML+OIL and OWL. Language independent.
15
Example: Camera Ontology
16
Creation of an Ontology Model Use of method createOntologyModel(). Possible to specify: Used language. Associated reasoning. String fileName = "c:/ejemplo.owl"; String baseURI = "file:///" + fileName; OntModel model = ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG); model.read(new FileReader(schemaFileName), baseURI);
17
Classes Classes are basic construction blocks. Represented as OntClass. Example: Obtain subclasses of class Camera. OntClass camera = model.getOntClass(camNS + "Camera"); for (Iterator i = camera.listSubClasses(); i.hasNext();) { OntClass c = (OntClass) i.next(); System.out.println(c.getLocalName()); }
18
Properties Represented via OntProperty. OntModel m = ModelFactory.createOntologyModel(); OntClass Camera = m.createClass(camNS + "Camera"); OntClass Body = m.createClass(camNS + "Body"); ObjectProperty part = m.createObjectProperty(camNS + "part"); ObjectProperty body = m.createObjectProperty(camNS + "body"); body.addSuperProperty(part); body.addDomain(Camera); body.addRange(Body);
19
Complex Classes It is possible to define classes by means of operations for union, intersection, difference. Example:
20
// create instance throughTheLens OntClass Window = m.createClass(camNS + "Window"); Individual throughTheLens = m.createIndividual(camNS + "ThroughTheLens", Window); // create property viewfinder ObjectProperty viewfinder = m.createObjectProperty(camNS + "viewfinder"); // create restriction hasValue HasValueRestriction viewThroughLens = m.createHasValueRestriction(null, viewfinder, throughTheLens); // create class Camera OntClass Camera = m.createClass(camNS + "Camera"); // create intersection for defining class SLR IntersectionClass SLR = m.createIntersectionClass(camNS + "SLR", m.createList(new RDFNode[] {viewThroughLens, Camera}));
21
Schema vs Instance Data Schema Possible to define: Classes Properties (DataTypeProperty, ObjectProperty) Restrictions Types of Data Cardinality Instance Data Defining instances (individuals) of the Schema elements.
22
Kodak
23
Managing Instance Data URI = http://test/camera/#Camera OntClass c = model.getOntClass(URI +#Camera") OntProperty p = model.getOntProperty(URI +#name") Individual ind = model.getIndividual(URI +#camera1") if (ind.hasProperty(p)) Statement st = ind.getProperty(p); Object l = (Object)st.getObject();
24
Managing Instance Data Other operations: model.listIndividuals() Returns all instances of the model individual.hasProperty(Property p,Object o) Returns True if there is an individual having property p with value o ontClass.listInstances(); Returns all instances of the class
25
Jena Inference Support Inference Deduce additional information The task of inferencing is carried out by reasoners Jena comprises a set of basic reasoners OWL Reasoner DAML Reasoner RDF Rule Reasoner Generic Rule Reasoner There is a way to include new reasoners For example: (?A rdfs:subClassOf ?B) (?B rdfs:subClassOf ?C) (?A rdfs:subClassOf ?C)
26
Jena Inference Support To reason, an Inference Model should be created Example: Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); reasoner = reasoner.bindSchema(schema); InfModel modelInf = ModelFactory.createInfModel(reasoner,data);
27
Ontology Validation in Jena Model schema = ModelLoader.loadModel("file:c:/Schema.owl"); Model data = ModelLoader.loadModel("file:c:/example.owl"); Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); reasoner = reasoner.bindSchema(schema); InfModel modelInf = ModelFactory.createInfModel(reasoner, data); ValidityReport vrp1 = modelInf.validate(); if (vrp1.isValid()){ System.out.println(“Valid OWL"); }else { System.out.println(“Not valid OWL"); for (Iterator i = vrp1.getReports(); i.hasNext();){ System.out.println(" - " + i.next()); }
28
KODAK Error (range check): Incorrectly typed literal due to range (prop, value) Culprit = http://www.xfront.com/owl/ontologies/camera/#camera1 Implicated node: http://www.xfront.com/owl/ontologies/camera/#name Implicated node: 'KODAK‘
29
1 KODAK OLIMPUS Error (too many values): Too many values on max-N property (prop, class) Culprit = http://www.xfront.com/owl/ontologies/camera/#camera1 Implicated node: http://www.xfront.com/owl/ontologies/camera/#name Implicated node: http://www.xfront.com/owl/ontologies/camera/#Camera
30
RDQL q1 contains a query: SELECT ?x WHERE (?x "John Smith") For executing q1 with a model m1.rdf: java jena.rdfquery --data m1.rdf --query q1 The outcome is: x =============================
31
Using RDQL from Java Code It is possible to run RDQL queries from the Java application. The following classes are to be used for this: Query QueryExecution QueryEngine QueryResults ResultBinding
32
RDQL Example SELECT ?x, ?fname WHERE (?x ?fname) Query query = new Query("SELECT...") ; query.setSource(model); QueryExecution qe = new QueryEngine(query) ; QueryResults results = qe.exec(); for (Iterator iter = results; iter.hasNext();) { ResultBinding res = (ResultBinding) iter.next(); Resource x = (Resource) res.get("x"); Literal fname = (Literal) res.get("fname"); System.out.println("x: " + x + " fname: " + fname); }
33
Persistent Models Jena permits to create persistent models: such as with relational databases. Jena 2 supports: MySQL Oracle PostgreSQL To create a persistent model: ModelFactory.createModelRDBMaker(conn).createModel()
34
Example // Create a connection to DB DBConnection c = new DBConnection(DB_URL, DB_USER, DB_PASS, DB_TYPE); // Create a ModelMaker for persistent models ModelMaker maker = ModelFactory.createModelRDBMaker(c); // Create a new model Model model = maker.createModel("modelo_1"); // Start transaction model.begin(); // Read a model from an XML archive model.read(in, null); // Commit a transaction model.commit();
35
Sesame When they were out of sight Ali Baba came down, and, going up to the rock, said, "Open, Sesame.“ --Tales of 1001 Nights
36
Querying Levels RDF documents can be considered at three different levels of abstraction: 1. At the syntactic level they are XML documents. 2. At the structure level they consist of a set of triples. 3. At the semantic level they constitute one or more graphs with partially predefined semantics. Querying at what level is the best?
37
Querying at the Syntactic Level In this level we just have an XML document. So we can Query RDF using an XML query language. (e.g. XQuery) But RDF is not just an XML dialect. XML: Has a tree structure data model. Only nodes are labeled. RDF: Has a graph structure data model. Both edges (properties) and nodes (subjects/objects) are labeled. Different ways of encoding the same information in XML are possible.
38
Querying at the Structure Level In this level RDF document represents a set of triples: (type, Book, Class) (subClassOf, FamousWriter, Writer) (hasWritten, twain/mark, ISBN00023423442) (type, twain/mark, FamousWriter) Advantage: Independent of the specific XML syntax. A successful query: SELECT ?x FROM … WHERE (type ?x FamousWriter) An unsuccessful query: SELECT ?x FROM … WHERE (type ?x Writer)
39
Querying at the Semantic Level We need a query language that is sensitive to the RDF Schema primitives: e.g. Class, subClassOf, Property, … RQL RDF Query Language The first proposal for a declarative query language for RDF and RDF Schema. Output of queries is again legal RDF schema code, which can be used as input of another query. A sample query: SELECT Y FROM FamousWriter {X}. hasWritten {Y}
40
Sesame – Introduction & History Sesame: An Architecture for Storing and Querying RDF Data and Schema Information. The European On-To-Knowledge project kicked off in Feb. 2000: This project aims at developing ontology-driven knowledge management tools. In this project Sesame fulfills the role of storage and retrieval middleware for ontologies and metadata expressed in RDF and RDF Schema.
41
On-To-Knowledge Project Sesame is positioned as a central tool in this project. OntoExtract: extracts ontological conceptual structures from natural-language documents. OntoEdit: An ontology editor. RDF Ferret: A user front-end, that provides search and query. RDF Ferret OntoExtract SesameOntoEdit
42
What is Sesame? Sesame is an open source Java framework for storing, querying and reasoning with RDF and RDF Schema. It can be used as: Standalone Server: A database for RDF and RDF Schema. Java Library: For applications that need to work with RDF internally.
43
Sesame’s Architecture Repository Repository Abstraction Layer (RAL) Admin ModuleExport ModuleQuery Module HTTP Protocol HandlerSOAP Protocol Handler Sesame SOAP HTTP
44
The Repository DBMSs Currently, Sesame is able to use PostgreSQL MySQL Oracle (9i or newer) SQL Server Existing RDF stores RDF flat files RDF network services Using multiple sesame server to retrieve results for queries. This opens up the possibility of a highly distributed architecture for RDF(S) storing and querying.
45
Repository Abstraction Layer (RAL) RAL offers stable, high-level interface for talking to repositories. It is defined by an API that offers these functionalities: Add data Retrieve data Delete data Data is returned in streams. (Scalability) Only small amount of data is kept in memory. Suitable for use in highly constrained environments such as portable devices. Caching data (Performance) E.g. caching RDF schema data which is needed very frequently.
46
Stacking Abstraction Layers
47
Admin Module Allows incrementally inserting or deleting RDF data in/from repository. Retrieves its information form an RDF(S) source Parses it using an RDF parser Checks each (S, P, O) statement it gets from the parser for consistency with the information already present in the repository and infers implied information if necessary for instance: If P equals type, it infers that O must be a class. If P equals subClassOf, it infers that S and O must be classes. If P equals subPropertyOf, then it infers that both S and O must be properties. If P equals domain or range, then it infers that S must be a property and O must be a class.
48
Query Module Evaluates RQL queries posed by the user It is independent of the underlying repository. So it can not use optimizations and query evaluations offered by specific DBMSs. RQL queries are translated into a set of calls to the RAL. e.g. when a query contains a join operation over two subqueries, each of the subqueries is evaluated, and the join operation is then executed by the query engine on the results.
49
RDF Export Module This module allows for the extraction of the complete schema and/or data from a model in RDF format. It supplies the basis for using Sesame with other RDF tools.
50
Important Features of Sesame Powerful query language Portability It is written completely in Java. Repository independence Extensibility Other functional modules can be created and be plugged in it. Flexible communication by using protocol handlers The architecture separates the communication details from the actual functionality through the use of protocol handlers.
51
SeRQL (Sesame RDF Query Language) It combined the best features of other query languages: RQL, RDQL, N-Triples, N3 Some of the built-in predicates: {X} serql:directSubClassOf {Y} {X} serql:directSubPropertyOf {Y} {X} serql:directType {Y}
52
Using PostgreSQL as Repository PostgreSQL is an open-source object-relational DBMS. It supports subtable relations between its tables. Subtable relations are also transitive. These relations can be used to model the subsumption reasoning of RDF schema.
53
Example RDF Schema & Data Writer FamousWriter …/ISBN00023423442…/twain/mark BookhasWritten Schema type hasWritten type subClassOf rangedomain Data
54
Storing Schema (in an RDBMS) uri Resource Writer FamousWriter Book uri hasWritten sourcetarget Writer FamousWriter Book Resource Writer Resource sourcetarget hasWrittenWriter sourcetarget hasWrittenBook sourcetarget ClassSubClassOfSubPropertyOf PropertyDomainRange
55
uri …/ISBN00023423442 uri …/twain/mark sourcetarget …/twain/mark…/ISBN00023423442 FamousWriter Writer Book Resource hasWritten Storing Data (PostgreSQL) In order to decrease the database size another table, called resources, is added to database which maps resource descriptions to unique IDs.
56
There are many ambiguities in RDFS: RDF Schema is defined in natural language. No formal description of its semantic is given. E.g. about subClassOf it only says that it is a property with class as its domain and range. RDF Schema is self-describing: The definition of its terms is itself done in RDF schema. As a result it consists some inconsistencies. Circular dependencies in terms definitions: Class is both a subclass of and an instance of Resource. Resource is an instance of Class. RDF Schema Ambiguities
57
Scalability Issues An experiment using Sesame: Uploading and querying a collection of nouns from Wordnet (http://www.semanticweb.org/library)http://www.semanticweb.org/library Consisting of about 400,000 RDF statements. Using a desktop computer (Sun UltraSPARC 5 workstation, 256MB RAM) Uploading the Wordnet nouns took 94 minutes. Querying was quite slow. Because data is distributed over multiple tables, and retrieving data needs doing many joins on tables.
58
Protégé
59
Protégé - Introduction Protégé is an extensible, platform- independent environment for creating and editing ontologies and knowledge bases. Current version is 3.1.1 but the tutorial in the next slides is based on version 2.1.1
60
Tutorial Scenario Semantic Web for Tourism/Traveling Goal: Find matching holiday destinations for a customer I am looking for a comfortable destination with beach access Tourism Web
61
Tourism Semantic Web OWL Metadata (Individuals) OWL Metadata (Individuals) OWL Metadata (Individuals) OWL Metadata (Individuals) Tourism Ontology Web Services Destination AccomodationActivity
62
OWL (in Protégé) Individuals (e.g., “FourSeasons”) Properties ObjectProperties (references) DatatypeProperties (simple values) Classes (e.g., “Hotel”)
63
Individuals Represent objects in the domain Specific things Two names could represent the same “real-world” individual SydneysOlympicBeach BondiBeach Sydney
64
ObjectProperties Link two individuals together Relationships (0..n, n..m) Sydney BondiBeach hasPart FourSeasons hasAccomodation
65
Inverse Properties Represent bidirectional relationships Adding a value to one property also adds a value to the inverse property Sydney BondiBeach hasPart isPartOf
66
Transitive Properties If A is related to B and B is related to C then A is also related to C Often used for part-of relationships Sydney BondiBeach hasPart NewSouthWales hasPart hasPart (derived)
67
DatatypeProperties Link individuals to primitive values (integers, floats, strings, booleans etc) Often: AnnotationProperties without formal “meaning” Sydney hasSize = 4,500,000 isCapital = true rdfs:comment = “Don’t miss the opera house”
68
Classes Sets of individuals with common characteristics Individuals are instances of at least one class City Sydney Beach Cairns BondiBeach CurrawongBeach
69
Range and Domain Property characteristics Domain: “left side of relation” (Destination) Range: “right side” (Accomodation) Sydney BestWestern FourSeasons hasAccomodation Destination Accomodation hasAccomodation
70
Domains Individuals can only take values of properties that have matching domain “Only Destinations can have Accomodations” Domain can contain multiple classes Domain can be undefined: Property can be used everywhere
71
Superclass Relationships Classes can be organized in a hierarchy Direct instances of subclass are also (indirect) instances of superclasses Cairns Sydney Canberra Coonabarabran
72
Class Relationships Classes can overlap arbitrarily City Sydney Cairns BondiBeach RetireeDestination
73
Class Disjointness All classes could potentially overlap In many cases we want to make sure they don’t share instances Sydney UrbanAreaRuralArea Sydney Woomera CapeYork disjointWith City Destination
74
Creating a new OWL project
75
Creating simple classes
76
Creating class hierarchy and set disjoints
77
Creating Contact class with datatype properties
78
Editing details of datatype properties
79
Createing an object property hasContact
80
Creating an object property with inverse
81
Creating the remaining classes and properties
82
Class Descriptions Classes can be described by their logical characteristics Descriptions are “anonymous classes” Things with three star accomodationThings with sightseeing opportunities RetireeDestination Sydney SanJose BlueMountains
83
Class Descriptions Define the “meaning” of classes Anonymous class expressions are used “All national parks have campgrounds.” “A backpackers destination is a destination that has budget accomodation and offers sports or adventure activities.” Expressions mostly restrict property values (OWL Restrictions)
84
Class Descriptions: Why? Based on OWL’s Description Logic support Formalize intentions and modeling decisions (comparable to test cases) Make sure that individuals fulfill conditions Tool-supported reasoning
85
Reasoning with Classes Tool support for three types of reasoning exists: Consistency checking: Can a class have any instances? Classification: Is A a subclass of B? Instance classification: Which classes does an individual belong to? For Protégé we recommend RACER.
86
Restrictions (Overview) Define a condition for property values allValuesFrom someValuesFrom hasValue minCardinality maxCardinality cardinality An anonymous class consisting of all individuals that fulfill the condition
87
Cardinality Restrictions Meaning: The property must have at least/at most/exactly x values is the shortcut for and Example: A FamilyDestination is a Destination that has at least one Accomodation and at least 2 Activities
88
allValuesFrom Restrictions Meaning: All values of the property must be of a certain type Warning: Also individuals with no values fulfill this condition (trivial satisfaction) Example: Hiking is a Sport that is only possible in NationalParks
89
someValuesFrom Restrictions Meaning: At least one value of the property must be of a certain type Others may exist as well Example: A NationalPark is a RuralArea that has at least one Campground and offers at least one Hiking opportunity
90
hasValue Restrictions Meaning: At least one of the values of the property is a certain value Similar to someValuesFrom but with Individuals and primitive values. Example: A PartOfSydney is a Destination where one of the values of the isPartOf property is Sydney
91
Enumerated Classes Consist of exactly the listed individuals OneStarRating TwoStarRating ThreeStarRating BudgetAccomodation
92
Logical Class Definitions Define classes out of other classes unionOf (or) intersectionOf (and) complementOf (not) Allow arbitrary nesting of class descriptions (A and (B or C) and not D)
93
unionOf The class of individuals that belong to class A or class B (or both) Example: Adventure or Sports activities AdventureSports
94
intersectionOf The class of individuals that belong to both class A and class B Example: A BudgetHotelDestination is a destination with accomodation that is a budget accomodation and a hotel BudgetAccomodation Hotel
95
Implicit intersectionOf When a class is defined by more than one class description, then it consists of the intersection of the descriptions Example: A luxury hotel is a hotel that is also an accomodation with 3 stars AccomodationWith3Stars Hotel LuxuryHotel
96
complementOf The class of all individuals that do not belong to a certain class Example: A quiet destination is a destination that is not a family destination Destination FamilyDestination QuietDestination (grayed)
97
Class Conditions Necessary Conditions: (Primitive / partial classes) “If we know that something is a X, then it must fulfill the conditions...” Necessary & Sufficient Conditions: (Defined / complete classes) “If something fulfills the conditions..., then it is an X.”
98
Class Conditions (2) QuietDestination NationalPark (not everything that fulfills these conditions is a NationalPark) (everything that fulfills these conditions is a QuietDestination)
99
Classification NationalPark BackpackersDestination A RuralArea is a Destination A Campground is BudgetAccomodation Hiking is a Sport Therefore: Every NationalPark is a Backpackers-Destiantion
100
Classification (2) Input: Asserted class definitions Output: Inferred subclass relationships
101
Creating an enumerated class out of individuals
102
Creating a hasValue restriction
104
Creating a defined class
105
Classifying Campground
106
Adding restrictions to City and Capital
107
Creating defined class BackpackersDestination
108
Creating defined class FamilyDestination
109
Creating defined class QuietDestination
110
Creating defined class RetireeDestination
111
Classification
112
Consistency Checking
113
Visualization with OWLViz
114
OWL Wizards
115
Ontology Import Adds all classes, properties and individuals from an external OWL ontology into your project Allows to create individuals, subclasses, or to further restrict imported classes Can be used to instantiate an ontology for the Semantic Web
116
Tourism Semantic Web (2) OWL Metadata (Individuals) Tourism Ontology Web Services Destination AccomodationActivity
117
Ontology Import with Protégé On the Metadata tab: Add namespace, define prefix Check “Imported” and reload your project
118
Individuals
120
Generated OWL File \ <rdf:RDF xmlns="http://protege.stanford.edu/plugins/owl/owl-library/heli-bunjee.owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:travel="http://protege.stanford.edu/plugins/owl/owl-library/travel.owl#" xml:base="http://protege.stanford.edu/plugins/owl/owl-library/heli-bunjee.owl"> msb@manicsuperbunjee.com Sydney Queen Victoria St 1240 Manic super bunjee now offers nerve wrecking jumps from 300 feet right out of a helicopter. Satisfaction guaranteed.
121
Lots of other tools RDFStore RDF framework for Perl Raptor RDF parser library Kowari, Gateway triple based database systems RAP RDF framework for PHP Validators For RDF W3C RDF For OWL WonderWeb Pellet
122
References Sesame User Guide for Sesame http://openrdf.org/doc/users/userguide.html http://openrdf.org/doc/users/userguide.html Broekstra J., Sesame: A Generic Architecture for Storing and Querying RDF and RDF Schema, ISWC’02 http://sesame.aidministrator.nl http://www.openRDF.org Protégé http://protege.stanford.edu/ http://www.co-ode.org
123
References Jena Official site of Jena 2 http://jena.sourceforge.net/ Jena 2 Ontology API http://jena.sourceforge.net/ontology/ An Introduction to RDF and the Jena RDF API http://jena.sourceforge.net/tutorial/RDF_API/ A Programmer's Introduction to RDQL http://jena.sourceforge.net/tutorial/RDQL/ Jena 2 Database Interface http://jena.sourceforge.net/DB/ Jena 2 Inference support http://jena.sourceforge.net/inference/ Other tools http://www.daml.org/tools/
124
The End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.