Hi,
This is the code i got through jena community... getting error in
getSubject().....can anyone help me????

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class MappingOntologies {
        public static void main(String[] args) {
                // In most cases, the ontologies already exist, but since
we do not have
                // sample data here, we create minimal ontologies that have
the classes
                // that were mentioned, namely Ont1 that has a class
Employee with a
                // subclass Age, and Ont2 that has a class Employee.

                // Ont1
                String NS1 = "http://www.example.com/ont1/";;
                OntModel ont1 = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM );
                OntClass employee1 = ont1.createClass( NS1 + "Employee" );
                OntClass age1 = ont1. createClass( NS1 + "Age" );
                employee1.addSubClass( age1 );

                // Ont2
                String NS2 = "http://www.example.com/ont2/";;
                OntModel ont2 = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM );
                OntClass employee2 = ont2.createClass( NS2 + "Employee" );

                // Usually when we merge or map ontologies, we are not
modifying either
                // ontology, but actually creating some third ontology that
imports the
                // others, and adding the mapping axioms to that third
ontology.  In OWL
                // we would probably do this using owl:imports, but in the
Jena API we
                // can just create the third model and add the first two as
submodels.

                // Ont3;  we make this one an inference model so that we
can get the
                // inference that employee2 has age1 is a subclass of
employee2.
                OntModel ont3 = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF );

                // add the submodels
                ont3.addSubModel( ont1 );
                ont3.addSubModel( ont2 );

                // assert that employee1 is equivalent to employee2
                ont3.add( employee1, OWL.equivalentClass, employee2 );

                // To see the subclasses of employee2 in the merged/mapped
ontology,
                // ask for statements of the form [x, rdfs:subClassOf,
employee2].  Each
                // x is a subclass of employee2.
                StmtIterator axioms = ont3.listStatements( null,
RDFS.subClassOf, employee2 );
                System.out.println( "Subclasses of "+employee2 );
                while ( axioms.hasNext() ) {
                    Resource re=axioms.next().*getSubject()* ;
                      System.out.println( "\t"+ re);
                }

                // Alternatively, you could get the employee2 OntClass from
the merged
                // model and list its subclasses.  It is important to
retrieve the
                // OntClass from the merged model, because that is the
model that
                // OntClass#listSubClasses will query.
                //
                // Note:  when I run this query, I only one less result
than I do
                // in the previous query.  I do not see the (trivial)
result that
                // employee2 is a subclass of itself.  Depending on your
intended
                // use, this might be a reason to favor the first approach.
                OntClass employee32 = ont3.getOntClass( NS2 + "Employee" );
                ExtendedIterator subclasses = employee32.listSubClasses();
                System.out.println( "Subclasses of "+employee32 );
                while ( subclasses.hasNext() ) {
                        System.out.println( "\t"+subclasses.next() );
                }
        }
}



On Sat, Apr 27, 2013 at 8:04 PM, Joshua TAYLOR <[email protected]>wrote:

> On Sat, Apr 27, 2013 at 9:20 AM, suganya <[email protected]> wrote:
> > error in getsubject method;
> >
> > here is a piece of code
> >   while ( axioms.hasNext() ) {
> >                     Resource re=axioms.next().getSubject() ;
> >                         System.out.println( "\t"+ re);
> > ERROR in netbeans:
> > cannot find symbol
> >   symbol:   method getSubject()
> >   location: class java.lang.Object
>
> That doesn't look like an error in getSubject().  That looks like
> axioms is an iterator over java.lang.Objects, not Jena statements.
> There's not enough code here to tell, though…
>
> //JT
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>



-- 
with regards.....
sugan,...

Reply via email to