简体   繁体   English

检索空白节点映射

[英]Retrieving blank node mapping

My group is currently developing a point and click interface for navigating and extracting information from RDF graphs. 我的小组目前正在开发一个点击界面,用于从RDF图表中导航和提取信息。 As a part of this we are connecting to various triple store endpoints using Jena's sparqlservice method. 作为其中的一部分,我们使用Jena的sparqlservice方法连接到各种三重存储端点。 In order to move the point at which the user is currently looking, the user can select a node and make it the center. 为了移动用户当前正在查看的点,用户可以选择节点并使其成为中心。 The program then fetches the neighbors of that node using the expression seen below: 然后程序使用下面的表达式获取该节点的邻居:

CONSTRUCT {
<URI> ?p ?o .
?s ?p <URI> .
} WHERE {
{<URI> ?p ?o .}
UNION
{?s ?p <URI> .}
} LIMIT N

Where URI is the node the user has selected(We do something slightly different for literals). 其中URI是用户选择的节点(我们对文字做了稍微不同的事情)。 This expression is then executed as follows: 然后按如下方式执行此表达式:

Query myQuery = QueryFactory.create(_query);
QueryExecution qexe = QueryExecutionFactory.sparqlService(this.myURL, myQuery);
Model resultModel = qexe.execConstruct();
return resultModel;

The issue we are facing is with regard to blank nodes. 我们面临的问题是关于空白节点。 When Jena gets a blank node from an endpoint, it is immediately assigned a Jena bNode ID. 当Jena从端点获取空白节点时,会立即为其分配Jena bNode ID。 This ID will not be the same as the one presented by the endpoint, and if a user selects a blank node on the client side as the new center, this obviously causes issues. 此ID与端点提供的ID不同,如果用户选择客户端的空白节点作为新中心,这显然会导致问题。

My question is therefore: Is there some way to retain the original endpoint-ID within Jena? 因此,我的问题是:有没有办法在Jena中保留原始端点ID? From browsing through the belly of Jena, I can see that several of the ResultSet classes use a class to handle the mapping between endpoint- and Jena ID's, called LabelToNodeMap . 通过浏览Jena的腹部,我可以看到几个ResultSet类使用一个类来处理endpoint-和Jena ID之间的映射,称为LabelToNodeMap Is there some way to retrieve this mapping? 有没有办法检索这个映射? Or alternatively, prevent Jena from using its own ID schema, and instead use the endpoints. 或者,防止Jena使用自己的ID模式,而是使用端点。

Essentially no you can't identify a blank node directly when talking to a remote SPARQL service. 基本上没有你在与远程SPARQL服务交谈时无法直接识别空白节点。

For a start the various SPARQL results specifications actually don't mandate that stores send their internal IDs as blank node IDs. 首先,各种SPARQL结果规范实际上并未要求存储将其内部ID作为空白节点ID发送。 For example the SPARQL Results XML specification has this to say: 例如, SPARQL结果XML规范有这样的说法:

Note: The blank node label I is scoped to the result set XML document and need not have any association to the blank node label for that RDF Term in the query graph. 注意:空白节点标签I的范围限定为结果集XML文档,不需要与查询图中该RDF术语的空白节点标签有任何关联。

And even with CONSTRUCT queries the situation is similar, almost all RDF formats say that a blank node label is only scoped to the document. 即使使用CONSTRUCT查询情况类似,几乎所有RDF格式都表示空白节点标签仅限于文档范围。 So if I have _:id and _:id in two separate requests semantically speaking I have two different blank nodes. 因此,如果我在两个单独的请求中有_:id_:id ,从语义上讲,我有两个不同的空白节点。

Regardless of the format you also have the issue that some syntaxes are quite restrictive in what characters can appear in a blank node label so even if a store does use its internal identifiers (which is rare) it will often have to escape/encode them in some way to be valid syntax. 无论格式如何,您还会遇到一些问题,即某些语法在空白节点标签中出现的字符非常严格,因此即使商店确实使用其内部标识符(这种情况很少见),它通常也必须转义/编码它们。某种方式是有效的语法。 This then requires you to be aware of each endpoints escaping/encoding scheme (if it exposes identifiers at all) and how to translate it into an actual ID. 然后,这需要您了解每个端点转义/编码方案(如果它完全公开标识符)以及如何将其转换为实际ID。

Bottom line is that the endpoint isn't giving you its internal identifiers anyway so making Jena preserve them (which strictly speaking is possible though not an easy extension point) wouldn't really help you. 底线是终端没有给你内部标识符,所以让Jena保留它们(严格说来虽然不是一个简单的扩展点)但是不会真正帮助你。

Even if you can preserve them you can't send them back to the remote endpoint since blank nodes in a query are anonymous variables not identifiers. 即使您可以保留它们,也无法将它们发送回远程端点,因为查询中的空白节点是匿名变量而不是标识符。 Some stores will accept the non-standard syntax <_:id> to refer to a blank node but many will not and you are going beyond the SPARQL specification so your application loses portability. 有些商店会接受非标准语法<_:id>来引用一个空白节点,但很多商店都不会这样做,而且您将超越SPARQL规范,因此您的应用程序将失去可移植性。

Workaround 解决方法

The workaround is to simply extend your previous query, your question implies that the user only sees this blank node because of a previous query. 解决方法是简单地扩展您之前的查询,您的问题意味着用户仅因为先前的查询而看到此空白节点。 Since you can only identify blank nodes by association you can modify your previous query to ask for additional details about the blank node. 由于您只能通过关联识别空白节点,因此您可以修改以前的查询以询问有关空白节点的其他详细信息。

It may be that this will return details about multiple nodes and you have to do some client side processing to figure out which node the user actually wanted and how to associate the additional data with your existing visualisation but that is all doable. 这可能会返回有关多个节点的详细信息,您必须进行一些客户端处理,以确定用户实际需要的节点以及如何将其他数据与现有可视化相关联,但这一切都是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM