Hi.

Assume the attached RDF file. This is a simple

Manufacturer -> Europe (subclass) -> Germany (subclass) -> Audi (subclass)
-> Instance,

which has been created using inference for subclass and type from jena.


The problem that I have is that if I get the root class (in this example
Manufacturer)

and call the listInstances(true) method, I get an empty set (I assume that
I should

get Manufacturer, since it has a direct instance).


Furthermore, if I use the transitive reduction of the above code and use no
inference

in the model, the listInstances(false) method this time, again I get an
empty result

(I assume that again I should get the Manufacturer class).


Finally, I am really interested in very fast access from classes or
subclasses to instances and from instances to classes and
subclasses. Can you provide me any hints?

Thank you!

public class JenaTest {
    private OntModel model;
    private String inputFileName;

    public JenaTest() {

        // Create a simple RDFS++ Reasoner.
        //StringBuilder sb = new StringBuilder();

        //sb.append("[rdfs9:   (?x rdfs:subClassOf ?y), (?a rdf:type ?x) ->
(?a rdf:type ?y)] ");
        //sb.append("[rdfs11:  (?x rdfs:subClassOf ?y), (?y rdfs:subClassOf
?z) -> (?x rdfs:subClassOf ?z)] ");

        //Reasoner reasoner = new
GenericRuleReasoner(Rule.parseRules(sb.toString()));

        // an OWL/RDF model that performs no reasoning at all:
        model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

        //Model base = ModelFactory.createDefaultModel();
        //model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM,
ModelFactory.createInfModel(reasoner, base));


        // using the FileManager to find the input file:
        InputStream in =
FileManager.get().open("/home/mythos/Virtuoso/WISE_Demo_Data/data/TestInference.rdf");

        if (in == null) {
            System.out.println("File: \"" + inputFileName + "\" not found");
        }

        // read the RDF/XML file
        try {
            model.read(in, "");
        } catch (Exception e) {
            System.err.println("Could not read file \"" + inputFileName +
"\". It's either malformed or corrupted\n");
        }

    }

    public Set<String> getAllTopClassesWithInstances() {
        Set <String> top = new HashSet<String>();

        ExtendedIterator<OntClass> it = model.listHierarchyRootClasses();
        for (; it.hasNext();) {
            OntClass cl = it.next();
            if (cl.listInstances(false).hasNext()) {
                String c = cl.getLocalName();
                top.add(c);
            }
        }

        return top;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        JenaTest test = new JenaTest();
        Set <String> top = test.getAllTopClassesWithInstances();
        System.out.println(top);

    }
}

-- 

Panagiotis Papadakos,


PhD Student

Computer Science Department

University of Crete

http://www.csd.uoc.gr/~papadako
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    xmlns:owl="http://www.w3.org/2002/07/owl#";
    xmlns="http://www.semanticweb.org/ontologies/2012/Preferences#";
    xmlns:ontologies="http://www.semanticweb.org/ontologies/2012/";
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#";
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"; > 
  <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2012/Preferences#Europe";>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Manufacturer"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2012/Preferences#ID21_Car_Audi_A3_2012_Automatic_Front_1.984lt_200hp_0Cyl_0.0022THC_0.71CO_428CO2_0.011NOx_0PM_0CH4_0N20";>
    <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Manufacturer"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Europe"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Germany"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Audi"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2012/Preferences#Manufacturer";>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2012/Preferences#Germany";>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Manufacturer"/>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Europe"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2012/Preferences#Audi";>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Manufacturer"/>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Europe"/>
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/Preferences#Germany"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
</rdf:RDF>

Reply via email to