耶拿(Jena):RDF/XML输出中只能包含格式正确的绝对URIref: [英] Jena: Only well-formed absolute URIrefs can be included in RDF/XML output: <A>

查看:183
本文介绍了耶拿(Jena):RDF/XML输出中只能包含格式正确的绝对URIref:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从构建RDF的csv文件进行解析器.现在,它只是将csv的标头及其值添加为属性. 当我尝试将输出编写为XML时,出现此错误:

I'm doing a parser from a csv file that builds an RDF. Right now it just adds as property the header of the csv and it's value. When I try to write the output as XML I get this error:

Caused by: org.apache.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <A> Code: 57/REQUIRED_COMPONENT_MISSING in SCHEME: A component that is required by the scheme is missing.

但是当我将其写为json时,会得到正确的输出.

But when I write it as json I get correct output.

有人知道我错了吗? 代码:

Does anyone know what I have wrong? code:

public List<Model> createRDF(File file) throws Exception { //TODO implement custom Exceptions
    Csv csv = CsvReader.convertFileToCsv(file);
    List<Model> modelList = new ArrayList<>();
    for(int i = 1; i < csv.lines.length; i++) {
        Model model = ModelFactory.createDefaultModel();
        Resource r = model.createResource( "http://provisionalUri.com/" + i);
        addProperties(r, csv, model, i);
        modelList.add(model);
    }


    return modelList;
}

private void addProperties(Resource r, Csv csv, Model model, int i) {
    for(int j = 0; j < csv.lines[i].length; j++) { // if the columns have different length this will cause problems
        Property property = model.createProperty(csv.headers[j]);
        Literal value = model.createLiteral(csv.lines[i][j]);
        model.add(r, property, value);
    }

}

写作:

List<Model> models = service.createRDF(new File("./src/test/java/resources/test/Bienes_declarados_Patrimonio_mundial_de_la_UNESCO_en_España.csv"));
        for(Model model: models){
            RDFDataMgr.write(System.out, model, Lang.RDFXML);
        }

推荐答案

与属性JSON-LD相比,RDF/XML对URI的要求更高,因为属性将被编写为XML qnames.

RDF/XML has more requirements on URIs than JSON-LD because properties will be written as XML qnames.

model.createProperty(csv.headers[j]);不是合法的绝对URI.

model.createProperty(csv.headers[j]); isn't a legal absolute URI unless you took care with the CSV headers.

需要两件事:

  1. 如果它具有对URI不利的字符,则需要对"csv.headers [j]"进行编码.
  2. 需要适当的URI,例如在前面添加" http://HOST/":

model.createProperty("http://example/"+encode(csv.headers[j]));

这篇关于耶拿(Jena):RDF/XML输出中只能包含格式正确的绝对URIref:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆