[Pellet-users] SWRL rules with OWLAPI
Ely Edison Matos
ely.matos at ufjf.edu.br
Sat Dec 22 19:42:43 UTC 2007
Hello,
I'm using Pellet 1.5.1 and I'm trying to run the RulesExample (converted to use with OWLAPI), but it seems that OWLAPI don't see the individuals created by the SWRL rules after ontology is loaded. I copied the code (below). Am I making a mistake, or are there another real problem here?
Thanks,
Ely
--------------------------------
public class RulesExample {
public static OWLOntology _ontology;
public static Reasoner _reasoner ;
public static void main(String[] args) throws OWLOntologyCreationException, UnknownOWLOntologyException, OWLOntologyStorageException {
String ont = "http://owldl.com/ontologies/dl-safe.owl";
OWLOntologyManager _manager = OWLManager.createOWLOntologyManager();
_ontology = _manager.loadOntologyFromPhysicalURI(URI.create(ont));
PelletOptions.DL_SAFE_RULES = true;
PelletOptions.IGNORE_UNSUPPORTED_AXIOMS = false;
_reasoner = new Reasoner( _manager );
_reasoner.setOntology( _ontology );
OWLDataFactory _factory = _manager.getOWLDataFactory();
OWLClass Child = _factory.getOWLClass(URI.create(ont + "#Child"));
OWLClass BadChild = _factory.getOWLClass(URI.create(ont + "#BadChild"));
OWLObjectProperty sibling = _factory.getOWLObjectProperty(URI.create(ont + "#sibling"));
OWLIndividual Cain = _factory.getOWLIndividual(URI.create(ont + "#Cain"));
OWLIndividual Abel = _factory.getOWLIndividual(URI.create(ont + "#Abel"));
OWLIndividual Remus = _factory.getOWLIndividual(URI.create(ont + "#Remus"));
OWLIndividual Romulus = _factory.getOWLIndividual(URI.create(ont + "#Romulus"));
printPropertyValues(Cain, sibling );
printPropertyValues(Abel, sibling );
printPropertyValues(Remus, sibling );
printPropertyValues(Romulus, sibling );
printInstances( Child );
printInstances( BadChild );
}
public static void printPropertyValues(OWLIndividual ind, OWLObjectProperty prop) {
System.out.println( ind.getURI() + " has " + URIUtils.getLocalName(prop.getURI()));
Map m = ind.getObjectPropertyValues(_ontology);
Set s = (Set) m.get(prop);
if (s != null) {
Iterator<OWLIndividual> i = s.iterator();
printIterator(i);
}
}
public static void printInstances(OWLClass cls) {
System.out.println( URIUtils.getLocalName(cls.getURI()) + " instances: " );
Set individuals = _reasoner.getIndividuals(cls, false);
if (individuals != null) {
printIterator(individuals.iterator());
}
}
public static void printIterator(Iterator i) {
if( !i.hasNext() ) {
System.out.print( "none" );
}
else {
while( i.hasNext() ) {
System.out.print( URIUtils.getLocalName(((OWLIndividual)i.next()).getURI()) );
if( i.hasNext() )
System.out.print( ", " );
}
}
System.out.println();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.owldl.com/pipermail/pellet-users/attachments/20071222/0ea8b6c7/attachment.htm
More information about the Pellet-users
mailing list