use of com.hp.hpl.jena.rdf.model.Resource in project stanbol by apache.
the class JenaToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the Jena model for the test.
* Simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
model = ModelFactory.createDefaultModel();
Resource foafPersonInJena = model.createResource(foaf + "Person");
Property knowsInJena = model.createProperty(foaf + "knows");
Resource andreaNuzzoleseInJena = model.createResource(ns + "AndreaNuzzolese", foafPersonInJena);
Resource enricoDagaInJena = model.createResource(ns + "EnricoDaga", foafPersonInJena);
andreaNuzzoleseInJena.addProperty(knowsInJena, enricoDagaInJena);
/*
* Set-up the Clerezza model for the test.
* As before simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
use of com.hp.hpl.jena.rdf.model.Resource 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.rdf.model.Resource in project stanbol by apache.
the class RuleParserImpl method getSWRLVariable.
private static URI getSWRLVariable(String argument) {
Resource variableResource = null;
String variableString = argument.substring(1);
variableResource = ModelFactory.createDefaultModel().createResource(kb.getPrefixURI("var") + variableString);
try {
return new URI(variableResource.getURI());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
use of com.hp.hpl.jena.rdf.model.Resource in project stanbol by apache.
the class RuleParserImpl method getSWRLArgument.
private static URI getSWRLArgument(String argument) {
Resource rdfNode = null;
String[] argumentComposition = argument.split(":");
if (argumentComposition.length == 2) {
String prefix = argumentComposition[0];
String resourceName = argumentComposition[1];
String namespaceURI = kb.getPrefixURI(prefix);
rdfNode = ModelFactory.createDefaultModel().createResource(namespaceURI + resourceName);
try {
return new URI(rdfNode.getURI());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
Aggregations