0

私は基本的に Jena を使用してこれを行いたい:

i) スキーマ

class:LivingBeing type owl:Class
prop:PrimeFeatures

class:Animal type owl:Class
prop:Speed typeOf PrimeFeatures
prop:Nature typeOf PrimeFeatures

class:HumanBeing type owl:Class
prop:Intelligence typeOf PrimeFeatures

ii) データ

Individual:Cat typeOf Animal resource="someuri:Cat"
prop:Speed = 100
prop:Nature = violent
prop:Veg = No

Individual:John typeOf HumanBeing resource="someuri:John"
prop:Intelligence = Average



Resource resourcecat = model.getResource("someuri:Cat") ;

上記のスキーマとデータを使用して、次のような resourcecat のニーズに応えたいと思います。だから、私は以下を取得する必要があります:-

           PrimeFeatures(catresource):
           speed=100
           nature=violent

また、Animal クラスのスキーマを使用して、Animal クラスの主な機能を変更できるはずです。

基本的には、スキーマを使用して取得したデータを制御したいと考えています。ほとんどの場合、OntClass、Resource、および Properties を使用します。Jena を使用すれば可能であるに違いないことはわかっています。

4

1 に答える 1

0

考えられる解決策の 1 つを以下に示します。ただし、OWL と RDF の特性を設計どおりに実際に使用していないことに注意してください。本当に Jena の機能を利用したい場合は、セマンティック Web テクノロジの詳細を読み、それを使用して設計を行う必要があります。それ以外の場合は、Java を使用してアプリケーション専用のカスタム ソリューションを設計することをお勧めします。

package test;

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class User1374179_Test
{
    public static String ns = "http://example.org/test#";

    private OntClass livingBeing;
    private OntClass animal;
    private OntProperty primeFeatures;
    private OntProperty speed;
    private OntProperty nature;

    public static void main( String[] args ) {
        new User1374179_Test().run();
    }

    public void run() {
        OntModel m = createSchema();
        showClassProperties( livingBeing );
        showClassProperties( animal );

        Individual cat1 = createInstance( m, animal, "cat1" );
        cat1.addProperty( speed, m.createTypedLiteral( 100 ));
        cat1.addProperty( nature, "violent" );
        showInstanceProperties( cat1, animal );
    }

    private OntModel createSchema() {
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );


        livingBeing = m.createClass( ns + "LivingBeing" );
        primeFeatures = m.createOntProperty( ns + "primeFeatures" );
        primeFeatures.addDomain( livingBeing );

        animal = m.createClass( ns + "Animal" );
        animal.addSuperClass( livingBeing );

        speed = m.createOntProperty( ns + "speed" );
        speed.addSuperProperty( primeFeatures );
        speed.addDomain( animal );

        nature = m.createOntProperty( ns + "nature" );
        nature.addSuperProperty( primeFeatures );
        nature.addDomain( animal );

        return m;
    }

    private Individual createInstance( OntModel m, OntClass cls, String name ) {
        return m.createIndividual( ns + name, cls );
    }

    private void showClassProperties( OntClass c ) {
        System.out.println( "Class " + c.getURI() );
        for (ExtendedIterator<OntProperty> i = c.listDeclaredProperties(); i.hasNext(); ) {
            System.out.println( " .. has property " + i.next() );
        }
    }

    private void showInstanceProperties( OntResource r, OntClass c ) {
        System.out.println( "Instance " + r.getURI() + " has properties: " );
        for (ExtendedIterator<OntProperty> i = c.listDeclaredProperties(true); i.hasNext(); ) {
            OntProperty p = i.next();
            System.out.println( p.getURI() + " ==> " + r.getPropertyValue( p ) );
        }
    }
}

出力:

Class http://example.org/test#LivingBeing
 .. has property http://example.org/test#primeFeatures
Class http://example.org/test#Animal
 .. has property http://example.org/test#speed
 .. has property http://example.org/test#primeFeatures
 .. has property http://example.org/test#nature
Instance http://example.org/test#cat1 has properties: 
http://example.org/test#speed ==> 100^^http://www.w3.org/2001/XMLSchema#int
http://example.org/test#nature ==> violent
于 2013-01-25T09:18:40.287 に答える