[ Team LiB ] |
10.5 SesameSesame is, to quote the web site where it's supported, "...an Open Source RDF Schema-Based Repository and Querying Facility." It's a Java JSP/Servlet application that I downloaded and installed on my Windows box, running it with a standalone Tomcat server (Version 4.1.18).
Once I worked through an installation problem having to do with an extraneous angle bracket in the web.xml file definition for an Oracle database installation (something the creators of Sesame have said will be fixed), getting the application to run was a piece of cake—just start Tomcat. I installed Sesame with support for MySQL. Once I started it (see instructions), the first thing I did was load in the monsters1.rdf test document, accessed through the URL online. The document loaded fairly quickly, though the tool didn't provide feedback that it was finished loading. After loading, I explored the database entries by accessing the Explore menu option (at the top of the page) and then specifying http://burningbird.net/articles/monsters1.htm as the URI to start the exploration with (the top-level resource for the test document). The page that opened is shown in Figure 10-4. Quite a nice layout, with each predicate/object defined as a hypertext link that takes you to more information about the object. Like BrownSauce, covered in Chapter 7, Sesame provides a nice RDF/XML browser. Figure 10-4. RDF/XML test document, explored in SesameTwo other options at the top of the Sesame page allow you to query the data using RDQL (the same RDQL explored in this chapter) or using Sesame's RQL (RDF Query Language). I accessed the RDQL page first and tried the RDQL query defined earlier in Example 10-7: SELECT ?date WHERE (?resource, <rdf:type>, <pstcn:Movement>), (?resource, <pstcn:movementType>, ?value), (?resource, <dc:date>, ?date) AND (?value eq "Add") USING pstcn FOR <http://burningbird.net/postcon/elements/1.0/>, rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, dc for <http://purl.org/dc/elements/1.1/> Note that this query is looking for a date (dc:date) for the resource movement where the movement was equivalent to the resource being added ("Add"). Figure 10-5 shows the result of running this query, which was evaluated in an amazingly short amount of time—seemingly instantaneous. Figure 10-5. Running RDQL query and viewing the resultRQL is similar in concept to RDQL, though not surprisingly it has a different syntax, as well as different features and functionality. For instance, using the online repository querying capability, you can easily find all RDF classes within the repository just by typing Class as the query (by itself with no other characters). For the test document, the result is: http://www.w3.org/1999/02/22-rdf-syntax-ns#Property http://www.w3.org/2000/01/rdf-schema#Resource http://www.w3.org/2000/01/rdf-schema#Literal http://www.w3.org/2000/01/rdf-schema#Class http://burningbird.net/postcon/elements/1.0/Resource http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq http://burningbird.net/postcon/elements/1.0/Movement The PostCon classes of Movement and Resource are found, as are the RDF class Seq and the RDFS classes of Property, Resource, Literal, and Class. A variation of this query is Property, to get a listing of all properties in the repository. To get more selective in your information querying, to find the source and target for a specific property, you would provide the full URI of the property. For instance, to find the source and target for the predicate movementType, I typed in the following: http://burningbird.net/postcon/elements/1.0/movementType This returned the following: http://www.yasd.com/dynaearth/monsters1.htm "Add" http://www.dynamicearth.com/articles/monsters1.htm "Move" http:/burningbird.net/articles/monsters1.htm "Move" As with RDQL, you can build complex queries using joins and conditional operations. It's here that there's a great deal of similarity between RDQL and RQL. In the following, the source and target for the movementType property is queried using a more formalized SQL-like query like RDQL uses: select X, Y from {X} http://burningbird.net/postcon/elements/1.0/movementType {Y} Conditional operators are provided in a where clause following the select from clause, as the following demonstrates finding a specific source whose movementType is equal to "Add": select X from {X} http://burningbird.net/postcon/elements/1.0/movementType {Y} where Y = "Add" To join queries, use a period between the query results. In the following RQL query, all objects that have a property of http://burningbird.net/postcon/elements/1.0/related are queried and then joined with another query that finds the titles of the related resources: select * from http://burningbird.net/postcon/elements/1.0/related {X}. http://purl.org/dc/ elements/1.1/title {Y} The result from this query is: http://burningbird.net/articles/monsters2.htm "Cryptozooloy" http://burningbird.net/articles/monsters3.htm "A Tale of Two Monsters: Architeuthis Dux (Giant Squid)" http://burningbird.net/articles/monsters4.htm "Nessie, the Loch Ness Monster " You can see a great deal of similarity between the two query languages, and I like both equally well, though I'll admit to a slight preference for the simplicity of RQL. Of course, being able to query a repository via a predefined interface isn't going to help you build an application. Sesame comes with a Java API for both server and client functions, including being able to run RDQL and RQL queries against the repository. I won't cover either in this chapter, as both are quite nicely documented at the Sesame web site, and documentation is included with the downloaded property. One additional feature of Sesame is the repositories support for different protocols for querying the data, using SOAP and the Java RMI in addition to invoking services using HTTP. Again, these are very well documented, including examples, at the Sesame site and in the downloaded product. In addition, as was mentioned earlier in the chapter, you can also use the Sesame repository as the persistent datastore with the Jena Java API. |
[ Team LiB ] |