2017-09-01 4 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/XML構文であなたのRDFの文書を読むことはありません - あなたはすでに認識されているように、これは本当に読める人間と機械のための交換フォーマットとして設計されていません。 RDFデータセットにはトリプルのセットが含まれています。これらのトリプルを表示するのに適した形式はNトリプルまたはタートルです。

私は(私は接頭辞ベースURIとしてcimhttp://example.org/dataのnamspaceするhttp://example.org/を仮定)N-トリプルにデータを変換:

<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.ConductingEquipment要素私に与える

Terminalを考える:私は(私はデータのドメインに慣れていない)、それを翻訳してみましたか?

  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); 

は、私は接頭辞cimの名前空間としてRDF/XMLドキュメントとhttp://example.org/のベースURIとしてhttp://example.org/dataを想定していること、忘れないでください。

関連する問題