本文介绍了耶拿从乌龟读失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚导入了jena库以使其能够在rdf-s上运行,这是我的第一次尝试,但是我无法读取乌龟(.ttl)文件.

I have just imported jena libraries to eclipse to work on rdf-s and it is my first try, but I cannot read a turtle (.ttl) file.

我以以下方式尝试过:

import java.io.*;
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;

public class Simpsons {

public static void main(String[] args) throws IOException {
    Model model=ModelFactory.createDefaultModel();
    model.read(new FileInputStream("simpsons.ttl"),null);

}

}

我得到的错误如下:

Exception in thread "main" org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not allowed in prolog.
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
at org.apache.jena.riot.lang.LangRDFXML$ErrorHandlerBridge.fatalError(LangRDFXML.java:252)
at com.hp.hpl.jena.rdf.arp.impl.ARPSaxErrorHandler.fatalError(ARPSaxErrorHandler.java:48)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:209)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.fatalError(XMLHandler.java:239)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:151)
at com.hp.hpl.jena.rdf.arp.ARP.load(ARP.java:119)
at org.apache.jena.riot.lang.LangRDFXML.parse(LangRDFXML.java:142)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTFactoryImpl$1.read(RDFParserRegistry.java:142)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:859)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:255)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:241)
at org.apache.jena.riot.adapters.RDFReaderRIOT_Web.read(RDFReaderRIOT_Web.java:62)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:253)
at assignment2.Simpsons.main(Simpsons.java:11)

请帮助我提供一些想法,因为我不知道问题是什么,因为这是我第一次尝试使用耶拿.我还从某处得到暗示,我应该执行以下操作:

Please help me with some ideas because I have no clue what the problem would be as it's my very first try with Jena. I also got a hint from somewhere that I should do the following: :

但是我不太了解如何编写该方法.

but I don't really understand how should I write that method.

推荐答案

您正在使用的读取方法假定输入格式为RDF/XML.

您需要使用其他读取方法.

应该是:

public static void main(String[] args) throws IOException {
    Model model=ModelFactory.createDefaultModel();
    model.read(new FileInputStream("simpsons.ttl"),null,"TTL");
}

这篇关于耶拿从乌龟读失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 03:37