非法的unicode转义序列值:\ n(0x6E)

时间:2016-09-30 20:57:04

标签: java regex apache unicode jena

我正在尝试将我的RDF三元组转换为RDFs四边形(添加上下文),这是我的三元组图片(输入): enter image description here

这是我的代码

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();
    }
}

但是我收到了这个错误:

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

我认为空格中的错误或反斜杠\。那么我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

\n在IRI中是非法的。

通过更改IRI来修复数据

也许可以\n替换%0A(注意:数据URI中确实会有% - 0 - A - 这不是逃避机构)。

或者将IRI修复到预期的状态。使用合法字符作为分隔符或删除\n