Question

I am programming in Java, trying to make a simple RDF Store using Jena library and lastfm.rdfize.com website.

I'm getting into the following problem: the lastfm.rdfize.com produces an rdf, for example in Turtle on the request like: "http://lastfm.rdfize.com/?username=&eventID=&artistName="+artistName+"&venueID=&output=turtle"

I make a request and take the contents of the resulting web page. If I print them - they seem like a decent RDF to me.

However, I can't add them to the model.

I tried creating a file, writing the String(which is the HTML content) to this file(which also seems okay) and reading it to the model like that:

InputStream lastf = FileManager.get().open("lastfm.txt");
Model temp=null;
temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
temp.read(lastf,null,"Turtle");

However, at this point I get the following error message:

(ErrorHandlerLib.java:49) - [line: 22, col: 2 ] Unknown char:

Was it helpful?

Solution

Your code does work for me with a trivial RDF/Turtle like ...

@base <http://example.org/ns/> .                                                                                                                     
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<s1> <p1> <o1>;
<p2> "some typed literal"^^xsd:string;
<p2> "some non-typed literal";
<p4> 10 .
<o1> <label> "some label" .

It seems therefore that you have some format or charset error in your data file lastfm.txt. I suggest to validate your file with an RDF validator, try with http://www.rdfabout.com/demo/validator/ With this validator you can test both RDF/XML and RDF/Turtle make sure you select the correct format for the type of RDF serialization you are working with.

Another option to validate your data could be the raptor tool from http://librdf.org but this one is a bit more sophisticated and you need to install it locally.

If the validators shouts with a charset error then you could change the charset you are using to read your data. Something like this should work ..

package t1;                        
import java.io.*;
import com.hp.hpl.jena.util.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import java.nio.charset.*;

class test {
 public static void main (String[] args) { 
       InputStreamReader lastf = new 
          InputStreamReader(FileManager.get().open("lastfm.txt"),
                            Charset.forName("ISO-8859-1"));

       Model temp=null;
       temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
       temp.read(lastf,null,"Turtle");
       System.out.println(temp.size());
       temp.write(System.out);
    }
}

All this should give you a guideline to spot the error (I hope) but If you don't spot it then post the data so that we can have a look at it.

OTHER TIPS

Sounds like charset trouble. Is the file in uTF-8 or something else?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top