作者:阜阳king | 来源:互联网 | 2023-01-31 14:14
我将使用Apache Jena并将RDF作为输入格式.但我有CSV格式的数据.我研究了很多,找不到转换它的方法.有谁知道如何有效地做到这一点.
我已经通过像xml123这样的工具,但下载链接无法正常工作.
1> ssz..:
使用jena-arq和jena-csv(均为v3.0.1),以下方式对我有用:
public static void main(String ... strings) throws Exception {
CSV2RDF.init();
//load through manager:
//Model m = RDFDataMgr.loadModel("test.csv") ;
//classic way to load:
Model m = ModelFactory.createDefaultModel();
try (InputStream in = JenaCSVTest.class.getResourceAsStream("/test.csv")) {
m.read(in, "http://example.com", "csv");
}
m.setNsPrefix("test", "http://example.com#");
m.write(System.out, "ttl");
}
输入(test.csv):
Town,Population
Southton,123000
Northville,654000
输出(乌龟中的rdf):
@prefix test: .
[ test:Population "123000"^^ ;
test:Town "Southton" ;
1
] .
[ test:Population "654000"^^ ;
test:Town "Northville" ;
2
] .
见官方文档jena-csv