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();
}
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());
}
}
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());
}
}
Aggregations