WebLab 1.2.5/WebLab Model Extended

From WebLab Wiki
Jump to: navigation, search

This page details how to deal with WebLab Resources creation.

All WebLab Resources are describes in the following ontology: WebLab Model

This ontology explains the role of each resource. A more user friendly description is also available here.

For your convenience, we provide a javadoc of WebLab Model.

How to create a WebLab Document?

A WebLab Document is a WebLab Resource dedicated to the representation of a multimedia (with images, texts, videos...) document. A WebLab Document is composed by several WebLab MediaUnit describing parts of the document and it contains WebLab Annotations that described semantic properties about the document itself or its media units.

To create a new WebLab Resource, we provide a factory that generates a Resource and its URI at the same time:

	Document document = WebLabResourceFactory.createResource("document-creator", "document-1", Document.class);

How to create a WebLab Text, Image or Video?

A WebLab Text, Image or Video is a subclass of a WebLab MediaUnit. To create a MediaUnit in a WebLab Document, you should use the same class WebLabResourceFactory. This factory will add your MediaUnit in the Document and will automatically set its URI.

To create a Text in the previous document;

	Text textSection = WebLabResourceFactory.createAndLinkMediaUnit(document, Text.class);
	textSection.setContent("This is the important content of the text unit");

How to create a WebLab Segment to refer to a MediaUnit?

WebLab Segments describe parts of MediaUnit. Thus, part of media unit can be referred in RDF annotation thanks to the URI of its associated Segment. Let's say that we got the following Document with a Text media unit:

	<document uri="weblab://document-creator/document-1" >
		<text uri="weblab://document-creator/document-1#0">
			<content>This is the important content of the text unit</content>
		<text>
	</document>

If we want to refer to the word important from the text unit in an RDF annotation, we must define an URI that will represent an access to this element. We provide a SegmentFactory to create segments. For example, the word important starts at the index 12 and ends at the index 20 in the text content, thus we can define a linear segment to refer this element:

	LinearSegment segment = SegmentFactory.createAndLinkLinearSegment(textSection, 12, 20);

The Segment factory can create several types of Segment; for more information about those, please see Segments description.

How export/import WebLab Resources to and from XML?

We provide a tool to marshall WebLab Resource into XML and to unmarshall them from XMl to retrieve Java Objects. You can use the WebLabMarshaller to save your document in a file:

	WebLabMarshaller wlm = new WebLabMarshaller();
	wlm.marshalResource(document, new File("mydocument.xml"));

The file "mydocument.xml" will contain the following XML description of the document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resource xsi:type="ns3:Document" uri="weblab://document-creator/document-1" xmlns:ns3="http://weblab.ow2.org/core/1.2/model#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <mediaUnit xsi:type="ns3:Text" uri="weblab://document-creator/document-1#0">
        <segment xsi:type="ns3:LinearSegment" end="20" start="12" uri="weblab://document-creator/document-1#0-1"/>
        <content>This is the important content of the text unit</content>
    </mediaUnit>
</resource>

To load your WebLab document, use the unmarshall function:

	WebLabMarshaller wlm = new WebLabMarshaller();
	Document loadedDocument = wlm.unmarshalResource(new File("mydocument.xml"), Document.class);

How to add annotations?

To add annotation on WebLab Resource, you can use Annotator if you want to read/write simple elements (title, author, ...). When you have to deal with huge properties you can have a look at RDF Helpers.