Author: Michael Grove
For: MINDSWAP
Introduction
PhotoStuff is an image annotation tool. It allows a user to create markup about images available on the web. Some assertions made by the tool require the use of a digital media ontology that defines concepts such as image, region, and depiction. Rather than having changes in the ontology require code changes, if specific concepts/terms are agreed upon, a generic multimedia term framework could be built. This is the motivation behind the Jena Multimedia API. A collection of generic terms found in any multimedia ontology, such as image, region and depiction, are defined in a programmatic API which is not specifically tied to an ontology. This way ontology changes will not break existing code as the code using this API does not depend on any specific ontology. The end result is that the API allows programmers to write cleaner, more readable code without having to deal with the specifics of the underlying ontology.The API is built directly on top of Jena. Each of the concepts in the API such as Image, Region and Video extend the Jena
Resource class. This allows us to leverage the polymorphism
support natively provided by Jena and was part of the motivation behind building the API on top of Jena.
It is also a good, simple example of how to create your own extension to the Jena Resource interface.
Examples
- Defining a Model Profile
- Creating Images, Regions and Multimedia Models
- Using the API and registering the implementations
- Extending the API
A ModelProfile represents the basic structure of a physical multimedia ontology. It provides a basic layout that maps to the core concepts in the ontology such as image, region and depiction. ModelProfile's are used by the MultimediaModel to identify exactly which resources map to the concepts in the real ontology. It provides basic access methods to get each of these concepts like image, region and depiction. Implementation's of a ModelProfile essentially capture the structure of the physical ontology they represent.
The ModelProfile associated with a MultimediaModel is the reason that the multimedia resources in the model like Image and Video must be associated with a MultimediaModel to work properly. They otherwise would have no handle to the ModelProfile and would not know which properties or classes to use when making assertions. For a full example, see MindswapMultimediaModelProfile
public class GenericModelProfile implements ModelProfile
|
Creating Images, Regions and Multimedia Models
Generally, it is the responsibility of the MultimediaModel to create new resources such as Image, Region and Video. When these resources are created, the rdf:type assertion is made in the model associated with the resource. These resources can also be created using the MultimediaFactory.
public static void main(String[] args) throws Exception
|
Using the API and registering the implementations
One of the key features of the API is that it takes advantage of Jena's polymorphism feature. If you have a handle to a
Resource you know is an Image you
can call .as(Image.class) to return that Resource represented as an Image. If you are not
sure if the conversion to Image is valid, you can call .canAs(Image.class) to find out if
your Resource object can be represented as an Image object. These two functions require implementing
classes to register an Implementation factory object that will provide the functionality to test and see
if the conversion is valid, and to do the actual conversion. There is a class
Mapper that registers all the known implementations.
When you create your own implementation, you should add a line of code to register your new object. Also,
Mapper.mapImplementations should be called during initialization of any applications that use the API.
If it is not called, then you will get ConversionException's when trying to convert and use the multimedia classes.
Check out some source code: See the Mapper source
Here's an example of the Implementation class for Image
Extending the API
1) Create an interface for your new media type, such as Image
a) make sure to extend DigitalMedia, or one of the existing types like Image or Video.
2) Create an implementation for your interface, like ImageImpl
a) be sure to extend
ResourceImpl so that your newly created object is also a Jena Resource.3) Create an Implemtation factory for your new type, like ImageImplementation
4) Add it to the Mapper
5) Add some methods to MultimediaFactory so it can be instantiated by the user
a) perhaps add methods to MultimediaModel for convience.
Links and Resources
- PhotoStuff
- Jena
- Mindswap Jena Multimedia API Javadocs
- Download the source.
- Download the Jar.
- The source is also available from SVN here.
- The Jena Multimedia API uses the Mindswap Utilities Library, which you can find out more here.
