this is my code... i got this code from a person in users@apache.
please help me
import com.hp.hpl.jena.graph.FrontsNode;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.ontology.BooleanClassDescription;
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.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.ontology.Restriction;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.hp.hpl.jena.ontology.*;
import org.semanticweb.owlapi.model.OWLIndividual;
import it.uniroma2.art.owlart.model.impl.*;
public class prop implements FrontsNode{
static final String inputFileName = "F:\\protege
classes\\ont\\newspaper.owl";
static final String inputFile = "F:\\protege
classes\\ont\\newspaper\\paper.owl";
// static final String inputFile = "C:\\Program Files
(x86)\\Protege_3.4.2\\country1.owl";
public static void main(String args[])
{ prop p= new prop();
boolean b=true;
try{
OntModel model = ModelFactory.createOntologyModel();
OntModel model1 = ModelFactory.createOntologyModel();
InputStream inStream = FileManager.get().open(inputFileName);
InputStream in = FileManager.get().open(inputFile);
if (inStream == null) {
throw new IllegalArgumentException("File: " + inputFileName
+ " not found");
}
if (in == null) {
throw new IllegalArgumentException("File: " + inputFile + "
not found");
}
model.read(inStream, "");
model1.read(in, "");
String uriBase = model.getNsPrefixURI("
http://www.owl-ontologies.com/Ontology1363337688.owl#");
String uri = "http://www.owl-ontologies.com/Ontology1363337688.owl#";
//String uri1 = "http://www.owl-ontologies.com/Ontology1365109828.owl#
";
String uri1 ="http://www.owl-ontologies.com/Ontology1363337688.owl#";
OntClass thisone = model.getOntClass(uri + "Personals_Ad");
OntClass thatone = model.getOntClass(uri1 + "Editor");
p.areEqual(b, thisone, thatone);
}
catch (Exception e) {
System.out.println(e);
}
}
private Map<String, String> nsRemap;
private boolean isMapped(String thisURI, String thatURI){
if(thisURI.equals(thatURI)) return true;
if(nsRemap == null) return false;
String mapString = nsRemap.get(thisURI);
if(mapString != null && mapString.equals(thatURI)) return
true;
return false;
}
private boolean areEqual(OntClass thisOne, OntClass thatOne){
return areEqual(false, thisOne, thatOne);
}
private boolean areEqual(boolean deep, OntClass thisOne, OntClass thatOne){
if (thisOne.isUnionClass() && thatOne.isUnionClass()) {
return areEqual(thisOne.asUnionClass(), thatOne.asUnionClass());
} else if (thisOne.isIntersectionClass() &&
thatOne.isIntersectionClass()) {
return areEqual(thisOne.asIntersectionClass(),
thatOne.asIntersectionClass());
} else if (thisOne.isComplementClass() &&
thatOne.isComplementClass()) {
return areEqual(thisOne.asComplementClass(),
thatOne.asComplementClass());
} else if (thisOne.isRestriction() && thatOne.isRestriction()) {
return areEqual(thisOne.asRestriction(),
thatOne.asRestriction());
} else if (thisOne.isURIResource() && thatOne.isURIResource()) {
// Both classes must have the same URI to be the same
if(!haveEqualURI(thisOne, thatOne))
return false;
if(deep){
// Must have the same Equivalent Classes
if(!areEqual(thisOne.listEquivalentClasses().toList(),
thatOne.listEquivalentClasses().toList()))
return false;
// Must have the same Superclasses
if(!areEqual(thisOne.listSuperClasses().toList(),
thatOne.listSuperClasses().toList()))
return false;
// Must have the same Disjoint Classes
if(!areEqual(thisOne.listDisjointWith().toList(),
thatOne.listDisjointWith().toList()))
return false;
}
return true;
}
return false;
}
private boolean haveEqualURI(OntResource thisURI, OntResource thatURI){
if(thisURI.isURIResource() && thatURI.isURIResource()){
if(thisURI.getLocalName().equals(thatURI.getLocalName())){
if(isMapped(thisURI.getNameSpace(),
thatURI.getNameSpace())){
return true;
}
}
}
return false;
}
private boolean areEqual(OntProperty thisOne, OntProperty thatOne){
return areEqual(false, thisOne, thatOne);
}
private boolean areEqual(boolean deep, OntProperty thisOne,
OntProperty thatOne){
if(thisOne.isURIResource() && thatOne.isURIResource()){
// Both properties must have the same URI to be the same
if(!haveEqualURI(thisOne, thatOne))
return false;
if(deep){
if(thisOne.isDatatypeProperty() &&
!thatOne.isDatatypeProperty()) return false;
if(thisOne.isFunctionalProperty() &&
!thatOne.isFunctionalProperty()) return false;
if(thisOne.isInverseFunctionalProperty() &&
!thatOne.isInverseFunctionalProperty()) return false;
if(thisOne.isObjectProperty() &&
!thatOne.isObjectProperty()) return false;
if(thisOne.isSymmetricProperty() &&
!thatOne.isSymmetricProperty()) return false;
if(thisOne.isTransitiveProperty() &&
!thatOne.isTransitiveProperty()) return false;
if(!areEqual(thisOne.listRange().toList(),
thatOne.listRange().toList())) return false;
if(!areEqual(thisOne.listDomain().toList(),
thatOne.listDomain().toList())) return false;
if(!areEqual(thisOne.listSuperProperties(true).toList(),
thatOne.listSuperProperties(true).toList())) return false;
}
return true;
}
return false;
}
// This will catch UnionClass, IntersectionClass, and ComplementClass
private boolean areEqual(BooleanClassDescription thisOne,
BooleanClassDescription thatOne){
return areEqual(thisOne.listOperands().toList(),
thatOne.listOperands().toList());
}
private boolean areEqual(List<? extends OntResource> thisOne,
List<? extends OntResource> thatOne){
for(int i = 0; i < thisOne.size(); i++ ){
for(int j = 0; j < thatOne.size(); j++){
if(areEqual(thisOne.get(i), thatOne.get(j))){
thisOne.remove(i);
thatOne.remove(j);
i--;
break;
}
}
}
if(thisOne.size() == 0 && thatOne.size() == 0) return true;
return false;
}
private boolean areEqual(Restriction thisOne, Restriction thatOne){
// Same property for this restriction
if(!areEqual(thisOne.getOnProperty(), thatOne.getOnProperty()))
return false;
// Same restriction type and values
if (thisOne.isAllValuesFromRestriction() &&
thatOne.isAllValuesFromRestriction())
return
areEqual(thisOne.asAllValuesFromRestriction().getAllValuesFrom(),
thatOne.asAllValuesFromRestriction().getAllValuesFrom());
if (thisOne.isSomeValuesFromRestriction() &&
thatOne.isSomeValuesFromRestriction())
return
areEqual(thisOne.asSomeValuesFromRestriction().getSomeValuesFrom(),
thatOne.asSomeValuesFromRestriction().getSomeValuesFrom());
if (thisOne.isHasValueRestriction() &&
thatOne.isHasValueRestriction())
return
areEqual(thisOne.asHasValueRestriction().getHasValue(),
thatOne.asHasValueRestriction().getHasValue());
if (thisOne.isCardinalityRestriction() &&
thatOne.isCardinalityRestriction())
return thisOne.asCardinalityRestriction().getCardinality()
== thatOne.asCardinalityRestriction().getCardinality();
if (thisOne.isMaxCardinalityRestriction() &&
thatOne.isMaxCardinalityRestriction())
return
thisOne.asMaxCardinalityRestriction().getMaxCardinality() ==
thatOne.asMaxCardinalityRestriction().getMaxCardinality();
if (thisOne.isMinCardinalityRestriction() &&
thatOne.isMinCardinalityRestriction())
return
thisOne.asMinCardinalityRestriction().getMinCardinality() ==
thatOne.asMinCardinalityRestriction().getMinCardinality();
return false;
}
private boolean areEqual(RDFNode thisOne, RDFNode thatOne){
if(thisOne.isResource() && thatOne.isResource())
return areEqual(thisOne.asResource(), thatOne.asResource());
if(thisOne.isLiteral() && thatOne.isLiteral())
return areEqual(thisOne.asLiteral(), thatOne.asLiteral());
return false;
}
private boolean areEqual(Resource thisOne, Resource thatOne){
if(thisOne.canAs(OntClass.class) && thatOne.canAs(OntClass.class))
return
areEqual(thisOne.as(OntClass.class),thatOne.as(OntClass.class));
if(thisOne.canAs(OntProperty.class) &&
thatOne.canAs(OntProperty.class))
return areEqual(thisOne.as(OntProperty.class),
thatOne.as(OntProperty.class));
else
return thisOne.equals(thatOne);
}
private boolean areEqual(Literal thisOne, Literal thatOne){
return this.equals(thatOne);
}
public Node asNode() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
On Thu, Apr 11, 2013 at 7:15 AM, Chris Dollin
<[email protected]>wrote:
> On Thursday, April 11, 2013 05:51:30 AM aarthi wrote:
> > i'm comparing two classes.. if its a resource, asResource() will return
> > the resource else it will through the exception..
>
> Yes, that's what it's for, but you /don't need to use/ asResource or
> asLiteral to do an equality test.
>
> > for this
> > asResource() i found an error that
> > " cannot find symbol
> > symbol: method asResource()
> > location: interface com.hp.hpl.jena.rdf.model.RDFNode"... so what
> to
> > do?
>
> (fx:checking) RDFNode definitely has the asResource() method.
>
> What version of Jena are you using? Can you construct the
> smallest possible example to show us the error in detail?
>
> Are you using an IDE for your Java development? If not, I strongly
> suggest you do. (It would be best if you could find another user
> to introduce you to it, though.) An IDE such as Eclipse offers useful
> features like "import the right class(es) to make this reference
> work" and "suggest a fix for this compilation problem".
>
> Chris
>
> >
> > On Mon, Apr 8, 2013 at 3:34 AM, Chris Dollin
> > <[email protected]>wrote:
> >
> > > On Monday, April 08, 2013 03:06:39 AM aarthi wrote:
> > > > hi....... i'm comparing two owl files using jena. in that i use
> this
> > > > code for comparision
> > > >
> > > >
> > > >
> > > > private boolean areEqual(RDFNode thisOne, RDFNode thatOne){
> > > > if(thisOne.isResource() && thatOne.isResource())
> > > > return areEqual(thisOne.asResource(),
> thatOne.asResource());
> > > > if(thisOne.isLiteral() && thatOne.isLiteral())
> > > > return areEqual(thisOne.asLiteral(),
> thatOne.asLiteral());
> > > >
> > > > return false;
> > > > }
> > > >
> > > > but there is an error in asLiteral() and asResource(). I have
> imported
> > > > hp.hpl.jena.rdf.graph.RDFNode but still i can't resolve the
> error.
> > > > anyone help me
> > >
> > > Why not just use .equals()?
> > >
> > > (You don't tell us what the error is or what RDFNode's you're comparing
> > > or what the calling code looks like or whether you have overloads for
> > > areEqual(), so it's a bit tricky to work out what you've done wrong.)
> > >
> > > Chris
> > >
> > > --
> > > "I don't want to know what the Structuralists think! I want
> /Archer's
> > > Goon/
> > > to know what YOU think!"
> > >
> > > Epimorphics Ltd, http://www.epimorphics.com
> > > Registered address: Court Lodge, 105 High Street, Portishead, Bristol
> BS20
> > > 6PT
> > > Epimorphics Ltd. is a limited company registered in England (number
> > > 7016688)
> > >
> > >
> --
> "You're down as expendable. You don't get a weapon." /Dark Lord of
> Derkholm/
>
> Epimorphics Ltd, http://www.epimorphics.com
> Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20
> 6PT
> Epimorphics Ltd. is a limited company registered in England (number
> 7016688)
>
>