ghillairet / emftriple

EMF Binding for RDF

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not a valid (absolute) URI Exception when trying to save to File

frostyandy2k opened this issue · comments

Hello,

when trying to save the resource I encounter following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid (absolute) URI: my.rdf#1
at org.openrdf.model.impl.URIImpl.setURIString(URIImpl.java:79)
at org.openrdf.model.impl.URIImpl.<init>(URIImpl.java:68)
at org.eclipselabs.emftriple.sesame.map.Extensions.toURI(Extensions.java:40)
at org.eclipselabs.emftriple.sesame.map.Extensions.toURI(Extensions.java:34)
at org.eclipselabs.emftriple.sesame.map.Serializer.createTypeStatement(Serializer.java:76)
at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:51)
at org.eclipselabs.emftriple.sesame.map.Serializer$2.apply(Serializer.java:39)
at org.eclipselabs.emftriple.sesame.map.Serializer$2.apply(Serializer.java:1)
at org.eclipse.xtext.xbase.lib.IteratorExtensions.forEach(IteratorExtensions.java:362)
at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:331)
at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:42)
at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:37)
at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:19)
at org.eclipselabs.emftriple.sesame.resource.RDFResource.doSave(RDFResource.java:60)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)
at org.eclipselabs.emftriple.example.Main.test(Main.java:97)

The model is the one from:

emftriple/examples/org.eclipselabs.emftriple.examples.basic/model/model.ecore

This is my code (copied from the git README):

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new RDFResourceFactory());
ResourceSet resourceSet = new ResourceSetImpl();
Resource r = resourceSet.createResource(URI.createURI("my.rdf"));
Parent b = ModelFactory.eINSTANCE.createParent();
b.setId("1");
b.setName("Parent1");
r.getContents().add(b);
r.save(null);

The import statements are:

package org.eclipselabs.emftriple.example;

import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipselabs.emftriple.example.model.Child;
import org.eclipselabs.emftriple.example.model.ModelFactory;
import org.eclipselabs.emftriple.example.model.ModelPackage;
import org.eclipselabs.emftriple.example.model.Parent;
import org.eclipselabs.emftriple.sesame.handlers.RepositoryHandler;
import org.eclipselabs.emftriple.sesame.resource.RDFResourceFactory;
import org.eclipselabs.emftriple.sesame.resource.TTLResource;
import org.eclipselabs.emftriple.sesame.resource.TTLResourceFactory;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.memory.MemoryStore;

I tried with different URI formats and absolute paths, but I seem to have a problem when saving to a file.

I tried on a different machine and the XMI save works. Unfortunately i still get the exact error when using an RDF ressource.

import org.eclipselabs.emftriple.sesame.resource.RDFResource;
Resource r = new RDFResource(URI.createURI("my.rdf"));

It works !!

It seems the other computer(Mac OSX 10.9) had a problem AND you have to specify the full absolute URI:

    Resource r = new RDFResource(URI.createURI("file:/D:\\Program Files\\eclipseEmfTriple\\workspace\\org.eclipselabs.emftriple.examples.basic\\my.rdf"));

    Book b = ModelFactory.eINSTANCE.createBook();
    b.setTitle("The Book");
    b.getTags().add("SciFI");
    b.getTags().add("Fantasy");

    r.getContents().add(b);
    r.save(null);

Too bad the URI is not normalized automatically.

Could you maybe update the README of the project?

Fixed the Mac OS X issue. I specified a wrong absolute URI, forgot a second "/".

This works now:

    String file = "file://Users/myusername/sources/emftriple/examples/org.eclipselabs.emftriple.examples.basic/model/Parent.ttl";
    Resource resRDF = new TTLResource(URI.createURI(file));

Maybe you should try with URI.createFileURI instead.

Does not work, because an absolute URI is needed and URI.createFileURI() does not do that.

I'm now using convertToFileURL("model/entitysupermodel.ecore") from http://stackoverflow.com/questions/3631623/convert-url-to-absolutepath

Could you change the README such that it is clear one needs to input an absolute URI? I spent some hours debugging..

Anyways, awesome work with EMFTriple!