2016-12-26 7 views
1

jenaライブラリが新しく、qualifiedCardinality制限のすべてのリソース、プロパティ、データ型をリストしたいと考えています。jenaのqualifiedCardinality制限のリソースをリスト表示

マイ制限:

... 
<rdfs:subClassOf> 
    <owl:Restriction> 
    <owl:onProperty   rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#sensingMethodUsed"/> 
    <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/> 
    <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality> 
    </owl:Restriction> 
</rdfs:subClassOf> 
<rdfs:subClassOf> 
    <owl:Restriction> 
    <owl:onProperty rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#featureOfInterest"/> 
    <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/> 
    <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:qualifiedCardinality> 
    </owl:Restriction> 
</rdfs:subClassOf> 
... 

目的の文字列出力:

qualcard sensingMethodUsed nonNegativeIteger 1 Sensing       
qualcard featureOfInterest nonNegativeIteger 1 FeatureOfInterest 

いくつかのいずれかが私を助けてくださいすることができますしてください。

答えて

0

スニペットはOWL2オントロジであることを示しています。 JenaはOWL1のみをサポートしています(パッケージorg.apache.jena.ontologyを参照)。 しかし、オプションとして、あなたはorg.apache.jena.ontology.OntModelのが、OWL2-仕様が完全にアナログであるONT-APIからru.avicomp.ontapi.jena.model.OntGraphModelを、使用することができます。これはapache-jenaベースのライブラリです。

例:

public static void main(String ... args) { 
    // build model with qualified exact cardinality object property restrictions: 
    OntGraphModel m = OntManagers.createONT().createOntology().asGraphModel(); 
    m.setNsPrefixes(PrefixMapping.Extended); 

    OntNOP op1 = m.createOntEntity(OntNOP.class, "http://purl.oclc.org/NET/ssnx/ssn#sensingMethodUsed"); 
    OntClass c1 = m.createOntEntity(OntClass.class, "http://purl.oclc.org/NET/ssnx/ssn#Sensing"); 
    OntNOP op2 = m.createOntEntity(OntNOP.class, "http://purl.oclc.org/NET/ssnx/ssn#featureOfInterest"); 
    OntClass c2 = m.createOntEntity(OntClass.class, "http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"); 

    OntClass clazz = m.createOntEntity(OntClass.class, "http://example.com#clazz"); 
    clazz.addSubClassOf(m.createObjectCardinality(op1, 1, c1)); 
    clazz.addSubClassOf(m.createObjectCardinality(op2, 1, c2)); 
    m.write(System.out, OntFormat.RDF_XML.getID()); 

    // printing: 
    System.out.println(); 
    m.ontObjects(OntCE.ObjectCardinality.class).forEach(c -> { 
     String datatype = Stream.of(OWL.qualifiedCardinality, OWL.cardinality) 
       .map(p -> c.objects(p, Literal.class)) 
       .flatMap(Function.identity()) 
       .map(Literal::getDatatypeURI) 
       .map(m::shortForm) 
       .map(s -> s.replaceAll("^.*:", "")) 
       .findFirst().orElse(null); 
     int cardinality = c.getCardinality(); 
     String onClass = Optional.ofNullable(c.getValue()).map(Resource::getLocalName).orElse(null); 
     String onProperty = c.getOnProperty().getLocalName(); 
     System.out.printf("qualcard %s %s %d %s%n", onProperty, datatype, cardinality, onClass); 
    }); 
} 

この例の出力:

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:eg="http://www.example.org/" 
    xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
    xmlns:ja="http://jena.hpl.hp.com/2005/11/Assembler#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:rss="http://purl.org/rss/1.0/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> 
    <owl:Ontology/> 
    <owl:Class rdf:about="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/> 
    <owl:Class rdf:about="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/> 
    <owl:Class rdf:about="http://example.com#clazz"> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#FeatureOfInterest"/> 
     <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger" 
     >1</owl:qualifiedCardinality> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:about="http://purl.oclc.org/NET/ssnx/ssn#featureOfInterest"/> 
     </owl:onProperty> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:onClass rdf:resource="http://purl.oclc.org/NET/ssnx/ssn#Sensing"/> 
     <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger" 
     >1</owl:qualifiedCardinality> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:about="http://purl.oclc.org/NET/ssnx/ssn#sensingMethodUsed"/> 
     </owl:onProperty> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    </owl:Class> 
</rdf:RDF> 

qualcard featureOfInterest nonNegativeInteger 1 FeatureOfInterest 
qualcard sensingMethodUsed nonNegativeInteger 1 Sensing 
関連する問題