繁体   English   中英

rdf4j的rdf:id过滤器模型

[英]rdf4j filter model by rdf:id

在rdf4j中是否可以通过rdf:id过滤模型? 我已经尝试了以下方法:

model.filter(res, null, null)

但是rdf:resource ,我也得到了所有rdf:resourcerdf:about 目前,我首先针对所需类型的所有出现情况(返回模型)过滤整个模型。 然后,我为资源过滤此模型,并使用此资源为所需的模型部分过滤整个模型:

Model typeModel = model.filter(null, RDF.TYPE, iri);
// the following obj contains only the id (found in an rdf:about or rdf:resource)
// normally I also do some checks before .iterator().next()
Resource res = typeModel.filter((Resource) obj, null, null).subjects().iterator().next();
Model resModel = model.filter(res, null, null);

我认为我的解决方案会产生过多的开销,因为我还需要为每个Type typeModel一个typeModel 还有另一种方法可以过滤rdf:id的模型吗?

更新:

这是一个简短的示例:我需要在Terminal.ConductingEquipmentrdf:resource的帮助下找到ACLineSegment

<cim:Terminal rdf:ID="_8fd6a918-5a8d-42f2-ae19-3ee77bc76911">
  <cim:ACDCTerminal.sequenceNumber>2</cim:ACDCTerminal.sequenceNumber>
  <cim:IdentifiedObject.name>XXXX</cim:IdentifiedObject.name>
  <cim:Terminal.ConductingEquipment rdf:resource="#_50c99578-6e17-45e1-a113-a4a28d643b40" />
  <cim:Terminal.ConnectivityNode rdf:resource="#_eefd8021-6f56-4154-9b2b-9e275c0f43d0" />
  <cim:Terminal.phases rdf:resource="http://iec.ch/TC57/2013/CIM-schema-cim16#PhaseCode.ABC" />
</cim:Terminal>
<cim:ACLineSegment rdf:ID="_50c99578-6e17-45e1-a113-a4a28d643b40">
  <cim:ACLineSegment.b0ch>5.44828e-5</cim:ACLineSegment.b0ch>
  <cim:ACLineSegment.bch>5.44828e-5</cim:ACLineSegment.bch>
  ....
</cim:ACLineSegment>

您永远不应该以RDF / XML语法阅读RDF文档-正如您已经认识到的那样,这不是真正的人类可读性,并且被设计为机器的交换格式。 RDF数据集包含一组三元组,N-Triples或Turtle是查看这些三元组的一种很好的格式。

我将您的数据转换为N-Triples(我假设http://example.org/是前缀cim的命名空间,而http://example.org/data是基本URI):

<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Terminal> .
<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://example.org/ACDCTerminal.sequenceNumber> "2" .
<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://example.org/IdentifiedObject.name> "XXXX" .
<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://example.org/Terminal.ConductingEquipment> <http://example.org/data#_50c99578-6e17-45e1-a113-a4a28d643b40> .
<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://example.org/Terminal.ConnectivityNode> <http://example.org/data#_eefd8021-6f56-4154-9b2b-9e275c0f43d0> .
<http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911> <http://example.org/Terminal.phases> <http://iec.ch/TC57/2013/CIM-schema-cim16#PhaseCode.ABC> .
<http://example.org/data#_50c99578-6e17-45e1-a113-a4a28d643b40> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ACLineSegment> .
<http://example.org/data#_50c99578-6e17-45e1-a113-a4a28d643b40> <http://example.org/ACLineSegment.b0ch> "5.44828e-5" .
<http://example.org/data#_50c99578-6e17-45e1-a113-a4a28d643b40> <http://example.org/ACLineSegment.bch> "5.44828e-5" .

您可以看到,实际上有9个RDF三元组。

你的任务是

Terminal.ConductingEquipmentrdf:resource的帮助下找到ACLineSegment

这种表述听起来是超级人为的,并不是人们在查询数据时会说的话。 我试图翻译它(我不习惯数据域):

给定Terminal ,给我它的Terminal.ConductingEquipment元素

那么到目前为止我们有什么呢?

  1. 我们有终端,即我们有http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911
  2. 我们也知道要为其获取对象的谓词,它是cim:ACLineSegment

这是什么意思? 我们拥有RDF三元组的主语和谓语,并希望获得其对象。 现在,您应该已经知道解决方案,只需按主题和谓词过滤模型,即

ValueFactory vf = SimpleValueFactory.getInstance();

// the subject which is the IRI of the terminal
IRI s = vf.createIRI("**http://example.org/data#_8fd6a918-5a8d-42f2-ae19-3ee77bc76911**");

// the predicate which is the IRI of the property cim:Terminal.ConductingEquipment
IRI p = vf.createIRI("http://example.org/Terminal.ConductingEquipment");

// filter by subject and predicate
Model filteredModel = model.filter(s, p, null);

// get the object, if one exists
Resource acLineSegment = Models.objectResource(filteredModel).orElse(null);

别忘了,我假设http://example.org/data作为RDF / XML文档的基本URI,而http://example.org/作为前缀cim的命名空间-您应该在代码中替换它以上具有适当的值。

暂无
暂无

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

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