# emftriple **Repository Path**: mirrors_IncQueryLabs/emftriple ## Basic Information - **Project Name**: emftriple - **Description**: EMF Binding for RDF - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-01-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README RDF Binding for EMF --- [![Build Status](https://travis-ci.org/ghillairet/emftriple.svg?branch=master)](https://travis-ci.org/ghillairet/emftriple) EMFTriple is an RDF binding for EMF that will help you persist your EMF models in RDF instead of XMI. EMFTriple can work on regular RDF files and RDF data stores such as the various Sesame implementations (SailRepository) and Jena TDB. EMFTriple comes with two independent implementation, the first makes use of Jena, the second of Sesame. Both implementations provide basic support for reading and writing RDF files in different formats (RDF/XML, Turtle, N-Triples). The Sesame implementation can also work over any SailRepository implementations, while the Jena one can also work over the TDB store. ## Installation Current version: 1.1.0 Update Site: (Composite update site with Jena and Sesame OSGI bundles. See the [content](http://ghillairet.github.io/p2/compositeContent.xml) from your browser.) ## Getting Started Register the desired `Resource.Factory`, e.g. `RDFResourceFactory` for generating RDF/XML files. Registering a `Resource.Factory` is the only thing you have to do to work with RDF. The `RDFResourceFactory` is implemented for both Jena and Sesame (`examples/org.eclipselabs.emftriple.examples.maven.jena` and `examples/org.eclipselabs.emftriple.examples.maven.sesame`, respectively). ```java Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new RDFResourceFactory()); ``` Create your resources and fill it with some objects. The `Book` class is defined in the `org.eclipselabs.emftriple.junit` project. ```java ResourceSet resourceSet = new ResourceSetImpl(); Resource r = resourceSet.createResource(URI.createURI("http://my.rdf")); Book b = ModelFactory.eINSTANCE.createBook(); b.setTitle("The Book"); b.getTags().add("SciFI"); b.getTags().add("Fantasy"); r.getContents().add(b); ``` Save it to a stream. ```java r.save(System.out, null); ``` The Jena version produces the following RDF/XML document: ```xml Fantasy SciFI The Book ``` ## Resource Factories Jena: * `org.eclipselabs.emftriple.jena.resource.NTResourceFactory` -> N-Triples * `org.eclipselabs.emftriple.jena.resource.RDFResourceFactory` -> RDF/XML * `org.eclipselabs.emftriple.jena.resource.RDFJSONResourceFactory` -> RDF/JSON * `org.eclipselabs.emftriple.jena.resource.TTLResourceFactory` -> Turtle Sesame: * `org.eclipselabs.emftriple.sesame.resource.NTResourceFactory` -> N-Triples * `org.eclipselabs.emftriple.sesame.resource.RDFResourceFactory` -> RDF/XML * `org.eclipselabs.emftriple.sesame.resource.TTLResourceFactory` -> Turtle ## RDF Stores When using emftriple on top of an RDF store, you need to use a specific URIHandler that will tell the EMF Resource framework how the Resource can be loaded and saved. Also in that case, a Resource will be map to an RDF named graph, with the Resource URI being the named graph URI or identifier. This will allow a clear storage of EMF models into your RDF store and make it easy to retrieve them. ### Jena TDB Initialize the TDB dataset. ```java Dataset dataset = TDBFactory.createDataset(); ``` Register the RDF `Resource.Factory` and create a new `ResourceSet`. ```java Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new RDFResourceFactory()); ResourceSet resourceSet = new ResourceSetImpl(); ``` Add to the `resourceSet` the `URIHandler` specific to TDB with the required dataset. ```java resourceSet.getURIConverter().getURIHandlers().add(0, new TDBHandler(dataset)); ``` Create a resource as usual, this one will be saved or loaded from the named graph `http://my.rdf` in the dataset. ```java Resource r = resourceSet.createResource(URI.createURI("http://my.rdf")); ``` ### Sesame SailRepository Initialize a SailRepository. ```java Repository repo = new SailRepository(new MemoryStore()); repo.initialize(); ``` Register the RDF `Resource.Factory` and create a new `ResourceSet`. ```java Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new RDFResourceFactory()); ResourceSet resourceSet = new ResourceSetImpl(); ``` Add to the `resourceSet` the `URIHandler` specific to `SailRepository` with the required repository. ```java resourceSet.getURIConverter().getURIHandlers().add(0, new RepositoryHandler(repo)); ``` Create a resource as usual, this one will be saved or loaded from the named graph http://my.rdf in the repository. ```java Resource r = resourceSet.createResource(URI.createURI("http://my.rdf")); ``` ## Using from Maven 1. Get the source code: ``` git clone https://github.com/ghillairet/emftriple.git ``` 2. Import the root project in Eclipse using Import Maven Projects of the [m2e plugin](http://www.eclipse.org/m2e/). 3. Compile and generate update site. ``` mvn clean install ``` 4. Add the required Maven dependencies. Note that [Tycho dependencies from Maven are not transitive](http://wiki.eclipse.org/Tycho/How_Tos/Dependency_on_pom-first_artifacts#Pom-first_dependencies_of_manifest-first_projects_are_not_fully_transitive), so you have to explicitly add the the dependencies of EMFTriple as well. For Sesame: ```xml org.eclipselabs org.eclipselabs.emftriple.sesame 1.1.0-SNAPSHOT org.slf4j slf4j-simple 1.7.13 org.openrdf.sesame sesame-repository-sail 2.8.8 ``` For Jena: ```xml org.eclipselabs org.eclipselabs.emftriple.jena 1.1.0-SNAPSHOT org.slf4j slf4j-simple 1.7.13 ``` The example metamodel is available in the `org.eclipselabs.emftriple.junit` project: ```xml org.eclipselabs org.eclipselabs.emftriple.junit 1.1.0-SNAPSHOT ``` ## License This software is distributed under the terms of the Eclipse Public License 1.0 - http://www.eclipse.org/legal/epl-v10.html.