Mohamed Gharibi Mohamed Gharibi - 2 months ago 8
Apache Configuration Question

Illegal unicode escape sequence value: \n (0x6E)

I am trying to convert my RDFs triples to RDFs quads (adding the context), Here is a picture of my triples (input):
enter image description here

This is my code

public static void main(String[] args) {
try {

Model model = RDFDataMgr.loadModel("/Users/mohamedghribi/Downloads/Thesis/csv2rdf-master/csv2rdf-master/examples/cars/last.nt");
DatasetGraph dsg = new DatasetGraphSimpleMem(); // very simple implementation
StmtIterator iter = model.listStatements();
PrintStream out = new PrintStream(new FileOutputStream("output.nq"));
System.setOut(out);

//Iterate through each triple and add context and add the quad to the datasetgraph which is written
//in N-Quads format
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
Resource subject = stmt.getSubject(); // get the subject
Property predicate = stmt.getPredicate(); // get the predicate
Literal object = (Literal)stmt.getObject();// get the object

Quad quad = new Quad(NodeFactory.createURI("/Users/mohamedghribi/Downloads/Thesis/csv2rdf-master/csv2rdf-master/examples/cars/Med2.csv"),
NodeFactory.createURI(subject.toString()),
NodeFactory.createURI(predicate.toString()),
NodeFactory.createLiteralByValue(object.getValue(),object.getDatatype())
);

dsg.add(quad);

}
RDFDataMgr.write(System.out, dsg, RDFFormat.NQUADS); // or NQUADS
}catch (Exception e)
{
e.printStackTrace();
}
}


But I am getting this error:

log4j:WARN No appenders could be found for logger (org.apache.jena.riot.system.stream.JenaIOEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.apache.jena.riot.RiotException: [line: 1, col: 62] Illegal unicode escape sequence value: \n (0x6E)
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
at org.apache.jena.riot.lang.LangEngine.raiseException(LangEngine.java:165)
at org.apache.jena.riot.lang.LangEngine.<init>(LangEngine.java:47)
at org.apache.jena.riot.lang.LangBase.<init>(LangBase.java:32)
at org.apache.jena.riot.lang.LangNTuple.<init>(LangNTuple.java:60)
at org.apache.jena.riot.lang.LangNTriples.<init>(LangNTriples.java:46)
at org.apache.jena.riot.RiotReader.createParserNTriples(RiotReader.java:416)
at org.apache.jena.riot.RiotReader.createParser(RiotReader.java:174)
at org.apache.jena.riot.RiotReader.createParser(RiotReader.java:140)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:170)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:905)
at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:686)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:209)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:102)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:93)
at org.apache.jena.riot.RDFDataMgr.loadModel(RDFDataMgr.java:327)
at Triple2Quad.main(Triple2Quad.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 0


I think the error in the spaces or the backslash
\
. So how can i solve that ?

Answer

\n is illegal in an IRI.

Fix the data by changing the IRIs

Maybe replace \n by %0A (note: there will really be %-0-A in the data URI- this is not an escape mechanism).

Or fix the IRI to what it is supposed to be. Use a legal character as a separator or delete the \n.