The document discusses the semantic web stack, which is made up of standards and technologies organized into layers. It describes the lower layers including URIs, Unicode, XML, RDF, RDF Schema, and ontologies. Ontologies add expressive power to define complex conceptual structures. The focus of the chapter is on programming semantic web applications using the Jena framework.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
82 views32 pages
Programming The Semantic Web
The document discusses the semantic web stack, which is made up of standards and technologies organized into layers. It describes the lower layers including URIs, Unicode, XML, RDF, RDF Schema, and ontologies. Ontologies add expressive power to define complex conceptual structures. The focus of the chapter is on programming semantic web applications using the Jena framework.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32
Chapter 14
PROGRAMMING THE SEMANTIC WEB
J orge Cardoso 1 Department of Mathematics and Engineering,University of Madeira, 9000-390, Funchal, Portugal jcardoso@uma.pt 1. INTRODUCTION Many researchers believe that a new Web will emerge in the next few years based on the large-scale ongoing research and developments in the semantic Web. Nevertheless, the industry and its main players are adopting a wait-and-see approach to see how real-world applications can benefit from semantic Web technologies (Cardoso, Miller et al. 2005). The success of the semantic Web vision (Berners- Lee, Hendler et al. 2001) is dependant on the development of practical and useful semantic Web-based applications. While the semantic Web has reached considerable stability from the technological point of view with the development of languages to represent knowledge (such as OWL (OWL 2004)), to query knowledge bases (RQL (Karvounarakis, Alexaki et al. 2002) and RDQL (RDQL 2005)), and to describe business rules (such as SWRL (Ian Horrocks, Peter F. Patel-Schneider et al. 2003)), the industry is still skeptical about its potential. For the semantic Web to gain considerable acceptance from the industry it is indispensable to develop real-world semantic Web-based applications to validate and explore the full potential of the semantic Web (Lassila and McGuinness 2001). The success of the semantic Web depends on its capability of supporting applications in commercial settings (Cardoso, Miller et al. 2005). Semantic Web Services, Processes and Applications
2 In several fields, the technologies associated with the semantic Web have been implemented with considerable success. Examples include semantic Web services (OWL-S 2004), tourism information systems (Cardoso 2004), semantic digital libraries, (Shum, Motta et al. 2000), semantic Grid (Roure, J ennings et al. 2001), semantic Web search (Swoogle 2005), and bioinformatics (Kumar and Smith 2004). To increase the development of semantic Web systems and solutions, in this chapter we will show how semantic Web applications can be developed using the J ena framework. 2. THE SEMANTIC WEB STACK The semantic Web identifies a set of technologies, tools, and standards which form the basic building blocks of an infrastructure to support the vision of the Web associated with meaning. The semantic Web architecture is composed of a series of standards organized into a certain structure that is an expression of their interrelationships. This architecture is often represented using a diagram first proposed by Tim Berners-Lee (Berners-Lee, Hendler et al. 2001). Figure 14-1 illustrates the different parts of the semantic Web architecture. It starts with the foundation of URIs and Unicode. On top of that we can find the syntactic interoperability layer in the form of XML, which in turn underlies RDF and RDF Schema (RDFS). Web ontology languages are built on top of RDF(S). The three last layers are the logic, proof, and trust, which have not been significantly explored. Some of the layers rely on the digital signature component to ensure security. Unicode URI XML + NS+ xmlschema RDF + rdfschema Ontol ogy vocabulary Logic Proof Trust D i g i t a l
S i g n a t u r e Our focus in this chapter
Figure 14-1. Semantic Web stack (Berners-Lee, Hendler et al. 2001) Programming the Semantic Web
3 In the following sections we will briefly describe these layers. While the notions presented have been simplified, they provide a reasonable conceptualization of the various components of the semantic Web.
URI and Unicode. A Universal Resource Identifier (URI) is a formatted string that serves as a means of identifying abstract or physical resource. A URI can be further classified as a Uniform Resource Locator (URL) or a Uniform Resource Name (URN). A URL identifies resources via a representation of their primary access mechanism. A URN remains globally unique and persistent even when the resource ceases to exist or becomes unavailable. Unicode provides a unique number for every character, independently of the underlying platform or program. Before the creation of unicode, there were various different encoding systems making the manipulation of data complex and required computers to support many different encodings.
XML. XML is accepted as a standard for data interchange on the Web allowing the structuring of data but without communicating the meaning of the data. It is a language for semi-structured data and has been proposed as a solution for data integration problems, because it allows a flexible coding and display of data, by using metadata to describe the structure of data. While XML has gained much of the worlds attention it is important to recognize that XML is simply a way of standardizing data formats. But from the point of view of semantic interoperability, XML has limitations. One significant aspect is that there is no way to recognize the semantics of a particular domain because XML aims at document structure and imposes no common interpretation of the data (Decker, Melnik et al. 2000). Even though XML is simply a data-format standard, it is part of the set of technologies that constitute the foundations of the semantic Web.
RDF. At the top of XML, the World Wide Web Consortium (W3C) has developed the Resource Description Framework (RDF) (RDF 2002) language to standardize the definition and use of metadata. RDF uses XML and it is at the base of the semantic Web, so that all the other languages corresponding to the upper layers are built on top of it. RDF is a simple general-purpose metadata language for representing information in the Web and provides a model for describing and creating relationships between resources. RDF defines Semantic Web Services, Processes and Applications
4 a resource as any object that is uniquely identifiable by a URI. Resources have properties associated with them. Properties are identified by property-types, and property-types have corresponding values. Property-types express the relationships of values associated with resources. The basic structure of RDF is very simple and basically uses RDF triples in the form of (subject, predicate, object). RDF has a very limited set of syntactic constructs and no other constructs except for triples is allowed.
RDF Schema. The RDF Schema (RDFS 2004) provides a type system for RDF. Briefly, the RDF Schema (RDFS) allows users to define resources (rdfs:Resource) with classes, properties, and values. The concept of RDFS class (rdfs:Class) is similar to the concept of class in object-oriented programming languages such as J ava and C++. A class is a structure of similar things and inheritance is allowed. This allows resources to be defined as instances of classes. An RDFS property (rdf:Property) can be viewed as an attribute of a class. RDFS properties may inherit from other properties (rdfs:subPropertyOf), and domain (rdfs:domain) and range (rdfs:range) constraints can be applied to focus their use. For example, a domain constraint is used to limit what class or classes a specific property may have and a range constraint is used to limit its possible values. With these extensions, RDFS comes closer to existing ontology languages.
Ontologies. An ontology is an agreed vocabulary that provides a set of well-founded constructs to build meaningful higher level knowledge for specifying the semantics of terminology systems in a well defined and unambiguous manner. Ontologies can be used to assist in communication between humans, to achieve interoperability and communication among software systems, and to improve the design and the quality of software systems (J asper and Uschold 1999). In the previous sections, we have established that RDF and RDFS were the base models and syntax for the semantic Web. On the top of the RDF/S layer it is possible to define more powerful languages to describe semantics. The most prominent markup language for publishing and sharing data using ontologies on the Internet is the Web Ontology Language (OWL 2004). OWL adds a layer of expressive power to RDF/S, providing powerful mechanisms for defining complex conceptual structures, and formally describes the semantics of classes and properties used in Web resources using, most Programming the Semantic Web
5 commonly, a logical formalism known as Description Logic (DL 2005).
Logic, Proof, and Trust. The purpose of this layer is to provide similar features to the ones that can be found in First Order Logic (FOL). The idea is to state any logical principle and allow the computer to reason by inference using these principles. For example, a university may decide that if a student has a GPA higher than 3.8, then he will receive a merit scholarship. A logic program can use this rule to make a simple deduction: David has a GPA of 3.9, therefore he will be a recipient of a merit scholarship. The use of inference engines in the semantic Web allows applications to inquire why a particular conclusion has been reached (inference engines, also called reasoners, are software applications that derive new facts or associations from existing information.). Semantic applications can give proof of their conclusions. Proof traces or explains the steps involved in logical reasoning. Trust is the top layer of the Semantic Web architecture. This layer provides authentication of identity and evidence of the trustworthiness of data and services. While the other layers of the semantic Web stack have received a fair amount of attention, no significant research has been carried out in the context of this layer. 3. SEMANTIC WEB DEVELOPMENT ENVIRONMENTS Several frameworks supporting OWL ontologies are available. We will briefly discuss the ones that are used the most by the developer community, namely the J ena framework, Protg-OWL API and the WonderWeb OWL API, which are all available for J ava language. These three APIs are open-source and thus interested people can carry out an in-depth study of their architecture. This is very important for the current stage of semantic Web development since it is difficult to know what the applications scope of the semantic Web will be in the near future. Therefore, open frameworks will allow for an easier integration of semantic Web components into new projects. J ena (J ena 2002; J ena 2005) is a J ava framework for building semantic Web applications developed by the HP Labs Semantic Web Programme. It provides a programmatic environment for RDF, RDFS and OWL, including a rule-based inference engine and a query Semantic Web Services, Processes and Applications
6 language for RDF called RDQL (RDQL 2005). Since we are mostly interested in ontology support, in subsequent sections we will discuss the J ena 2 Ontology API included in the J ena toolkit. This API supports several ontology description languages such as DAML, DAML+OIL and OWL. However building ontologies in OWL W3Cs language is strongly recommended because DAML and DAML+OIL support may be removed in future releases of J ena. Because J ena 2 Ontology API is language-neutral, it should be easy to update existing projects using J ena and other ontology languages to support OWL. J ena OWL API supports all three OWL sublanguages, namely OWL Lite, OWL DL and OWL Full. Specifying an URI to an OWL ontology, J ena parses the ontology and creates a model for it. With this model it is possible to manipulate the ontology, create new OWL classes, properties or individuals (instances). The parsing of OWL documents can be highly resource consuming, especially for documents describing large ontologies. To address this particularity, J ena provides a persistence mechanism to store and retrieve ontology models from databases efficiently. As stated before, J ena includes an inference engine which gives reasoning capabilities. J ena provides three different reasoners that can be attached to an ontology model, each of them providing a different degree of reasoning capability. More capable reasoners require substantially more time to answer queries. Therefore, developers should be very careful when choosing a reasoner. Of course, it is possible to create a model with no reasoner defined. An interesting aspect of J ena is that its inference engine is written in a very generic way so that it allows developers to write their own inference rules to better address their needs. This generic implementation also allows for attaching any reasoner that is compliant with the DIG interface, which is a standard providing access to reasoners, such as Racer, FaCT, and Pellet. Another important aspect is that it is very easy to find documentation and practical programming examples for J ena. Protg (Protg 2005) is a free, open-source platform that provides a growing user community with a suite of tools to construct domain models and knowledge-based applications with ontologies. It was developed by the Stanford Medical Informatics Labs of the Stanford School of Medicine. The Protg-OWL API is an open- source J ava library for OWL and RDF(S). The API provides classes and methods to load and store OWL files, to query and manipulate OWL data models, and to perform reasoning (Protg-API 2006). This API, which is part of the Protg-OWL plug-in, extends the Programming the Semantic Web
7 Protg Core System based on frames so that it can support OWL ontologies and allows users to develop OWL plug-ins for Protg or even to create standalone applications. Protg-OWL API uses J ena framework for the parsing and reasoning over OWL ontologies and provides additional support for programming graphical user interfaces based on J ava Swing library. The Protg-OWL API architecture follows the model-view pattern, enabling users to write GUIs (the view) to manipulate the internal representation of ontologies (the model). This architecture, together with the event mechanism also provided, allows programmers to build interactive user interfaces in an efficient and clean way. A community even stronger than J enas one has grown around Protg, making it very easy to find good documentation, examples and support for this API. WonderWeb OWL API (OWLAPI 2006) is another API providing programmatic services to manipulate OWL ontologies. It can also infer new knowledge once a reasoner is attached to the ontology model. Pellet is one of the reasoners that is currently supported. One should note that the current release of this API is still in working progress. Consequently, there are some issues that need to be corrected. Nevertheless, WonderWeb OWL API was successfully used in several projects such as Swoop (SWOOP 2006) and Smore (SMORE 2006), respectively, an ontology editor and a semantic annotation tool, from the MIND LAB at the University of Maryland Institute for Advanced Computer Studies. This demonstrates that this API is mature enough to be considered when developing semantic Web applications. One major drawback of the WonderWeb OWL API is lack of documentation. Currently, J avadoc documentation and some open-source applications that use this API, is what can be found about it. It is very difficult to find practical examples. This fact may lead developers to choose to discard this API. 4. OUR RUNNING ONTOLOGY Our recent work has involved the development of a Semantic Course Management System (S-CMS). Course management systems (CMS) are becoming increasingly popular. Well-known CMSs include Blackboard.com and WebCT.com whose focus has centered on distance education opportunities. Typically, a CMS include a variety of functionalities, such as class project management, registration tool for students, examinations, enrolment management, test Semantic Web Services, Processes and Applications
8 administration, assessment tools, and online discussion boards (Meinel, Sack et al. 2002). The S-CMS system that we have developed is part of the Strawberry project 1 and explores the use of semantic Web technologies to develop an innovative CMS. The S-CMS provides a complete information and management solution for students and faculty members. Our focus and main objective was to automate the different procedures involved when students enroll or register for class projects. Managing a large course and its class projects is a complex undertaking. Many factors may contribute to this complexity, such as a large number of students, the variety of rules that allow students to register for a particular project, students background, and students grades. The development of a semantic Web application typically starts with the creation of one or more ontology schema. For simplicity reasons, in this chapter we will only present one ontology, the University ontology. This ontology will be used in all the programming examples that we will show. As with any ontology, our ontology contains the definition of the various classes, attributes, and relationships that encapsulate the business objects that model a university domain. The class hierarchy of our simple ontology is shown in Figure 14-1 using the OWL Viz Protg plug-in (OWLViz 2006).
Figure 14-2. Class hierarchy Some of the properties of our ontology are shown in Figure 14-2 using Protg (Protg 2005).
1 http://dme.uma.pt/jcardoso/Research/Projects/Strawberry/ Programming the Semantic Web
9
Figure 14-3. Classes and properties 5. USING JENA J ena is a framework for building Semantic Web applications. It provides a programmatic environment for RDF, RDFS and OWL. It also includes a rule-based inference engine. J ena is open source and is a development effort of the HP Labs Semantic Web Research program. HP Labs have made considerable investments in Semantic Web research since 2000 which lead to the development of standards (such as RDF and OWL) and semantic applications (such as J ena). The J ena toolbox includes a J ava programming API that gives a framework to program semantic Web applications. The API is divided into five sets of functions that deal with the processing of ontologies, namely:
Processing and manipulation of RDF data models Processing and manipulation of ontologies SPARQL query support Properties Class hierarchy Semantic Web Services, Processes and Applications
10 Inference on OWL and RDFS data models Persistence of ontologies to databases
In this chapter we will focus primarily on the API responsible for the processing and manipulation of OWL ontologies. 5.1 Installing Jena To install J ena the first step is to download J ena API from http://jena.sourceforge.net. The version used for the examples shown in this chapter was J ena 2.3. Once you have downloaded J ena (in our case the package was named J ena 2. 3. zi p), you need to extract the zip file. You will find in the /lib directory all the libraries needed to use the J ena API. To develop semantic applications with J ava you will need to update your CLASSPATH to include the following libraries:
ant l r - 2. 7. 5. j ar ar q. j ar commons- l oggi ng. j ar concur r ent . j ar i cu4j _3_4. j ar j akar t a- or o- 2. 0. 8. j ar j ena. j ar j enat est . j ar j uni t . j ar l og4j - 1. 2. 12. j ar st ax- 1. 1. 1- dev. j ar st ax- api - 1. 0. j ar xer cesI mpl . j ar xml - api s. j ar 5.2 Creating an Ontology Model The main J ava class that represents an ontology in memory is the OntModel.
Ont Model model ;
Programming the Semantic Web
11 In J ena, ontology models are created using the Model Fact or y class. A model can be dynamically created by calling the cr eat eOnt ol ogyModel ( ) method.
Ont Model m= Model Fact or y. cr eat eOnt ol ogyModel ( ) ;
When creating an ontology it is possible to describe its characteristics, such as the ontology language used to model the ontology, the storage scheme and the reasoner. To describe specific characteristics of an ontology, the method cr eat eOnt ol ogyModel ( Ont Model Spec o) needs to be called and accepts a parameter of the type Ont Model Spec. For example, Ont Model Spec. OWL_DL_MEM determines that the ontology to be created will have an OWL DL model and will be stored in memory with no support for reasoning. Various other values are available. Table 14-1 illustrates some of the possibilities. Table 14-1. Types of ontology models with J ena Field Description DAML_MEM A simple DAML model stored in memory with no support for reasoning DAML_MEM_RDFS_I NF A DAML model stored in memory with support for RDFS inference OWL_LI TE_MEM A simple OWL Lite model stored in memory with no support for reasoning OWL_MEM_RULE_I NF A OWL Lite model stored in memory with support for OWL rules inference RDFS_MEM A simple OWL Lite model stored in memory with no support for reasoning
More than 20 different ontology models can be created. The following segment of code illustrates how to create an OWL ontology model, stored in memory, with no support for reasoning.
i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y;
publ i c cl ass Cr eat eModel publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ; } Semantic Web Services, Processes and Applications
12 } 5.3 Reading an Ontology Model Once we have an ontology model, we can load an ontology. Ontologies can be loaded using the r ead method which can read an ontology from an URL or directly from an input stream.
r ead( St r i ng ur l ) r ead( I nput St r eamr eader , St r i ng base)
In the following example, we show a segment of code that creates an OWL ontology model in memory and loads the University ontology from the URL ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl .
Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ; model . r ead( "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl " ) ;
For performance reasons, it is possible to cache ontology models locally. To cache a model, it is necessary to use a helper class that manages documents (Ont Document Manager ), allowing subsequent accesses to an ontology to be made locally. The following example illustrates how to add an entry for an alternative copy of an OWL file with the given OWL URI. An alternative copy can be added by calling the method addAl t Ent r y.
i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Document Manager ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y;
publ i c cl ass CacheOnt ol ogy { publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { Ont Model m= Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ; Ont Document Manager dm= m. get Document Manager ( ) ; dm. addAl t Ent r y( "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ", "f i l e: / / / c: / Uni ver si t y. OWL") ; Programming the Semantic Web
13 m. r ead( "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ; } }
Since we specify that a local copy of our University ontology exists in f i l e: / / / c: / Uni ver si t y. OWL, J ena can load the ontology from the local copy instead of loading it from the URL. 5.4 Manipulating Classes OWL ontology classes are described using the Ont Cl ass J ava class. To retrieve a particular class from an ontology we can simply use the method get Ont Cl ass( URI ) from the Ont Model or, alternatively, it is possible to use the l i st Cl asses( ) method to obtain a list of all the classes of an ontology. The class Ont Cl ass allows us to retrieve all the subclasses of a class using the method l i st SubCl asses( ) . For example, the following segment of code allows listing of all the subclasses of the class #Per son of our University ontology.
St r i ng baseURI = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #";
Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ;
model . r ead( ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ; Ont Cl ass p = model . get Ont Cl ass( baseURI +"Per son") ; f or ( Ext endedI t er at or i =p. l i st SubCl asses( ) ; i . hasNext ( ) ; ) { Ont Cl ass Cl ass=( Ont Cl ass) i . next ( ) ; Syst em. out . pr i nt l n( Cl ass. get URI ( ) ) ; }
In our scenario the output of this example is:
ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #St udent ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Teacher
Semantic Web Services, Processes and Applications
14 The cr eat eCl ass method can be used to create a new class. For example we can create the new class #Resear cher and set as superclass the class #Per son from the previous example,
Ont Cl ass p = model . get Ont Cl ass( baseURI +"Per son") ; Ont Cl ass r = model . cr eat eCl ass( baseURI +"Resear cher ") ; r . addSuper Cl ass( p)
The class Ont Cl ass has several methods available to check the characteristics of a class. All these methods return a Boolean parameter. Some of these methods are illustrated in table 14-2. Table 14-2. Methods to check the characteristics of an OntClass object i sI nt er sect i onCl ass( ) i sCompl ement Cl ass( ) i sRest r i ct i on( ) hasSuper Cl ass( )
5.5 Manipulating Properties With J ena, properties are represented using the class Ont Pr oper t y. Two types of OWL properties exist:
Datatype Properties are attributes of a class. These types of properties link individuals to data values and can be used to restrict an individual member of a class to RDF literals and XML Schema datatypes. Object Properties are relationships between classes. They link individuals to individuals. They relate an instance of one class to an instance of another class.
It is possible to dynamically create new properties. The Ont Model class includes the method cr eat eXXX( ) to create properties (and classes as we have already seen previously). As an example, the following code creates a new class named #Pr oj ect and an Obj ect Pr oper t y named #Pr oj ect Owner . Using the set Range and set Domai n methods of the class Obj ect Pr oper t y we set the domain of the new property to #Pr oj ect and its range to #Per son.
. . . Ont Cl ass p=model . cr eat eCl ass( BaseUr i +"#Pr oj ect ") ; Obj ect Pr oper t y po= Programming the Semantic Web
15 model . cr eat eObj ect Pr oper t y( BaseUr i +"#Pr oj ect Owner ") ; po. set Range( model . get Resour ce( BaseUr i +"#Per son") ) ; po. set Domai n( p) ; . . .
A DatatypeProperty can be created in the same way, but using the cr eat eDat at ypePr oper t y method, i.e.
Dat at ypePr oper t y p= model . cr eat eDat at ypePr oper t y( BaseUr i +"#Pr oj ect Dat e") ;
The class Ont Pr oper t y has several methods available to check the characteristics of a Property. All these methods return a Boolean parameter. For example, Table 14-3. Methods to check the characteristics of an OntProperty object i sTr ansi t i vePr oper t y( ) i sSymmet r i cPr oper t y( ) i sDat at ypePr oper t y( ) i sObj ect Pr oper t y( )
The following segment of code can be used to list the properties of a class. Basically the l i st Decl ar edPr oper t i es( ) from the class Ont Cl ass needs to be called.
i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Cl ass; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y; i mpor t com. hp. hpl . j ena. ut i l . i t er at or . Ext endedI t er at or ;
publ i c cl ass Li st Pr oper t i es { publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { St r i ng baseURI = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #";
Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ;
model . r ead( ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ;
Ont Cl ass cl s = model . get Ont Cl ass( baseURI +"Per son") ; Semantic Web Services, Processes and Applications
16 Syst em. out . pr i nt l n( "Cl ass: ") ; Syst em. out . pr i nt l n( " "+cl s. get URI ( ) ) ; Syst em. out . pr i nt l n( "Pr oper t i es: ") ; f or ( Ext endedI t er at or j =cl s. l i st Decl ar edPr oper t i es( ) ; . hasNext ( ) ; ) { Syst em. out . pr i nt l n( " "+( Ont Pr oper t y) j . next ( ) ) ; } } }
The output of executing this example is:
Cl ass: ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Per son Pr oper t i es: ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Age ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Addr ess ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Emai l ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Name
#Age, #Addr ess, #Emai l , and #Name are properties of the class #Per son. 5.6 Manipulating Instances Instances, also known as individuals of classes, are represented through the class I nst ance. Having a class Ont Cl ass it is possible to list all its instances using the method l i st I nst ances( ) . A similar method exists in the class Ont Model but is named l i st I ndi vi dual s( ) . For example, the following segment of code lists all the individuals of the University ontology,
i mpor t com. hp. hpl . j ena. ont ol ogy. I ndi vi dual ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y; i mpor t com. hp. hpl . j ena. ut i l . i t er at or . Ext endedI t er at or ;
publ i c cl ass Li st I nst ances { publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { Programming the Semantic Web
17 Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ;
model . r ead( ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ; f or ( Ext endedI t er at or i = model . l i st I ndi vi dual s( ) ; . hasNext ( ) ; ) { Syst em. out . pr i nt l n( ( ( I ndi vi dual ) i . next ( ) ) . t oSt r i ng( ) ) ; } } }
The output of executing this example is:
ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Adel i a ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Fat i ma ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Car ol i na ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #ASP ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #SD ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #CF ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Gr ade_1 ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Gr ade_3 ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Gr ade_2 ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #I C ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #J C ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #RF
To list all the individuals of the class #St udent , we can add the following lines of code to the previous example:
Ont Cl ass St udent = model . get Ont Cl ass( ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #St udent ) ; f or ( Ext endedI t er at or i = St udent . l i st I nst ances( ) ; i . hasNext ( ) ; ) { Syst em. out . pr i nt l n( ( ( I ndi vi dual ) i . next ( ) ) . t oSt r i ng( ) ) ; }
Now we can create instances dynamically. The following example creates an instance #J or ge of type #Teacher and set the name and Semantic Web Services, Processes and Applications
18 e-mail of the instance #J or ge to J orge Cardoso and jcardoso@uma.pt, respectively.
Resour ce t Cl ass=model . get Resour ce( baseURI +"#Teacher ") ; I ndi vi dual t eacher = model . cr eat eI ndi vi dual ( baseURI +"#J or ge", t Cl ass) ; Dat at ypePr oper t y name = model . get Dat at ypePr oper t y( baseURI +"#Name") ; t eacher . addPr oper t y( name, "J or ge Car doso") ; Dat at ypePr oper t y emai l = model . get Dat at ypePr oper t y( baseURI +"#Emai l ") ; t eacher . addPr oper t y( emai l , "j car doso@uma. pt ") ; 5.7 Queries with Jena One task that is particularly useful once an ontology is available, is to query its data. An OWL knowledge base can be queried using API function calls or using RDQL (RDF Data Query Language). J enas built-in query language is RDQL, a query language for RDF. While not yet a formally established standard, (it was submitted in J anuary 2004), RDQL is commonly used by many RDF applications. RDQL has been designed to execute queries in RDF models, but it can be used to query OWL models since their underlying representation is RDF. It is a very effective way of retrieving data from an RDF model. 5.7.1 RDQL Syntax RDQLs syntax is very similar to SQLs syntax. Some of their concepts are comparable and will be well-known to people that have previously worked with relational database queries. A simple example of a RDQL query structure is,
SELECT variables WHERE conditions
Variables are represented with a question mark followed by the variable name (for example: ?a, ?b). Conditions are written as triples (Subject Property Value) and delimited with < and >. RDQL allows us to search within a RDF graph to find subgraphs that match some patterns of RDF node triples. Programming the Semantic Web
19 Using our University ontology, we can inquire about the direct subclasses of the class #Per son. This can be achieved with the following RDQL query:
SELECT ?x WHERE ( ?x <r df s: subCl assOf > <uni v: Per son>) USI NG r df s FOR <ht t p: / / www. w3. or g/ 2000/ 01/ r df - schema#> uni v FOR ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #>
The ?x in this query is a variable representing something that we want of the query. The query engine will try to substitute a URI value for ?x when it finds a subclass of #Per son. The rdfs and univ prefixes make the URIs in the query shorter and more understandable. Executing the above query to the University ontology illustrated in Figure 14-1 we expected to retrieve two URIs. One corresponding to the #St udent concept and the other to the concept #Teacher , i.e.
<ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #St udent > <ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Teacher >
RDQL allows complex queries to be expressed succinctly, with a query engine performing the hard work of accessing the data model. Sometimes, not every part of the ontology structure is known. For example, if we wish to inquire about the list of courses that a student has enrolled for. Since we do not know all the URIs, we have to use variables to represent the unknown items in the query. For instance, Show me all Y where Y is a Course, X is a Student, X is named Adelia Gouveia, and X studies Y. The response will list all the possible values for Y that would match the desired properties. The query for this question would be,
SELECT ?y WHERE ( ?x <uni v: Name> "Adel i a Gouvei a"^^xsd: st r i ng) , ( ?x <uni v: St udi es> ?y) USI NG uni v FOR <ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #>
We can also ask for all the students that have passed courses with a grade higher than 12,
SELECT ?x, ?c Semantic Web Services, Processes and Applications
20 WHERE ( ?x <uni v: HasGr ade> ?y) , ( ?x <uni v: St udi es> ?c) , ( ?y <uni v: Val ue> ?z) AND ?z>12 USI NG uni v FOR <ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #> 5.7.2 RDQL and Jena J enas com. hp. hpl . j ena. r dql package contains all of the classes and interfaces needed to use RDQL in a J ava application.
i mpor t com. hp. hpl . j ena. r dql ;
J enas RDQL is implemented as an object called Quer y. To create a query it is sufficient to put the RDQL query in a St r i ng object, and pass it to the constructor of Quer y,
St r i ng quer ySt r i ng =. . . ; Quer y quer y = new Quer y( quer ySt r i ng) ;
The method set Sour ce of the object Quer y must be called to explicitly set the ontology model to be used as the source for the query (the model can alternatively be specified with a FROM clause in the RDQL query.)
quer y. set Sour ce( model ) ;
Once a Quer y is prepared, a Quer yEngi ne must be created and the query can be executed using the exec( ) method. The Quer y needs to be passed to the Quer yEngi ne object, i.e.
Quer yEngi ne qe = new Quer yEngi ne( quer y) ;
The results of a query are stored in a Quer yResul t object.
Quer yResul t s r esul t s = qe. exec( ) ;
Once we have the results of a RDQL query, a practical object that can be used to display the results in a convenient way is to use the Quer yResul t sFor mat t er object.
Programming the Semantic Web
21 Quer yResul t sFor mat t er f or mat t er = new Quer yResul t sFor mat t er ( ( Quer yResul t s) r esul t s ) ; f or mat t er . pr i nt Al l ( new Pr i nt Wr i t er ( Syst em. out ) ) ;
An alternative to using the Quer yResul t sFor mat t er object is to iterate through the data retrieved using an iterator. For example,
Quer yResul t s r esul t = new Quer yEngi ne( quer y) . exec( ) ; f or ( I t er at or i = r esul t ; i . hasNext ( ) ; ) { Syst em. out . pr i nt l n( i . next ( ) ) ; }
With RDQL it is possible to inquire about the values that satisfy a triple with a specific subject and property. To run this query in J ena, the University ontology is loaded into memory. The query is executed using the static exec method of J enas Quer y class and the results are processed. For example, the following segment of code retrieves all the RDF triples of an ontology.
i mpor t j ava. ut i l . I t er at or ;
i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y; i mpor t com. hp. hpl . j ena. r dql . Quer y; i mpor t com. hp. hpl . j ena. r dql . Quer yEngi ne; i mpor t com. hp. hpl . j ena. r dql . Quer yResul t s;
publ i c cl ass RDQL { publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ; model . r ead( "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ;
St r i ng sql = "SELECT ?x, ?y, ?z WHERE ( ?x ?y ?z) "; Quer y quer y=new Quer y( sql ) ; quer y. set Sour ce( model ) ; Quer yResul t s r esul t = new Quer yEngi ne( quer y) . exec( ) ; f or ( I t er at or i = r esul t ; i . hasNext ( ) ; ) { Syst em. out . pr i nt l n( i . next ( ) ) ; Semantic Web Services, Processes and Applications
22 } } }; 5.8 Inference and Reasoning Inference engines, also called reasoners, are software applications that derive new facts or associations from existing information. Inference and inference rules allow for deriving new data from data that is already known. Thus, new pieces of knowledge can be added based on previous ones. By creating a model of the information and relationships, we enable reasoners to draw logical conclusions based on the model. For example, with OWL it is possible to make inferences based on the associations represented in the models, which primarily means inferring transitive relationships. Nowadays, many inference engines are available.
J ena reasoner J ena includes a generic rule based inference engine together with configured rule sets for RDFS and for OWL. J ess Using J ess (Gandon and Sadeh 2003) it is possible to build J ava software that has the capacity to reason using knowledge supplied in the form of declarative rules. Jess has a small footprint and it is one of the fastest rule engines available. It was developed at Carnegie Melon University. SWI-Prolog Semantic Web Library Prolog is a natural language for working with RDF and OWL. The developers of SWI-Prolog have created a toolkit for creating and editing RDF and OWL applications, as well as a reasoning package (Wielemaker 2005). FaCT++ This system is a Description Logic reasoner, which is a re-implementation of the FaCT reasoner. It allows reasoning with the OWL language (FaCT 2005).
In the following sections we will concentrate our attention on using the J ena rule based inference engine programmatically. 5.8.1 Jena Reasoners The J ena architecture is designed to allow several inference engines to be used with J ena. The current version of Jena includes five predefined reasoners that can be invoked, namely:
Programming the Semantic Web
23 Transitive reasoner: A very simple reasoner which implements only the transitive and symmetric properties of r df s: subPr oper t yOf and r df s: subCl assOf . DAML micro reasoner: A DAML reasoner which provides an engine to legacy applications that use the DAML language. RDFS rule reasoner: A RDFS reasoner that supports most of the RDFS language. Generic rule reasoner: A generic reasoner that is the basis for the RDFS and OWL reasoners. OWL reasoners: OWL rule reasoners are an extension of the RDFS reasoner. They exploit a rule-based engine for reasoning. OWL reasoners supports OWL Lite plus some of the constructs of OWL Full.
In this section we will study how to develop J ava applications using the OWL reasoning engines since OWL is becoming the most popular language on the semantic Web compared to DAML and RDFS. 5.8.2 Jena OWL Reasoners J ena provides three internal reasoners of different complexity: OWL, OWL Mini, and OWL Micro reasoners. They range from the simple Micro reasoner with only domain-range and subclass inference, to a complete OWL Lite reasoner. The current version of J ena (version 2.3) does not fully support OWL yet. It can understand all the syntax of OWL, but cannot reason in OWL Full. J ena supports OWL Lite plus some constructs of OWL DL and OWL Full, such as owl : hasVal ue. Some of the important constructs that are not supported in J ena include owl : compl ement Of and owl : oneOf . Table 14-4 illustrates the OWL constructs supported by the reasoning engines available. Table 14-4. J ena reasoning support OWL Construct Reasoner rdfs:subClassOf, rdfs:subPropertyOf, rdf:type all rdfs:domain, rdfs:range all owl:intersectionOf all owl:unionOf all owl:equivalentClass all owl:disjointWith full, mini owl:sameAs, owl:differentFrom, owl:distinctMembers full, mini Semantic Web Services, Processes and Applications
24 owl:Thing all owl:equivalentProperty, owl:inverseOf all owl:FunctionalProperty, owl:InverseFunctionalProperty all owl:SymmeticProperty, owl:TransitiveProperty all owl:someValuesFrom full, (mini) owl:allValuesFrom full, mini owl:minCardinality, owl:maxCardinality, owl:cardinality full, (mini) owl:hasValue all owl:complementOf none owl:oneOf none
For a complete OWL DL reasoning it is necessary to use an external DL reasoner. The J ena DIG interface makes it easy to connect to any reasoner that supports the DIG standard. By communicating with other ontology processing systems, such as RACER or FAcT, J ena can enhance its ability for reasoning in large and complex ontologies. 5.8.3 Programming Jena reasoners Given an ontology model, J enas reasoning engine can derive additional statements that the model does not express explicitly. Inference and inference rules allow for deriving new data from data that is already known. Thus, new pieces of knowledge can be added based on previous ones. By creating a model of the information and relationships, we enable reasoners to draw logical conclusions based on the model. As we have already done previously, the first step to develop a semantic Web application with support for reasoning is to create an ontology model,
St r i ng baseURI = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #";
Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ;
model . r ead( ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl ") ;
The main class to carry our reasoning is the class Reasoner . This class allows us to extract knowledge from an ontology. J ena provides several reasoners to work with different types of ontology. Since in Programming the Semantic Web
25 our example we want to use our OWL University ontology, we need to obtain an OWL reasoner. This reasoner can be accessed using t he Reasoner Regi st er y. get OWLReasoner ( ) method call, i.e.,
Reasoner r easoner = Reasoner Regi st r y. get OWLReasoner ( ) ;
Other reasoners can be instantiated with a call to the methods get OWLMi cr oReasoner ( ) , get OWLMi ni Reasoner ( ) , get RDFSReasoner ( ) , and get Tr ansi t i veReasoner ( ) .
Once we have a reasoner, we need to bind it to the ontology model we have created. This is achieved with a call to the method bi ndSchema, i.e.,
r easoner = r easoner . bi ndSchema( model ) ;
This invocation returns a reasoner which can infer new knowledge from the ontologys rules. The next step is to use the bound reasoner to create an I nf Model from the University model,
I nf Model i nf model =Model Fact or y. cr eat eI nf Model ( r easoner , model ) ;
Since several J ava packages are needed to execute and run the examples that we have given, the following segment shows all the J ava code needed to instantiate a reasoner.
i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model ; i mpor t com. hp. hpl . j ena. ont ol ogy. Ont Model Spec; i mpor t com. hp. hpl . j ena. r df . model . I nf Model ; i mpor t com. hp. hpl . j ena. r df . model . Model Fact or y; i mpor t com. hp. hpl . j ena. r easoner . Reasoner ; i mpor t com. hp. hpl . j ena. r easoner . Reasoner Regi st r y;
publ i c cl ass I nst anci at eReasoner { publ i c st at i c voi d mai n( St r i ng[ ] ar gs) { Ont Model model = Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM) ;
St r i ng BaseUr i = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl "; model . r ead( BaseUr i ) ; Semantic Web Services, Processes and Applications
26
Reasoner r easoner = Reasoner Regi st r y. get OWLReasoner ( ) ; r easoner =r easoner . bi ndSchema( model ) ; I nf Model i nf model = Model Fact or y. cr eat eI nf Model ( r easoner , model ) ; } }
Once a reasoner is instantiated, one of the first tasks that we can execute is to check for inconsistencies within the ontology data by using the val i dat e( ) method, i.e.,
Val i di t yRepor t vr = i nf model . val i dat e( ) ; i f ( vr . i sVal i d( ) ) { Syst em. out . pr i nt l n( "Val i d OWL") ; } el se { Syst em. out . pr i nt l n( "Not a val i d OWL! ") ; f or ( I t er at or i = vr . get Repor t s( ) ; i . hasNext ( ) ; ) { Syst em. out . pr i nt l n( i . next ( ) ) ; } }
This example prints a report if the ontology data is found to be inconsistent. The following output shows the example of a report generated when trying to validate an inconsistent ontology,
Not a val i d OWL - Er r or ( "r ange check") : "I ncor r ect l y t yped l i t er al due t o r ange ( pr op, val ue) " Cul pr i t = ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Car ol i na I mpl i cat ed node: ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl #Emai l I mpl i cat ed node: ' car ol i na@uma. pt '
The report indicates that the email address (#Emai l ) of the individual #Car ol i na has an incorrect type. One other interesting operation that we can carry out is to obtain information from the ontology. For example, we can retrieve all the Programming the Semantic Web
27 pairs (property, resource) associated with the resource describing the course CS8050, which is defined with ID #CS8050.
St r i ng BaseUr i = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl "; . . . Resour ce r es = i nf model . get Resour ce( BaseUr i +"#CS") ; Syst em. out . pr i nt l n( "CS8050 *: ") ;
f or ( St mt I t er at or i = i nf model . l i st St at ement s( r es, ( Pr oper t y) nul l , ( Resour ce) nul l ) ; i . hasNext ( ) ; ) { St at ement st mt = i . next St at ement ( ) ; Syst em. out . pr i nt l n( Pr i nt Ut i l . pr i nt ( st mt ) ) ; }
The output of running the previous example is shown below. To make the output more readable we have replaced the URI ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl with the symbol @and the URI ht t p: / / www. w3. or g/ 2001/ XMLSchema with the symbol .
CS8050 *: ( @#CS8050 r df : t ype @#Cour se) ( @#CS8050 @#I sSt udi edBy @#Adel i a) ( @#CS8050 @#Cour seName ' Semant i c Web' ^^#st r i ng) ( @#CS8050 @#I sSt udi edBy @#Car ol i na) ( @#CS8050 @#I sTeachedBy @#I sabel Car doso) ( @#CS8050 r df : t ype owl : Thi ng) ( @#CS8050 r df : t ype r df s: Resour ce) . . . ( @#CS8050 owl : sameAs @#CS8050)
Instance recognition is another important operation in inference. Instance recognition tests if a particular individual belongs to a class. For example, in our University ontology, #Adel i a is known to be an individual of the class #St udent and the class #St udent is a subclass of the class #Per son. One question that can be asked is if #Adel i a is recognized to be an instance or individual of the class Semantic Web Services, Processes and Applications
28 #Per son, in other words is Adelia a person? This can be asked of the inference model using the cont ai ns method, i.e.,
Resour ce r 1 = i nf model . get Resour ce( BaseUr i +"#Adel i a") ; Resour ce r 2 = i nf model . get Resour ce( BaseUr i +"#Per son") ;
i f ( i nf model . cont ai ns( r 1, RDF. t ype, r 2) ) { Syst em. out . pr i nt l n( "Adel i a i s a Per son") ; } el se { Syst em. out . pr i nt l n( "Adel i a i s not a Per son") ; }
Other interesting examples of inference include the use of the transitivity, union, functional, and intersection properties. 5.9 Persistence As we have seen above, J ena provides a set of methods to load ontologies from files containing information models and instances. J ena can also store and load ontologies from relational databases. Depending on the database management system used, it is possible to distribute stored metadata. While J ena itself is not distributed, by using a distributed database back end, an application may be distributed. Currently, J ena only supports MySQL, Oracle and PostgreSQL. To create a persistent model in a database we can use the Model Fact or y object and invoke the cr eat eModel RDBMaker method. This method accepts a DBConnect i on connection object to the database. An object Model Maker will be created and can subsequently be used to create the model in the database. For example, to store an existing ontology model in a database we can execute the following segment of code,
Cl ass. f or Name( "com. mysql . j dbc. Dr i ver ") ; St r i ng BaseURI = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl "; DBConnect i on conn = new DBConnect i on( "j dbc: mysql : / / l ocal host / Uni vDB", "myl ogi n", "mypasswor d", "MySQL") ; Model Maker maker =Model Fact or y. cr eat eModel RDBMaker ( conn) ; Model db=maker . cr eat eModel ( BaseURI , f al se) ; Programming the Semantic Web
29 db. begi n( ) ; db. r ead( BaseURI ) ; db. commi t ( ) ;
And to read a model from a database we can use the following program,
Cl ass. f or Name( "com. mysql . j dbc. Dr i ver ") ; St r i ng BaseURI = "ht t p: / / dme. uma. pt / j car doso/ owl / Uni ver si t y. owl "; DBConnect i on conn = new DBConnect i on( "j dbc: mysql : / / l ocal host / Uni vDB", "myl ogi n", "mypasswor d", "MySQL") ; Model Maker maker =Model Fact or y. cr eat eModel RDBMaker ( conn) ; Model base=maker . cr eat eModel ( BaseURI , f al se) ; model =Model Fact or y. cr eat eOnt ol ogyModel ( Ont Model Spec. OWL_MEM, base) ; 6. QUESTIONS FOR DISCUSSION Beginner: 1. Identify the main differences between XML and RDF. 2. Install J ena in your computer and create programmatically an OWL ontology describing painters and their paintings. The ontology should be able to represent the following statements: Painter X has painted the painting Y, Painter X was born in W, and Painting Y was painted in year Z. 3. Create several individuals for the Painters ontology. For example: Paul Cezanne, born 1839, Aix-en-Provence, France, painted Le paysan and Le Vase Bleu; Leonardo da Vinci, born 1452, Vinci, Florence, painted Mona Lisa and The Last Supper; Michelangelo Buonaroti, born 1475, Florence, painted Sybille de Cummes and Delphes Sylphide.
Intermediate: 1. Identify the main differences between RDFS and OWL. 2. Write down an RDQL query which retrieves the names of all the painters born in Florence using the ontology created in the previous exercise. Semantic Web Services, Processes and Applications
30 3. Use J ena to execute the previous RDQL query and write down the results of executing the query on the ontology. 4. Make your ontology persistent in a database.
Advanced: 1. Write down and execute an RDQL query which retrieves the paintings Michelangelo Buonaroti painted in 1512 (note: The Sybille de Cummes was painted 1512). 2. Validate your model using J enas inference engine. 3. Why is inference a time consuming operation? 7. SUGGESTED ADDITIONAL READING J ena Documentation, http://jena.sourceforge.net/documentation.html. This is a fundamental source of information to start programming with the J ena Framework. Antoniou, G. and van Harmelen, F. A semantic Web primer. Cambridge, MA: MIT Press, 2004. 238 pp.: This book is a good introduction to Semantic Web languages. H. Peter Alesso and Craig F. Smith, Developing Semantic Web Services, AK Peters, Ltd, October, 2004, 445 pp.: The book presents a good overview of Semantic Tools in chapter thirteen. 8. REFERENCES Berners-Lee, T., J . Hendler, et al. (2001). The Semantic Web. Scientific American. May 2001. Berners-Lee, T., J . Hendler, et al. (2001). The Semantic Web: A new formof Web content that is meaningful to computers will unleash a revolution of new possibilities. Scientific American. Cardoso, J . (2004). Issues of Dynamic Travel Packaging using Web Process Technology. International Conference e-Commerce 2004, Lisbon, Portugal. Cardoso, J ., J . Miller, et al. (2005). Academic and Industrial Research: Do their Approaches Differ in Adding Semantics to Web Services. Semantic Web Process: powering next generation of processes with Semantics and Web services. J . Cardoso and S. A. Heidelberg, Germany, Springer-Verlag. 3387: 14-21. Decker, S., S. Melnik, et al. (2000). "The Semantic Web: The Roles of XML and RDF." Internet Computing 4(5): 63-74. Programming the Semantic Web
31 DL (2005). Description Logics, http://www.dl.kr.org/. FaCT (2005). FaCT++, http://owl.man.ac.uk/factplusplus/. Gandon, F. L. and N. M. Sadeh (2003). OWL inference engine using XSLT and J ESS, http://www- 2.cs.cmu.edu/~sadeh/MyCampusMirror/OWLEngine.html. Ian Horrocks, Peter F. Patel-Schneider, et al. (2003). SWRL: A Semantic Web Rule Language Combining OWL and RuleML, http://www.daml.org/2003/11/swrl/. J asper, R. and M. Uschold (1999). A framework for understanding and classifying ontology applications J ena (2002). The jena semantic web toolkit, . IJ CAI99 Workshop on Ontologies and Problem- Solving Methods. http://www.hpl.hp.com/semweb/jena- top.html, Hewlett-Packard Company. J ena (2005). J ena - A Semantic Web Framework for J ava, http://jena.sourceforge.net/,. Karvounarakis, G., S. Alexaki, et al. (2002). RQL: a declarative query language for RDF. Eleventh International World Wide Web Conference, Honolulu, Hawaii, USA. Kumar, A. and B. Smith (2004). On Controlled Vocabularies in Bioinformatics: A Case Study in Gene Ontology. Drug Discovery Today: BIOSILICO. 2: 246- 252. Lassila, O. and D. McGuinness (2001). "The Role of Frame-Based Representation on the Semantic Web." Linkping Electronic Articles in Computer and Information Science 6(5). Meinel, C., H. Sack, et al. (2002). Course management in the twinkle of an eye - LCMS: a professional course management system OWL (2004). OWL Web Ontology Language Reference, W3C Recommendation, World Wide Web Consortium, . Proceedings of the 30th annual ACM SIGUCCS conference on User services, Providence, Rhode Island, USA, ACM Press. http://www.w3.org/TR/owl-ref/. 2004. OWLAPI (2006). "The WonderWeb OLW API, http://sourceforge.net/projects/owlapi." OWL-S (2004). OWL-based Web Service Ontology. 2004. OWLViz (2006). OWL Viz. [Online] Available at http://www.co- ode.org/downloads/owlviz/. Protg (2005). Protg, Stanford Medical Informatics. 2005. Protg-API (2006). The Protg-OWL API - Programmer's Guide, http://protege.stanford.edu/plugins/owl/api/guide.html. RDF (2002). Resource Description Framework (RDF), http://www.w3.org/RDF/. RDFS (2004). RDF Vocabulary Description Language 1.0: RDF Schema, W3C, http://www.w3.org/TR/rdf-schema/. RDQL (2005). J ena RDQL, http://jena.sourceforge.net/RDQL/. Semantic Web Services, Processes and Applications
32 Roure, D., N. J ennings, et al. (2001). Research Agenda for the Future Semantic Grid: A Future e-Science Infrastructure http://www.semanticgrid.org/v1.9/semgrid.pdf. Shum, S. B., E. Motta, et al. (2000). "ScholOnto: an ontology-based digital library server for research documents and discourse." International Journal on Digital Libraries SMORE (2006). "SMORE - Create OWL Markup for HTML Web Pages, 3(3): 237-248. http://www.mindswap.org/2005/SMORE/." Swoogle (2005). Search and Metadata for the Semantic Web - http://swoogle.umbc.edu/. SWOOP (2006). "SWOOP - A Hypermedia-based Featherweight OWL Ontology Editor, www.mindswap.org/2004/SWOOP/." Wielemaker, J . (2005). SWI-Prolog Semantic Web Library, http://www.swi- prolog.org/packages/semweb.html.