Skip to content

Instantly share code, notes, and snippets.

@harschware
Created October 5, 2013 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harschware/6835202 to your computer and use it in GitHub Desktop.
Save harschware/6835202 to your computer and use it in GitHub Desktop.
2013-Oct-04 17:52:34.010 PDT DEBUG [main] [org.apache.jena.riot.stream.JenaIOEnvironment:createLocationMapper] [JenaIOEnvironment.java:181] [] [] [] - Failed to find configuration: location-mapping.ttl;location-mapping.rdf;location-mapping.n3;etc/location-mapping.rdf;etc/location-mapping.n3;etc/location-mapping.ttl
=== FILE CONTENTS ===
_:b0 <http://p> <http://o> .
=== MODEL CONTENTS ===
blank URI URI
Exception in thread "main" com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <http://> Code: 57/REQUIRED_COMPONENT_MISSING in HOST: 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.xmlnsDecl(BaseXMLWriter.java:339)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFHeader(Basic.java:64)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeBody(Basic.java:47)
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 mypackage.TestRdfXmlOnBlankNodes.main(TestRdfXmlOnBlankNodes.java:47)
package mypackage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.RDFReader;
import com.hp.hpl.jena.rdf.model.RDFWriter;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
public class TestRdfXmlOnBlankNodes {
public static void main(String... args) throws IOException {
Model m = ModelFactory.createDefaultModel();
RDFReader arp = m.getReader("N-TRIPLES");
// File contents = "_:b0 <http://p> <http://o> ."
URL someTriples = Thread.currentThread().getContextClassLoader()
.getResource("mypackage/tripleWithBNodeAsSubject.nt");
if (someTriples == null) {
System.err.println("file not found");
System.exit(1);
}
System.out.println("=== FILE CONTENTS ===");
InputStream in = someTriples.openStream();
System.out.println(convertStreamToString(in));
in = someTriples.openStream();
arp.read(m, in, null);
in.close();
System.out.println("=== MODEL CONTENTS ===");
printAll(m);
RDFWriter writer = m.getWriter("RDF/XML");
writer.write(m, System.out, null);
}
private static void printAll(Model model) {
StmtIterator iter = model.listStatements();
try {
while (iter.hasNext()) {
Statement stmt = iter.next();
Resource s = stmt.getSubject();
Resource p = stmt.getPredicate();
RDFNode o = stmt.getObject();
if (s.isURIResource()) {
System.out.print("URI");
} else if (s.isAnon()) {
System.out.print("blank");
}
if (p.isURIResource())
System.out.print(" URI ");
if (o.isURIResource()) {
System.out.print("URI");
} else if (o.isAnon()) {
System.out.print("blank");
} else if (o.isLiteral()) {
System.out.print("literal");
}
System.out.println();
}
} finally {
if (iter != null)
iter.close();
}
}
private static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
}
@harschware
Copy link
Author

The above code illustrates what I think may be a bug in Jena 2.11.0 for the RDF/XML serializer

@harschware
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment