1
    OntModel onto = ModelFactory.createOntologyModel(
            OntModelSpec.OWL_MEM_MICRO_RULE_INF, null );

    String inputFileName = "./src/test.xml";    

    InputStream in = FileManager.get().open(inputFileName);
    if (in == null) {
        throw new IllegalArgumentException( "File: " + inputFileName + " not found");
    }

    onto.read(new InputStreamReader(in), "");        

    //ns is the namespace...
    OntClass userClass = onto.getOntClass(ns+"User");

    Individual dada = onto.createIndividual(ns+"Daryl", userClass);

    Property prefBathtub = onto.getProperty(ns+"prefersBathtub");
    Property prefBathtubWt = onto.getProperty(ns+"prefersBathtubWeight");

    dada.addLiteral(prefBathtub, true);
    dada.addLiteral(prefBathtubWt, 0.30);

    OutputStream out = new FileOutputStream("./src/test2.xml");
    onto.write( out, "RDF/XML"); // readable rdf/xml
    out.close();

プロパティだけでなく、OntPropertyやDatatypePropertyを使用するにはどうすればよいですか?

プロパティを使用することで、同じ量の表現力を得ることができますか?

4

1 に答える 1

0

ObjectPropertyオントロジー モデルからオブジェクトを取得するには、 OntModel.getObjectProperty()を使用します。データ型プロパティなどについても同様です。Ontクラスは、1 つのメソッド呼び出しでプロパティのスーパー プロパティなどを取得するための便利な API が含まれているという意味で、より表現力があります。ただし、コンビニエンス API はグラフ内の基になるトリプルにのみアクセスするため、厳密に言えば、ObjectPropertyで実行できて で実行できないことはありませんProperty。それはただのより難しい仕事です!

ちなみに、Jena では、メソッドを使用して、基礎となる RDF リソースの他のファセットにアクセスできます.as()。そう:

Property p = myModel.getProperty( "http://example.com/foo#p" );
OntProperty op = p.as( OntProperty.class );
于 2012-09-25T20:53:50.877 に答える