Migrating an Existing Application to the Semantic Web

his is the third article in a series that describes the why, what, and how to migrate an existing application to the semantic web. The first article, “Why Migrate to the Semantic Web,” outlined the reasons for migrating an existing web application to the semantic web. The second article, “Laying the Foundation of a Semantic Web Application,” focused on selecting a suitable semantic web framework (Jena plus SDB).

This article focuses on migrating a CDMS web application that supports quality assurance and compliance checking in the Australian building and construction industries to the semantic web. As a part of this process:

  • Information useful to the general building industry but previously hidden within the application becomes publicly available as Linked Data.
  • The existing domain model classes are mapped to RDF.
  • The security model is refactored to incorporate FOAF-based social networking information.

Publishing Selected Database Tables as Linked Data

Stored in a MySQL database within CDMS is a subset of information that you can share with the general building and construction industry to help promote a higher, uniform standard of quality. This subset is described in the article “Constructing an Ontology – Common Inspection and Test Plans.” The central concept is an Inspection and Test Plan (ITP) that identifies when and what will be inspected and verified to meet acceptance criteria.

The D2R Server provides an easy way to publish the ITP and related tables to the semantic web as Linked Data. After the content is published as Linked Data, other building applications can use the ITP. For example, you can create an owl:ObjectProperty, such as the following appliesInspectionTestPlan:

building:appliesInspectionTestPlan      a       owl:ObjectProperty ;      rdfs:domain building:BuildingProject ;      rdfs:label "applies inspection test plan"^^xsd:string .
Figure 1. Building Project: An extract from the updated building project is shown here.

Adding this definition to a building project example called Breaker Bay allows the published ITP to be applied to building projects. This is shown in Figure 1.

The process for publishing the database tables to the semantic web is as follows. First, create a MySQL database common_itps by logging into mysql and running the command:

mysql> create database common_itps character set utf8 ;

Unzip the attached source code and open a command prompt in the top directory, which contains the file common_itps.sql. This is a mysql dump of the ITP, which you can load into the database by running the command:

mysql --user=richard_rap --password=fender common_itps < common_itps.sql

Install the D2R Server by following the Quick Start instructions and adding the MySQL driver JAR file to the D2R Server installation /lib directory.

Generate a mapping file (mapping_common_itps.n3) for the common_itps database by opening a command prompt in the D2R Server directory and running:

generate-mapping -o mapping_common_itps.n3 -u db-user -p db-password jdbc:mysql://localhost/common_itps

After the mapping file is generated, start the server by running the command:

d2r-server mapping_common_itps.n3
Figure 2. SPARQL Query: You can see the initial project set up here.

Alternatively, you can start the server using the mapping file simple_mapping_common_itps.n3 from src/main/data. This mapping file hides audit fields such as created_by and updated_at.

You can now browse the ITP data online by opening http://localhost:2020/ in a web browser, ideally Firefox with the Tabulator extension installed.

Open the ITP directly in the browser using URLs such as http://localhost:2020/resource/inspection_test_plan/1.

You can run SPARQL queries using the AJAX-based SPARQL explorer http://localhost:2020/snorql/. For example, run the following SPARQL query (see Figure 2):

PREFIX itp:  CONSTRUCT { ?s itp:inspection_test_plan_name ?name } WHERE {?s a itp:inspection_test_plan . ?s itp:inspection_test_plan_name ?name } ORDER BY ASC(?name) LIMIT 5

Mapping Existing Domain Classes to RDF

Jenabean provides an easy way to map existing domain model classes to RDF using annotations. (See "Jenabean: Easily bind JavaBeans to RDF" for more details on Jenabean.)

Jersey and implicit MVC also provide an easy way to create a simple RESTful web application based on Jena SDB (installed in the previous article "Laying the Foundation of a Semantic Web Application").

You can use a combination of Jenabean and Jersey annotations to map a domain class to RDF and also a RESTful resource that receives HTTP requests.

The Jenabean annotation @Namespace defines the namespace for the BuildingProject class, @RdfProperty defines the RDF property, and @Uri specifies the URI of the instance. This allows you to add the builder and ITP to the building project.

The Jersey JAX-RS annotations @POST, @Path, @Consumes, and @Produces allow the BuildingProject class to receive the POST requests from the JSP page, which is part of the implicit MVC implementation (see Listing 1).

Refactoring the Existing Security Model

The existing CDMS application stores its user and role information in the database tables user and role with a third table user_role linking them together. Additional tables link the project owner, the building project, and users participating in project activities.

User and Role classes map to the user and role tables using Hibernate JPA and implement the Spring Security framework interfaces UserDetails and GrantedAuthority respectively. The UserServiceImpl implements the UserDetailsService.

In the semantic web version of the application, a building project is stored as an RDF Named Graph in SDB. The URI of this graph contains the user name of the project owner. Also, as shown in this example project, roles are now defined by an owl:ObjectProperty such as foaf:fundedBy, building: builtBy, and building:designedBy. People are represented as foaf:Person. A URI to the foaf:Person definition for a person, such as contained in their personal FOAF page, links the person to the project.

To bridge the existing user table to the RDF project, the column person_uri is added to the user table, linking a CDMS user to their foaf:Person definition.

Access to a project can be controlled based on a person:

  • Having a CDMS user account for accessing restricted information
  • Being the owner of the project
  • Having a role on the project

If the user is the owner of the project, the username is part of the URI of the project. If the user has a role on the project, they are associated via an RDF property.

Figure 3. Access: An example of who has access to the project.

For example, Alex, who is the architect, is given access to the Breaker Bay project (see Figure 3).

A user is still authenticated using the user name and password held in the user table, but the Spring Security authorization now includes an additional AccessDecisionVoter, called ProjectMemberVoter, which implements the access rules above.

When a user who is not the project owner requests project access, the result of the SPARQL query below is used to check the projects they are associated with:

'SELECT DISTINCT ?s { GRAPH ?g 	{ ?s a   . 	?s ?p  < person_uri > } } '

where < person_uri > is the person's FOAF URI.

For the project example above, the query grants Alex access to the BreakerBay project.

Next Steps

You now know how to take the first steps in migrating to the semantic web, just enough to begin publishing data to the semantic web and incorporating information already there.

The next steps include:

  • Publishing project information as Linked Data
  • Providing a user-friendly interface to the application, including AJAX controls for the lookup of external Linked Data information and querying of local project information

The the attached source code contains a full semantic web application. You should build the maven project 3kbo-security first, because the buildings project (which is the semantic web application) has a dependency on the security project.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS