On Thu, Apr 18, 2013 at 2:31 PM, aarthi <[email protected]> wrote:
>  hi ... i have two ontology.  some how i found the equivalent classes in
> that two ontology. l need to create a relation between these two classes,
> that they are equivalent. how to do this in jena?

You want OntClass#addEquivalentClass [1], or just the property
OWL.equivalentClass [2].  Here's an example:

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.vocabulary.OWL;

public class EquivalentClasses {
        public static void main(String[] args) {
                OntModel model = ModelFactory.createOntologyModel();
                String NS = "http://www.example.com/ont#";;
                
                OntClass a = model.createClass( NS + "A" );
                OntClass b = model.createClass( NS + "B" );
                
                // If you're working with an OntModel and you have your
                // classes as OntClasses, you can use 
OntClass#addEquivalentClass.
                a.addEquivalentClass( b );

                // Alternatively, if you do not have the classes as
                // OntClasses, but just as resources, you can still
                // just add the following triple to the model:
                // [a, OWL.equivalentClass, b]
                model.add( a, OWL.equivalentClass, b );
                
                model.write( System.out, "N3" );
        }
}

Output:

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

<http://www.example.com/ont#A>
      a       owl:Class ;
      owl:equivalentClass <http://www.example.com/ont#B> .

<http://www.example.com/ont#B>
      a       owl:Class .


//JT

[1] 
http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntClass.html#addEquivalentClass(com.hp.hpl.jena.rdf.model.Resource)
[2] 
http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/vocabulary/OWL.html#equivalentClass

-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to