Apache Jena Getting "ERROR riot" processing element

jena, rdf

Solution

The problem is that that data isn't RDF/XML (or even XML)

The big problem with the input is that it's not legal RDF/XML, or even legal XML. There a number of lines that contain ill-formed strings, e.g.,

$ grep '""' rdf.rdf
<j.0:target rdf:resource="urn:evitakarina""/>
<j.0:target rdf:resource="urn:MiaWaluyo""/>
<j.0:target rdf:resource="urn:AnggaMOB""/>
…

There are also some problems with entities, or rather, places where ampersands appear that aren't entities. E.g.:

$ grep "&" rdf-without-quotes.rdf 
<j.0:target rdf:resource="urn:HERUWA--&gty"/>
<j.0:target rdf:resource="urn:PiniiPin&andreasbimoo"/>

If you replace each of those with `&amp;`, you'll get a bit farther (although maybe that `&gt` was supposed to be `>`?), but there are still problems. You might, after that, track down:

<j.0:target rdf:resource="urn:cordeliabuvaledesilvaa"jajajajajajajajaja"/>

Unfortunately, I don't know of a way of getting better debugging information about the line numbers. Since this (not quite) RDF/XML document was so regularly structured, it wasn't too hard to cut it in half a few times to narrow down the problem, and from the experience that these sorts of things often arise from some bad character where it shouldn't be, that's what I was looking for (and found).

Generating better data

If you have any control over the data (e.g., if you're generating it), I'd strongly suggest that you consider generating the data using an RDF API (e.g., Jena) to generate the RDF data from whatever the original input data is, rather than mashing it into some text based templates. That will probably give you the nicest output. Otherwise, you'll just need to be much more careful about URL-encoding things that have to be URLs. Most languages include some standard library functionality for handling that.

This isn't too hard to do using Jena. I'd suggest trying to reconstruct a minimal model that includes data that has been problematic. Here's a small sample taken from your data (but it's a complete RDF/XML document (or would be, if it weren't for the problems discussed above)):

<?xml version="1.0" encoding="iso-8859-1" ?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:j.0="urn:" >
<rdf:Description rdf:about="urn:communication243">
    <j.0:hour rdf:datatype="http://www.w3.org/2001/XMLSchema#long">20120219</j.0:hour>
    <j.0:minute rdf:datatype="http://www.w3.org/2001/XMLSchema#long">2012021910</j.0:minute>
    <j.0:source rdf:resource="urn:wirojericko"/>
    <j.0:target rdf:resource="urn:evitakarina""/>
</rdf:Description>
<rdf:Description rdf:about="urn:communication4574">
    <j.0:hour rdf:datatype="http://www.w3.org/2001/XMLSchema#long">20120304</j.0:hour>
    <j.0:minute rdf:datatype="http://www.w3.org/2001/XMLSchema#long">2012030406</j.0:minute>
    <j.0:source rdf:resource="urn:renomaximuz"/>
    <j.0:target rdf:resource="urn:HERUWA--&gty"/>
</rdf:Description>
</rdf:RDF>

We can recreate this using Jena with the following code. I've stored the values in an `Object[][]` array so that we can even simulate iterating over the original input data.

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class RecreateRDFExample {
    public static void main(String[] args) {
        final String NS = "urn:";
        final Model model = ModelFactory.createDefaultModel();
        final Object[][] data = {
                { 243, 20120219L, 2012021910L, "wirojericko", "evitakarina\"" }, 
                { 4574, 20120304L, 2012030406L, "renomaximuz", "HERUWA--&gty" }
        };

        final Property hour = model.createProperty( NS+"hour" );
        final Property minute = model.createProperty( NS+"minute" );
        final Property source = model.createProperty( NS+"source" );
        final Property target = model.createProperty( NS+"target" );

        for ( Object[] communication : data ) { 
            final Resource com = model.createResource( NS + "communication" + communication[0] );
            com.addLiteral( hour, (long) communication[1] ); 
            com.addLiteral( minute, (long) communication[2] ); 
            com.addProperty( source, model.createResource( NS+communication[3] ));
            com.addProperty( target, model.createResource( NS+communication[4] ));
        }

        model.write( System.out );
    }
}

The output is is exactly what we'd hope for; the IRIs have been appropriately encoded with `&quot;` and `&amp;`.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="urn:" > 
  <rdf:Description rdf:about="urn:communication243">
    <j.0:target rdf:resource="urn:evitakarina&quot;"/>
    <j.0:source rdf:resource="urn:wirojericko"/>
    <j.0:minute rdf:datatype="http://www.w3.org/2001/XMLSchema#long">2012021910</j.0:minute>
    <j.0:hour rdf:datatype="http://www.w3.org/2001/XMLSchema#long">20120219</j.0:hour>
  </rdf:Description>
  <rdf:Description rdf:about="urn:communication4574">
    <j.0:target rdf:resource="urn:HERUWA--&amp;gty"/>
    <j.0:source rdf:resource="urn:renomaximuz"/>
    <j.0:minute rdf:datatype="http://www.w3.org/2001/XMLSchema#long">2012030406</j.0:minute>
    <j.0:hour rdf:datatype="http://www.w3.org/2001/XMLSchema#long">20120304</j.0:hour>
  </rdf:Description>
</rdf:RDF>

Problem

I have an RDF file here:rdf.rdf that has 35696 records in it. I'm trying to process it with Jena using: ``` ./bin/sparql --data=/tmp/rdf.rdf --query=./basic.query ``` but I'm getting: ``` 21:25:27 ERROR riot :: Element type "j.0:target" must be followed by either attribute specifications, ">" or "/>". Failed to load data ``` I believe the issue is a specific record but I don't know which one, does anyone have a way to check this or a command to produce a line number for the problem?

Original source