![]() |
![]() |
|
![]() |
These pages are deprecated ; please go to the pages of our new team EdelweissSemtag: tutorial on the SeWeSe JSP library for Semantic web application using RDF, RDFS, OWL, Rules and SPARQLupdated 02/05/2007About Description Downloads Documentation Tutorial Contacts For remarks or questions on this tutorial contact Fabien Gandon This semantic web application tutorial gives a quick tour of the Sewese JSP library to rapidly develop lightweight web application relying on RDF, RDFS, SPARQL and Rules. It was designed as a hand-on-keyboard introduction to the basics of the SEWESE libary. It uses RDF, RDFS and OWL Lite semantics for lightweight ontologies, SPARQL query language for RDF graph bases and production rules for knowledge factorisation in semantic web annotation bases. TOC: Basics, Initializing, Querying RDF annotations, Querying RDFS/OWL ontologies, Editing RDF annotations. This tutorial uses one web archive (WAR file for the tutorial available on the download page of SeWeSe) and requires that you have a container to deploy it that supports Servlet API 2.4 and JSP 2.0 like Tomcat 5.5.x. The tutorial web application also contains a sub-directory with the solutions of the questions of this tutorial. For a complete javadoc of the Semtag library see the API. For an introduction to RDF SPARQL and rules Corese Tutorial. For an exhaustive introduction to OWL see the OWL Overview. InitializingOnce you have deployed the (web archive) WAR file you can start editing the index.jsp page. (NB: one way to quickly deploy it in tomcat is to paste it in the webapp directory) The web application contains the same ontologies, annotations and rules than the Corese Tutorial. You will find them in the WEB-INF/data sub directory. The first thing to do in an application using the Semtag lib is to initialize at least one Corese instance to load annotations and ontologies. The default instance is named defaultEngineWrapper and can be created by adding this to index.jsp: See also: init
The attributes that appear in lines 2, 3 and 4 specify the directories respectively containing ontologies, annotations and rules to load. Additional attributes like the one in line 5 may be used to declare namespaces which prefix can then directly be used in all the SPARQL queries. Querying RDF annotationsThere are several tags to run SPARQL queries but one of the most useful ones is a JSP loop tag to directly iterate over the results of a query. For instance to lists all the persons annotated in the loaded data just add these lines at the end of the index.jsp file. See also: for-each-result
Line 4 uses the attribute query of the tag for-each-result to specify a query and the selected variables (here ?name). Line 5 directly references the variable in JSP ${name} accessing its value for each result. Imagine you also want the age of the persons then you can just modify lines 4 and 5 like this:
Since not all the persons where specified with their age we are retrieving fewer answers. If we want to say that the age is an optional part of the query we can change the code to take that into account both in the query and in the display of its results when the age variable is not bound:
The Semtag lib also provides the equivalents of the classical if and choose tags but using SPARQL queries as test. For instance if you want to display males in blue and women in red you can change the above code like this:
In lines 7 and 8 a ASK query is used to test the type of the resource ?x returned in each result. Note the use of < and > to escape the < and > surrounding a URI in SPARQL. There are other tags to query the base as you can see in the API. There is also a function to quickly send a query and obtain the first value of the first result:
See also: quickQuery Querying RDFS/OWL ontologiesCorese and Sewese can also be used to query the ontology. For instance to list all the sub-types of animals in the loaded ontology you can use the tag for-each-child: See also: for-each-child
In line 4 the attribute root is used to specify the class for which we want the direct sub-types and the attribute var names the variable that will contain the URI of each child. You could extend this code to display the number of instances for each one of the classes by calling the allInstanceNb function in line 5:
See also: label allInstanceNb There are also two handy functions to generate check boxes and lists from the children of a class:
See also: select
See also: input-list Using functions and tags from the library one can rapidly develop a web-based ontology browser. First add this link at the end of the index.jsp file.
Then make a copy of the index.jsp, name it browse.jsp and leave it at the root of the web application with the index.jsp file. Edit the file browse.jsp and replace the content of its body with the following code:
Test this page by clicking on the link you added to the index.jsp file. This new page is divided in two parts:
See also: for-each-label for-each-comment for-each-child for-each-parent for-each-root-concept for-each-root-property Editing RDF annotationsUsing tags from the library one can also rapidly develop a web-based editor for the RDF data. Let us prototype an small interface to add, edit and remove persons. See also: modify-annot First add this form at the end of the index.jsp file:
Then make a copy of the index.jsp, name it add_person.jsp and leave it at the root of the web application with the index.jsp file. Edit the file add_person.jsp and replace the content of its body with the following code:
Line 2 uses the tag modify-annot and the attribute kind with the value add to specify that we want to add some RDF. Line 5 gives the file and line 3 gives the XPath where the RDF should be added. Line 04 indicates we want the engine to load this change. Line 6 and 7 declare namespaces and 8 to 12 specify the RDF to add. Now to change the name of a person add this form at the end of the index.jsp file:
Then make a copy of the index.jsp, name it edit_person.jsp and leave it at the root of the web application with the index.jsp file. Edit the file edit_person.jsp and replace the content of its body with the following code:
Line 66 uses the tag modify-annot and the attribute kind with the value replace to specify that we want to modify some RDF. Line 9 gives the file and line 7 gives the XPath of the RDF/XML node that should be changed. Line 8 indicates we want the engine to load this change. Line 10 and 11 declare namespaces and line 11 specify the RDF to replace the selected node. Finally to remove a person add this form at the end of the index.jsp file:
Then make a copy of the index.jsp, name it delete_person.jsp and leave it at the root of the web application with the index.jsp file. Edit the file delete_person.jsp and replace the content of its body with the following code:
Line 6 uses the tag modify-annot and the attribute kind with the value del to specify that we want to delete some RDF. Line 9 gives the file and line 7 gives the XPath of the RDF/XML node that should be deleted. Line 8 indicates we want the engine to load this change. Line 10 and 11 declare namespaces. |