问题描述
我已经在Java Apache Jena上测试了linkedmdb-18-05-2009-dump.nt,但是在dotNetRDF上抛出异常为
VDS.RDF.Parsing.RdfParseException
HResult=0x80131500
Message=Invalid URI encountered,see inner exception for details
Source=dotNetRDF
StackTrace:
at VDS.RDF.Parsing.NTriplesParser.TryParseUri(TokenisingParserContext context,String uri)
at VDS.RDF.Parsing.NTriplesParser.TryParseTriple(TokenisingParserContext context)
at VDS.RDF.Parsing.NTriplesParser.Parse(TokenisingParserContext context)
at VDS.RDF.Parsing.NTriplesParser.Load(IRdfHandler handler,TextReader input)
at ConsoleApp2_RDFWALKTHROUGH.Program.Main(String[] args) in
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
UriFormatException: Invalid URI: The hostname Could not be parsed.
我的c#代码如下:
String inputFile = "D:/linkedmdb-18-05-2009-dump.nt";
IGraph g = new Graph();
NTriplesParser parser = new NTriplesParser(NTriplesSyntax.Original);
Console.WriteLine("RDF DS-1 Loading Started:");
parser.Load(g,new StreamReader(inputFile));
Console.WriteLine("RDF DS-1 Loading Finished:");
Console.WriteLine(new DateTime(loadingTime).ToShortTimeString());
Console.ReadLine();
请指导我我错了,因为在Java上可以使用同一文件但在dotNetRDF上不能解析该文件非常令人困惑。
解决方法
问题在于转储包含无效的IRI。我从https://www.cs.toronto.edu/~oktie/linkedmdb/下载的转储中的第3104575行有以下内容:
<http://data.linkedmdb.org/film/9995> <http://xmlns.com/foaf/0.1/page> <http://?> .
该行上的最后一个IRI是导致解析器阻塞的内容,因为?
在IRI中的那个位置不是有效字符。