gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:26:25 32 4
gpt4 key购买 nike

我正在尝试将我的 RDF 三元组转换为 RDF 四元组(添加上下文),这是我的三元组的图片(输入): 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

我认为空格或反斜杠 \ 中存在错误。那么我该如何解决这个问题呢?

最佳答案

\n在 IRI 中是非法的。

通过更改 IRI 来修复数据

也许可以替换\n通过%0A (注意:数据 URI 中确实会有 % - 0 - A - 这不是转义机制)。

或者将 IRI 修复为应有的值。使用合法字符作为分隔符或删除 \n .

关于java - 非法 unicode 转义序列值 :\n (0x6E),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39799976/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com