Helpers Documentation

From WebLab Wiki
Jump to navigationJump to search

We provide a Java package called WebLab Core that contains useful elements to work with the WebLab Model. These are namely the projects called extended and annotator and some extra helpers (including bean helper and multiple RDF helpers).

Note that in the following examples, sometimes we use PoK as an alias for PieceOfKnowlege.


WebLab Core

WebLab model extended manipulation

The extended project is mainly dedicated to the manipulation of WebLab objects such as a Resource, a Document, a Segment and so on... In the following you will find some examples of use of the extended functionalities.

Create a WebLab PieceOfKnowlegde

The following code will create a new PieceOfKnowlege with the uri: weblab://PoKBuilder/newPoKName

	// Create a Piece of Knowledge with a RDF Triple
	// that describes who created the PoK
	PieceOfKnowledge pok = WebLabResourceFactory.createResource(
		"PoKBuilder", // Identifier of the builder
		"newPoKName", // Identifier of the Resource
		PieceOfKnowledge.class); // Class of the WebLab Resource


Serialise a WebLab Resource in XML

This code illustrates how to serialise a Weblab Resource (here, it is a PieceOfKnowledge but it could be any subclass of WebLab Resource) in an XML file.

	// Let's save our PoK in XML for later use.
	try {
		new WebLabMarshaler().marshalResource(pok, new File("mypok.xml"));
	} catch (WebLabCheckedException e) {
		// If something goes wrong, but it should not ...
		logger.error(e);
	}

The previous code will serialise an empty PieceOfKnowlegde in a XML file named mypok.xml with the following content:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resource xsi:type="ns3:pieceOfKnowledge" uri="weblab://simpleCreationExample/newPoK" xmlns:ns3="http://weblab-project.org/core/model/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>


Deserialise a WebLab Resource from XML

To deserialise a WebLab Resource from an XML file, you can use WebLabMarshaler

	// This example illustrates how to deserialise a PieceOfKnowledge
	PieceOfKnowledge pok;
	try {
		pok = new WebLabMarshaler().unmarshal(new File("src/main/resources/mypok.xml"),PieceOfKnowledge.class);
	} catch (WebLabCheckedException e) {
		// If something goes wrong, you can throw your own exception or deal with the error in the way it pleases you...
	}

WebLab annotator

The WebLab annotator a simple mean to read/write RDF statements into PieceOfKnowledge. See WebLab annotator.

WebLab helpers

WebLab RDF Jena helper

See WebLab RDF helper.

WebLab RDF Jena helper structure

TODO: This part has to be completed.