2017-09-01 99 views
0

是否有可能在rdf4j过滤模型的rdf:id?我已经尝试以下方法:rdf4j过滤器模型的rdf:id

model.filter(res, null, null) 

但有了这个,我也得到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); 

我觉得我的解决方案创造了太多的开销,因为我还需要为每一个typeModel类型。是否有另一种方法来过滤rdf:id的模型?

UPDATE:

下面是一个简单的例子:我需要与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> 
+1

'rdf:id'不是RDF数据模型的一部分,而是RDF/XML序列化的一部分。你想过滤RDF三元组的主题,对吗?或者总体目标是什么? – AKSW

+0

也许提供一些样本数据,你期望得到什么,以及你目前得到什么也是很好的。 – AKSW

+0

我更新了这个问题,我希望现在更清楚。 –

回答

2

你不应该读你的RDF文档中的RDF/XML语法 - 因为你已经认识到,这是不是真的人类可读和设计为机器交换格式。 RDF数据集包含一组三元组,这是一种很好的格式,可以查看这些三元组是N元组还是乌龟。

我转换数据到N-三同(I假定http://example.org/是前缀cim的namspace和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.ConductingEquipment

这一提法听起来超级人造,而不是查询数据时,人会说什么rdf: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文档和http://example.org/为前缀cim的命名空间的基础URI - 你应该在代码替换这上面有正确的价值观。