【发布时间】:2020-02-22 17:19:02
【问题描述】:
我想问一下Java中是否有一种方法可以读取,基本上是任何文件格式(N3、JSON、RDF-XML)等,然后将其转换为turtle(.ttl)。我在谷歌上搜索了一些想法,但它们主要只是解释特定的文件类型以及如何将文件类型转换为 RDF,而我想要它以另一种方式。
编辑(按照答案中给出的代码示例):
if(FilePath.getText().equals("")){
FilePath.setText("Cannot be empty");
}else{
try {
// get the inputFile from file chooser and setting a text field with
// the path (FilePath is the variable name fo the textField in which the
// path to the selected file from file chooser is done earlier)
FileInputStream fis = new FileInputStream(FilePath.getText());
// guess the format of the input file (default set to RDF/XML)
// when clicking on the error I get take to this line.
RDFFormat inputFormat = Rio.getParserFormatForFileName(fis.toString()).orElse(RDFFormat.RDFXML);
//create a parser for the input file and a writer for Turtle
RDFParser rdfParser = Rio.createParser(inputFormat);
RDFWriter rdfWriter = Rio.createWriter(RDFFormat.TURTLE,
new FileOutputStream("./" + fileName + ".ttl"));
//link parser to the writer
rdfParser.setRDFHandler(rdfWriter);
//start the conversion
InputStream inputStream = fis;
rdfParser.parse(inputStream, fis.toString());
//exception handling
} catch (FileNotFoundException ex) {
Logger.getLogger(FileConverter.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(FileConverter.class.getName()).log(Level.SEVERE, null, ex);
}
}
我已将“eclipse-rdf4j-3.0.3-onejar.jar”添加到 NetBeans 的 Libraries 文件夹中,现在当我运行该程序时,我不断收到此错误:
线程“AWT-EventQueue-0”中的异常 java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 在 org.eclipse.rdf4j.common.lang.service.ServiceRegistry.(ServiceRegistry.java:31)
任何帮助或建议将不胜感激。谢谢。
【问题讨论】:
标签: java file rdf converters turtle-rdf