dotNetRdf与Unicode转义序列的问题/ Jena Fuseki无法在URI中加载撇号

问题描述 投票:1回答:1

我正在开发一个Web应用程序,我需要支持从几个数据源(DB转储/ URI)将RDF数据存储到我的Jena Fuseki服务器上。我遇到了dotNetRdf的问题。我使用的是作为NuGet包下载的最新版本(2.2.0)。我认为问题可能是由于在解析时遇到unicode转义序列的一些不幸。

起初,当我收到解析错误时,我试图从dotNetRdf的文档(部分:读取RDF数据,链接在下面)中作为一个例子。失败的代码如下:

IGraph g = new Graph();
g.LoadFromUri(new Uri("http://dbpedia.org/resource/Barack_Obama"));

这应该在功能上等同于文档中的代码示例(https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Reading-RDF#reading-rdf-from-uris),我只是使用扩展方法。

我收到一个带有消息的VDS.RDF.Parsing.RdfParseException:

[Line 2233 Column 42 to Line 2233 Column 83] 
Unexpected Token <b>'Integer'</b> encountered, expected a Property Value
describing one of the properties of an Object Node

给定DBpedia资源的第2233行应该如下:

"Barack Hussein Obama II (US /b\u0259\u02C8r\u0251\u02D0k hu\u02D0\u02C8se\u026An o\u028A\u02C8b\u0251\u02D0m\u0259/; born August 4, 1961) is an American politician who is the 44th and current President of the United States. He is the first African American to hold the office and the first president born outside the continental United States. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he was president of the Harvard Law Review. He was a community organizer in Chicago before earning his law degree. He worked as a civil rights attorney and taught constitutional law at the University of Chicago Law School between 1992 and 2004. While serving three terms representing the 13th District in the Illinois Senate from 1997 to 2004, he ran unsuccessfully in the Democratic primary for the United States Hou"@en ,

在列42和84之间有一些unicode转义序列,所以我想dotNetRdf没有正确解析它们?! (因为有关于意外整数的注释。)

我看过一些StackOverflow问题,讨论DBpedia无法提供正确的数据,但这些问题似乎有点过时,已经是2019年了。所以我认为DBpedia不是问题所在。我对使用RDF数据的经验很少,但这里的一切似乎都没问题。


其次,我尝试通过.NET的HttpClient下载内容,并指定一些Accept-Headers(在我的例子中为text / turtle),然后尝试通过调用IGraph.LoadFromString(...)方法将数据加载到IGraph实例中。没有帮助。同样的问题但不同的例外。

第三 - 我终于找到了解决方法!我已经将内容加载到字符串变量中(正如所说 - 通过HttpClient)然后我使用了VDS.RDF.Parsing.Notation3Parser类。这已经奏效了,但是......发生了另一个问题 - 当我试图将Graph保存到我的Jena Fuseki Triplestore时,我得到了一个带有内部异常的RdfStorageException(WebException:远程服务器返回400 Bad Request)。

异常消息:

A HTTP error (HTTP 400 Parse error: [line: 10, col: 50] 
The declaration for the entity "ns5" must end with '>'.) 
occurred while saving a Graph to the Store.
Empty response body, see aformentioned status line or the inner exception for further details

那么数据甚至可能无法正确解析?它甚至可能吗?

以下是简化的解决方法代码:

string content = /* get content via HttpClient */;

IGraph g = new Graph();
IRdfReader reader = new Notation3Parser();
reader.Load(g, new StringReader(content));

string connectionStr = "...";
var store = new PersistentTripleStore(new FusekiConnector(connectionStr));
...
store.UnderlyingStore.SaveGraph(g); // this call causes the mentioned RdfStorageException

我使用扩展方法将IGraph保存到文件中以查看IGraph中的内容(文件内容可用于此处:https://pastebin.com/nULJtjXu)并再次 - 当我查找导致问题的第10行时,有一个unicode转义序列:

@prefix ns5:    <http://dbpedia.org/resource/Buyer\u0027s_Remorse:> .

(注意:\ u0027是撇号('))

这很奇怪,因为在DBpedia返回的HTTP响应中,有许多unicode转义序列,并且解析在第一次出现时不会失败。

因此,我的Jena Fuseki可能更有可能在URI中使用撇号加载数据时出现问题?

任何有关我的问题的帮助将不胜感激

rdf jena dbpedia fuseki dotnetrdf
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.