On Mon, Mar 18, 2013 at 12:24 PM, Ed Swing <[email protected]> wrote:
> Thanks Joshua for looking into this. From the results you generated, it looks 
> like the Pellet reasoner gets the (more) correct results, while the default 
> Jena reasoner has some issues (Unfortunately, I may not be able to use Pellet 
> due to licensing issues - checking with legal). Anyhow, there are some 
> incorrect results - specifically (A) AircraftHijacking does not include 
> TerrorAttack as a parent at all, (B) it includes Agent as a parent, which is 
> mutually exclusive with AircraftHijacking.

Yeah, licensing might be tricky. As to the incorrect results, no one
on the list can diagnose without a complete minimal working example.

> Though an ontology class can have multiple parents, it should be possible to 
> get the original definition of the class - e.g., AircraftHijacking is a 
> subclass of TerrorAttack.
>
> I am passing true to the listSuperClasses (and subclasses) and I am still 
> getting the anonymous classes.
> I've attached the original ontology to this message - I'm tweaking it to try 
> to get it to work properly, and modifying it for use with Jena (as opposed to 
> a different ontology tool).

Not to be pedantic, but— actually, to be pedantic:  there's no reason
that an anonymous class can't be a direct superclass.  If you say
that, e.g., "C subClassOf (A and B)" then (A and B) is an anonymous
class, and a direct superclass of C.  It sounds like what you're
looking for is the presence of certain kinds of triples in the input
file.  There's no reason you can't query that, though it won't be with
the OntModel API. Here's code to load your ontology in the same way,
but to query the base model for triples using rdfs:subClassOf.  This
prints the base model, and then superclasses of terrorAttack and
aircraftHijacking.  (Using the null wildcard, you could query for
[null, RDFS.subClassOf, someClass] to find the "children" of
someClass.)  In addition, while listing the statements, we check
whether the object is a URI resource (i.e., not anonymous).

import java.io.IOException;
import java.io.InputStream;

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.Model;
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.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDFS;


public class SASTerror2 {
        public static void main(String[] args) throws IOException {
                OntModel model = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF );
                InputStream is = SASTerror.class.getResourceAsStream( 
"sas-terror.owl" );
                model.read( is, null );
                is.close();

                String ns = model.getNsPrefixURI( "" );
                
                OntClass terrorAttack = model.getOntClass( ns+"TerrorAttack" );
                OntClass aircraftHijacking = model.getOntClass( 
ns+"AircraftHijacking" );
                
                Model base = model.getBaseModel();
                base.write( System.out, "N3" );
                
                for ( Resource klass : new Resource[] { terrorAttack, 
aircraftHijacking } ) {
                        System.out.println( "* superclasses of "+klass );
                        StmtIterator it = base.listStatements( klass, 
RDFS.subClassOf,
(RDFNode) null );
                        while ( it.hasNext() ) {
                                Statement s = it.next();
                                System.out.println( "\t* "+s + ( 
s.getObject().isURIResource() ?
"(*)" : "" ));
                        }
                }
        }
}

The query output is:

* superclasses of http://example.com/sas-terror#TerrorAttack
        * [http://example.com/sas-terror#TerrorAttack,
http://www.w3.org/2000/01/rdf-schema#subClassOf,
64e6ac17:13d7e6fae01:-7ff8]
        * [http://example.com/sas-terror#TerrorAttack,
http://www.w3.org/2000/01/rdf-schema#subClassOf,
http://example.com/sas-terror#Killing](*)
* superclasses of http://example.com/sas-terror#AircraftHijacking
        * [http://example.com/sas-terror#AircraftHijacking,
http://www.w3.org/2000/01/rdf-schema#subClassOf,
http://example.com/sas-terror#TerrorAttack](*)

This still lists two superclasses of TerrorAttack, and that's because
TerrorAttack is defined by

:TerrorAttack
      a       owl:Class ;
      rdfs:subClassOf :Killing ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:allValuesFrom :TerrorAgent ;
                owl:onProperty :actor
              ] .

But only one of these is a URI resource (indicated by (*)), which is
probably what you're looking for.

//JT

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

Reply via email to