2012-03-16 7 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에서 c616123 c123에 이름을 변경할 때

나는 또한 내가 다른 동작을 발견했습니다

내가 잘못하고 있니? 누군가이 이상한 행동을 설명 할 수 있습니까? 감사합니다.

답변

2

두 접두어는 사용되지 않으며 RDF 그래프의 '특성'에 영향을주지 않습니다. 숫자로 시작할 수 없습니다 소위 'localnames'을 참조하십시오

첫 번째 예에서 두 개의 접두사 (j.0 및 J.1)되지 않습니다 실제로 사용되었는데, 왜 그들이 당신을 그렇게 많이 염려 하는가?

+0

나는 localnames가 숫자로 시작할 수 없다는 것을 몰랐다. 링크에 감사드립니다! 내 관심사는 (i) 사용되지 않는 jena가 왜 이러한 네임 스페이스를 추가했는지 이해하고, (ii) RDF/XML 직렬화에서만 나타나는 이유와 관련이 있습니다. 어쨌든, 필자의 필독 교훈은 숫자로 시작하는 localnames를 사용하면 안된다는 것입니다. :) – MarcoS

관련 문제