Question

I created an ontology based Security alerts. After reading in some data(Individuals) it got pretty big, so I decided to use a Jena Rule Reasoner to determine some facts. I mostly give Individuals types and attributes and use some regex. Heres a small (constructed) example which gives an individual the type "multiple", when its information matches the regex:

[testRuleContent: (?X ns:hasClassification ?Y), (?Y ns:hasText ?Z), regex(?Z, '.Multiple.') -> (?X rdf:type ns:Multiple)]

To use the reasoner i create an infModel based on my previous loaded ontology:

RuleReasoner ruleReasoner = new RuleReasoner("GenaralRuleReasoner");
//read rules from file
List<Rule> ruleList = Rule.parseRules(Rule.parseRules(rd));
com.hp.hpl.jena.reasoner.Reasoner reasoner = new GenericRuleReasoner(ruleList);
//jenaOntology is the ontology with the data
InfModel inferredOntotlogy = ModelFactory.createInfModel(reasoner, jenaOntology);
inferredOntotlogy.prepare();

This works without a problem and i can write the infModel into a file with the added types.

Whats the preferable method to query the inferred ontology for certain individuals (in this example those with the type: "Multiple")?

At the moment I use "listStatements()" on the Inferred Model:

Resource multiple = inferredOntotlogy.getResource("file:/C:/ns#Multiple");
StmtIterator iter = inferredOntotlogy.listStatements(null, RDF.type, multiple);
while (iter.hasNext()) {
        Resource subject = iter.next().getSubject();
        //Individual ind = subject.as(Individual.class);
        String indUri = iter.next().getSubject().getURI();

The cast throws an exception(Its only a node with the Uri). But I get the valid Uri of the individual and could work with the basic ontology model without the new proprties (I only need them to get the searched individual so its a possible solution).

A similar attempt would be to use getDeductionsModel() on the Inferred Model to get a Model -> OntModel and query it (potentially with SPARQL).

But id prefere an easy way to query the Inferred Model. Is there such a solution? Or can u give me a tip how to handle this situaion the best way?

Was it helpful?

Solution

I will just work with the resources fow now. It provides all the functionality I need. I should have taken a closer look at the API.

I answered my own question to mark it as solved tomorrow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top