Search in sources :

Example 6 with Rule

use of com.hp.hpl.jena.reasoner.rulesys.Rule in project stanbol by apache.

the class JenaReasoningServiceTest method testIsConsistentWithRules.

/**
     * Tests the isConsistent(Model,List<Rule>) method of a service
     * 
     * @param service
     */
private void testIsConsistentWithRules(JenaReasoningService service) {
    log.info("Testing reasoner of type {}", service.getClass());
    // Prepare the rule set
    String source = "" + "\n@prefix foaf: <" + TestData.FOAF_NS + ">." + "\n@prefix ex: <" + TestData.TEST_NS + ">." + "\n[rule1: (?a foaf:knows ?b) (?a foaf:workplaceHomepage ?w) (?b foaf:workplaceHomepage ?w) -> (?a ex:collegueOf ?b)] " + "\n[rule2: (?b foaf:knows ?a) -> (?a foaf:knows ?b)] " + "\n[rule3: (?a ex:collegueOf ?b) -> (?b ex:collegueOf ?a)] ";
    // log.info("This is the ruleset: \n {}", source);
    List<Rule> rules = TestUtils.parseRuleStringAsFile(source);
    log.info("Loaded {} rules", rules.size());
    // Clean data
    TestData.alexdma.removeProperties();
    TestData.enridaga.removeProperties();
    Resource wphomepage = TestData.model.createResource("http://stlab.istc.cnr.it");
    // Prepare data
    TestData.alexdma.addProperty(TestData.foaf_knows, TestData.enridaga);
    TestData.alexdma.addProperty(TestData.foaf_workplaceHomepage, wphomepage);
    TestData.enridaga.addProperty(TestData.foaf_workplaceHomepage, wphomepage);
    // Setup input for the reasoner
    Model input = ModelFactory.createUnion(TestData.enridaga.getModel(), TestData.alexdma.getModel());
    input = ModelFactory.createUnion(input, TestData.foaf);
    try {
        // Run the method
        boolean isConsistent = service.isConsistent(input, rules);
        // Assert true
        log.info("Is consistent (true)? {}", isConsistent);
        assertTrue(isConsistent);
    } catch (ReasoningServiceException e) {
        log.error("Error thrown: {}", e);
        assertTrue(false);
    }
    // Clean data
    TestData.alexdma.removeProperties();
    TestData.enridaga.removeProperties();
}
Also used : ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) Resource(com.hp.hpl.jena.rdf.model.Resource) Model(com.hp.hpl.jena.rdf.model.Model) Rule(com.hp.hpl.jena.reasoner.rulesys.Rule)

Example 7 with Rule

use of com.hp.hpl.jena.reasoner.rulesys.Rule in project stanbol by apache.

the class JenaAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<Rule> rules = (List<Rule>) ruleAdapter.adaptTo(recipeGood, Rule.class);
        StringBuilder sb = new StringBuilder();
        for (Rule rule : rules) {
            sb.append(rule.toString());
        }
        Assert.assertNotSame(sb.toString(), "");
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        Assert.fail(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) Rule(com.hp.hpl.jena.reasoner.rulesys.Rule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 8 with Rule

use of com.hp.hpl.jena.reasoner.rulesys.Rule in project stanbol by apache.

the class ClerezzaAdpterTest method wrongAdaptabeClassTest.

@SuppressWarnings("unchecked")
@Test
public void wrongAdaptabeClassTest() {
    try {
        List<Rule> rules = (List<Rule>) ruleAdapter.adaptTo(recipeGood, Rule.class);
        for (Rule rule : rules) {
            log.debug(rule.toString());
            Assert.fail("The adapter for Clerezza should not accept " + Rule.class.getCanonicalName() + " objects.");
        }
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        log.debug(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) Rule(com.hp.hpl.jena.reasoner.rulesys.Rule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Aggregations

Rule (com.hp.hpl.jena.reasoner.rulesys.Rule)8 Model (com.hp.hpl.jena.rdf.model.Model)4 Resource (com.hp.hpl.jena.rdf.model.Resource)3 Statement (com.hp.hpl.jena.rdf.model.Statement)3 List (java.util.List)3 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)3 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)3 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)3 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Test (org.junit.Test)2 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)2 Property (com.hp.hpl.jena.rdf.model.Property)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 IRI (org.apache.clerezza.commons.rdf.IRI)1