2012-03-16 34 views
1

私はjena 2.6.4を使用していますが、名前空間で奇妙な動作が発生しました。奇妙な名前空間宣言

public static void main(String[] args) { 
    String myUri = "http://www.example.com/1.0/myUri#"; 
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); 

    model.setNsPrefix("myuri", myUri); 

    OntClass c616 = model.createClass(myUri + "616"); 
    OntClass c123 = model.createClass(myUri + "123"); 

    Individual a = c616.createIndividual(myUri + "a"); 
    a.addOntClass(c123); 

    model.write(System.out); 
} 

出力は次のとおりです:私は、次のコードを使用してい

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:j.0="http://www.example.com/1.0/myUri#616" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:j.1="http://www.example.com/1.0/myUri#123" 
    xmlns:myuri="http://www.example.com/1.0/myUri#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" > 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#123"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> 
    </rdf:Description> 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#a"> 
    <rdf:type rdf:resource="http://www.example.com/1.0/myUri#123"/> 
    <rdf:type rdf:resource="http://www.example.com/1.0/myUri#616"/> 
    </rdf:Description> 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#616"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> 
    </rdf:Description> 
</rdf:RDF> 
次の名前空間が宣言されている理由を私は理解していない

xmlns:j.0="http://www.example.com/1.0/myUri#616" 
xmlns:j.1="http://www.example.com/1.0/myUri#123" 

不思議なことに、私が変更した場合は、シリアル化をTURTLE(model.write(System.out, "TURTLE");)にすると、次の出力が得られます。

@prefix myuri: <http://www.example.com/1.0/myUri#> . 
@prefix owl:  <http://www.w3.org/2002/07/owl#> . 
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> . 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 

<http://www.example.com/1.0/myUri#123> 
     a  owl:Class . 

myuri:a 
     a  <http://www.example.com/1.0/myUri#123> , <http://www.example.com/1.0/myUri#616> . 

<http://www.example.com/1.0/myUri#616> 
     a  owl:Class . 

ここで、名前空間の宣言は私が期待したとおりです。

public static void main(String[] args) { 
    String myUri = "http://www.example.com/1.0/myUri#"; 
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); 

    model.setNsPrefix("myuri", myUri); 

    OntClass c616 = model.createClass(myUri + "c616"); 
    OntClass c123 = model.createClass(myUri + "c123"); 

    Individual a = c616.createIndividual(myUri + "a"); 
    a.addOntClass(c123); 

    model.write(System.out); 
} 

出力:

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:myuri="http://www.example.com/1.0/myUri#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" > 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#c123"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> 
    </rdf:Description> 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#a"> 
    <rdf:type rdf:resource="http://www.example.com/1.0/myUri#c123"/> 
    <rdf:type rdf:resource="http://www.example.com/1.0/myUri#c616"/> 
    </rdf:Description> 
    <rdf:Description rdf:about="http://www.example.com/1.0/myUri#c616"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> 
    </rdf:Description> 
</rdf:RDF> 

とTURTLE形式で:

@prefix myuri: <http://www.example.com/1.0/myUri#> . 
@prefix owl:  <http://www.w3.org/2002/07/owl#> . 
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> . 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 

myuri:c123 
     a  owl:Class . 

myuri:a 
     a  myuri:c123 , myuri:c616 . 

myuri:c616 
     a  owl:Class . 
OntClass 616から c616へと 123 c123に名前を変更するとき

は私も異なる動作を気づきました

何か間違っているのですか?誰かがこの奇妙な行動を説明できますか? ありがとう!

答えて

2

2つの接頭辞は使用されず、RDFグラフの「性質」には影響しません。数字で始めることはできません いわゆる 'ローカル名'、次を参照してください。

あなたの最初の例では2つのプレフィックス(j.0とJ.1)ではありません実際に使用されている、彼らはなぜあなたにそんなに関心があるのです

+0

私はlocalnamesが数字で始めることができなかったことを知らなかった:リンクありがとう!私の関心事は、(i)なぜこのような名前空間が使用されていない場合にjenaによって追加されるのか、(ii)RDF/XMLのシリアル化でのみ出現する理由に関連しています。とにかく、離陸の教訓は、数字で始まるローカル名を使うべきではないということです。 – MarcoS

関連する問題