ghillairet / emftriple

EMF Binding for RDF
25 stars 8 forks source link

URI issue in the README example #13

Closed szarnyasg closed 8 years ago

szarnyasg commented 8 years ago

The example in the README (Sesame, Jena) throws an exception for both implementation:

Sesame:

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid (absolute) URI: my.rdf#/
    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:37)
    at org.eclipselabs.emftriple.sesame.map.Extensions.toURI(Extensions.java:32)
    at org.eclipselabs.emftriple.sesame.map.Serializer.createTypeStatement(Serializer.java:72)
    at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:45)
    at org.eclipselabs.emftriple.sesame.map.Serializer$1.accept(Serializer.java:33)
    at org.eclipselabs.emftriple.sesame.map.Serializer$1.accept(Serializer.java:1)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.eclipselabs.emftriple.sesame.map.Serializer.to(Serializer.java:36)
    at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:34)
    at org.eclipselabs.emftriple.sesame.map.EObjectMapper.to(EObjectMapper.java:19)
    at org.eclipselabs.emftriple.sesame.resource.RDFResource.doSave(RDFResource.java:58)
    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.emftriples.examples.maven.EMFTripleExample.main(EMFTripleExample.java:27)

Jena:

Exception in thread "main" com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <my.rdf#/> Code: 57/REQUIRED_COMPONENT_MISSING in SCHEME: A component that is required by the scheme is missing.
    at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.checkURI(BaseXMLWriter.java:820)
    at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.relativize(BaseXMLWriter.java:797)
    at com.hp.hpl.jena.xmloutput.impl.Basic.writeResourceId(Basic.java:144)
    at com.hp.hpl.jena.xmloutput.impl.Basic.writeDescriptionHeader(Basic.java:92)
    at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFStatements(Basic.java:84)
    at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFStatements(Basic.java:74)
    at com.hp.hpl.jena.xmloutput.impl.Basic.writeBody(Basic.java:48)
    at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.writeXMLBody(BaseXMLWriter.java:492)
    at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:464)
    at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:450)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.write(ModelCom.java:347)
    at org.eclipselabs.emftriple.jena.io.RDFWriter.writeXML(RDFWriter.java:47)
    at org.eclipselabs.emftriple.jena.io.RDFWriter.write(RDFWriter.java:28)
    at org.eclipselabs.emftriple.jena.resource.RDFResource.write(RDFResource.java:67)
    at org.eclipselabs.emftriple.jena.resource.RDFResource.doSave(RDFResource.java:58)
    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.emftriples.examples.maven.sesame.EMFTripleExample.main(EMFTripleExample.java:26)

To fix this, I changed the my.rdf URI to a file URI file:///tmp/my.rdf:

final Resource r = resourceSet.createResource(URI.createURI("file:///tmp/my.rdf"));

This runs fine for both.

Sesame:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<rdf:Description rdf:about="file:///tmp/my.rdf#/">
    <rdf:type rdf:resource="http://www.eclipselabs.org/emf/junit#//Book"/>
    <title xmlns="http://www.eclipselabs.org/emf/junit#//Book/" rdf:datatype="http://www.w3.org/2001/XMLSchema#string">The Book</title>
    <tags xmlns="http://www.eclipselabs.org/emf/junit#//Book/" rdf:datatype="http://www.w3.org/2001/XMLSchema#string">SciFI</tags>
    <tags xmlns="http://www.eclipselabs.org/emf/junit#//Book/" rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Fantasy</tags>
</rdf:Description>

</rdf:RDF>

Jena:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://www.eclipselabs.org/emf/junit#//Book/"
    xmlns:j.1="http://www.eclipselabs.org/emf/junit#//" > 
  <rdf:Description rdf:about="file:///tmp/my.rdf#/">
    <j.0:tags>Fantasy</j.0:tags>
    <j.0:tags>SciFI</j.0:tags>
    <j.0:title>The Book</j.0:title>
    <rdf:type rdf:resource="http://www.eclipselabs.org/emf/junit#//Book"/>
  </rdf:Description>
</rdf:RDF>

The latter is very similar to the output suggested in the README, the main difference is (of course) the URI in the rdf:about attribute.

Should this be fixed in the README or the implementation?

szarnyasg commented 8 years ago

I figured it out: the issue was with the README. The implementations work now:

I'll fix the README soon.

szarnyasg commented 8 years ago

Fixed by PR #12.