Changes between Version 2 and Version 3 of WikiStart
- Timestamp:
- 04/04/05 13:47:24 (20 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WikiStart
v2 v3 1 1 == 1. Introduction == 2 2 3 rdf2java is a small tool written in Java. It allows an easy handling withRDF data. Instead of using an RDF api for creating and searching for RDF triples, i.e., (subject, predicate, object), you just work with Java objects representing RDF subjects / objects.4 5 Normally, you'd first create an RDFS (RDF Schema) file, containing declarations for classes and properties. RDF data (e.g. in an RDF file) would refer to this RDFS file, just like an XML file can refer to a DTD or to an XML Schema file. The RDF Schema specifies what kind of RDF subjects (i.e. instances of these classes) would be allowed and how they would be linked to each other (-> properties).3 rdf2java is a small tool written in Java. It allows easy handling of RDF data. Instead of using an RDF api for creating and searching for RDF triples, i.e., (subject, predicate, object), you just work with Java objects representing RDF subjects / objects. 4 5 Typically, you first create an RDFS (RDF Schema) file, containing declarations for classes and properties. RDF data (e.g. in an RDF file) refers to this RDFS file, just like an XML file can refer to a DTD or to an XML Schema file. The RDF Schema specifies what kind of RDF subjects (i.e. instances of these classes) are allowed and how they are linked to each other (-> properties). 6 6 So, you have RDFS specifications and RDF data (instances) matching this RDF Schema. 7 7 8 Similarly we first create (generate) Java classes corresponding to the RDFS classes. Then we can "read in" RDF data, which are instances of RDFS classesand convert them to Java objects, being instances of the respective Java classes.8 Using rdf2java (or, to be more precise, the rdfs2class utility of the rdf2java package), we first create Java classes corresponding to the RDFS classes. Then we can use rdf2java to "read in" RDF data, and convert them to Java objects, being instances of the respective Java classes. 9 9 10 10 The original tool was written by Michael Sintek. Information and download of the old tool can be found [http://www.dfki.uni-kl.de/frodo/rdf2java/ here]. … … 95 95 }}} 96 96 97 When you visualize these set of triples you receive the following picture (only the RDF data is shown, not the RDF Schema). Boxes represent resources (RDF subjects) whereas ellipses show literals (strings), which can only be RDF objects. The named and directed edges visualize the predicates. Click on the image to get a bigger version.98 99 XXX image missing 100 graph representation of these RDF triples 97 When you visualize these set of triples you receive the following picture (only the RDF data is shown, not the RDF Schema). Boxes represent resources (RDF subjects) whereas ellipses show literals (strings), which can only be RDF objects. The named and directed edges visualize the predicates. 98 99 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example1.a.75.gif 100 [[BR]] ''graph representation of these RDF triples'' 101 101 102 102 This RDF data contains two Persons: Bart Simpson and Homer Simson, whereas Bart has a parent, namely Homer. … … 150 150 151 151 == 1.5 Online documentation (javadoc) of the rdf2java API == 152 . . . can be found here XXX.152 . . . can be found [http://www.dfki.uni-kl.de/~schwarz/rdf2java/apidoc/index.html here]. 153 153 154 154 == 2. Installation == 155 155 rdf2java is a pure java tool, written using Java 2, JDK 1.3.1_02. Hence, I propose to NOT use an older JDK. However, the sources are included, whereas you could try to recompile the tool with whatever JDK you like. If you are using JBuilder 6 (or later), you will even find a project file "rdf2java.jpx", so you can open it directly into the JBuilder IDE and compile it, debug it, whatever... 156 156 157 Just download rdf2java.zipand extract it to some directory, e.g., C:\java\ (an rdf2java directory will be created there automatically).158 159 Top-level directories: 160 doc : documentation (javadoc) 161 import : jar-files needed by rdf2java; these must be included in the CLASSPATH ("java -cp ..."), when using rdf2java. 162 lib : jar-file of the rdf2java tool; of course this must be included in the CLASSPATH, as well. 163 src : the complete source code 164 testdata : some test data for examples 157 Just download [http://www.dfki.uni-kl.de/~schwarz/rdf2java.zip rdf2java.zip] and extract it to some directory, e.g., C:\java\ (an rdf2java directory will be created there automatically). 158 159 Top-level directories:[[BR]] 160 doc : documentation (javadoc)[[BR]] 161 import : jar-files needed by rdf2java; these must be included in the CLASSPATH ("java -cp ..."), when using rdf2java.[[BR]] 162 lib : jar-file of the rdf2java tool; of course this must be included in the CLASSPATH, as well.[[BR]] 163 src : the complete source code[[BR]] 164 testdata : some test data for examples[[BR]] 165 165 166 166 All you need to use rdf2java is to get the CLASSPATH right, whenever starting a Java-VM. You can either set the CLASSPATH environment variable, or specify the classpath temporarily via the "-cp" parameter whenever you call the java interpreter. … … 239 239 However, the RDF/S files found there are slightly different than the one's I pasted above. That's because they have been generated using Protégé-2000 and, hence, they contain additional, Protégé-2000 specific modeling. Also the generated Java class org.dfki.rdf2java.example1.Person is a bit more complex than the structure snipped above, but after having a look at it, you should roughly get the picture. Besides, although you can, you won't look into these classes very often. They are structures for keeping and representing some RDF data. In most cases, you will do nothing more than just call the getters and putters of these objects. 240 240 241 4. RDF Import / Export (RDF data <--> Java instances) 242 Look at SimpleImportExport.java to get an understanding of how the import / export works. 241 == 4. RDF Import / Export (RDF data <--> Java instances) == 242 243 Look at !SimpleImportExport.java to get an understanding of how the import / export works. 243 244 For a better understanding I pasted an extract of the most important parts of the code below (marginal stuff like, e.g., exception handling has been removed): 244 245 … … 333 334 Assume further we want to assign a new object for Lisa Simpson plus relevant relationships to this knowledge base. You see the graphical representation of the RDF data to assign on the right image below. We will see below, the assignment won't lead to the result you might expect. Later we will show the correct RDF data to assign... 334 335 335 <- 336 337 XXX image missing 338 339 340 the knowledge base so far 341 342 RDF data to assign to the knowledge base 336 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.a.short.75.gif 337 [[BR]] ''the knowledge base so far'' 338 339 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.b.short.gif 340 [[BR]] ''RDF data to assign to the knowledge base'' 343 341 344 342 When looking at these pictures, keep in mind, that they are nothing more than the graphical representation of RDF triples; boxes represent RDF resources, ellipses represent literals (strings). Via rdf2java, resources (boxes) for instances of RDFS classes are represented by corresponding Java objects in the knowledge base, and outgoing edges are stored in these Java objects and are available via getter methods. … … 355 353 The result (knowledge base) is as follows: 356 354 357 355 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.c.short.75.gif 358 356 359 357 The result is not quite the one, you might have expected when I started this example. There are several mistakes: The Bart object forgot about his name. Then it still "knows" about his parent, but the Homer object doesn't reflect this relationship. As RDF/S doesn't know anything about inverse slots, this is this correct RDF. Finally it's not quite what we wanted to receive. The problem arose right at the beginning, where we specified, what RDF data to assign to the knowledge base. Let's make another assignment: 360 358 361 <- 362 363 364 365 366 the knowledge base so far 367 368 RDF data to assign to the knowledge base 359 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.a.short.75.gif 360 [[BR]] ''the knowledge base so far'' 361 362 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.b2.short.75.gif 363 [[BR]] ''RDF data to assign to the knowledge base'' 369 364 370 365 Note, that example1:example1_00005 (on the right image) will only be represented by an RDFResource object, because the right-side Homer object just needs to links to a reference of this resource. There's no need to know about about or change this resource. The Homer object has to be changed because of the hasChild property. Hence, we need to represent that by a THING object and add / change the property values we like. 371 366 However, the result of this assignment will be as follows: 372 367 373 368 http://www.dfki.uni-kl.de/~schwarz/rdf2java/testdata/example/example2.d.short.75.gif 374 369 375 370 == 6. Additional Stuff == 376 In addition to really needed stuff like, e.g., the KnowledgeBase class, other useful tools emerged naturally.371 In addition to really needed stuff like, e.g., the !KnowledgeBase class, other useful tools emerged naturally. 377 372 378 373 == 6.1 RDF Diff (dfki.rdf.util.RDFDiff) ==