Search in sources :

Example 11 with Resource

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);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Resource(com.hp.hpl.jena.rdf.model.Resource) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Property(com.hp.hpl.jena.rdf.model.Property) BeforeClass(org.junit.BeforeClass)

Example 12 with Resource

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();
}
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 13 with Resource

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;
    }
}
Also used : Resource(com.hp.hpl.jena.rdf.model.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 14 with Resource

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;
}
Also used : Resource(com.hp.hpl.jena.rdf.model.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

Resource (com.hp.hpl.jena.rdf.model.Resource)14 Statement (com.hp.hpl.jena.rdf.model.Statement)6 Model (com.hp.hpl.jena.rdf.model.Model)5 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)5 Rule (com.hp.hpl.jena.reasoner.rulesys.Rule)3 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)3 OntModel (com.hp.hpl.jena.ontology.OntModel)2 Property (com.hp.hpl.jena.rdf.model.Property)2 RDFNode (com.hp.hpl.jena.rdf.model.RDFNode)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 IRI (org.apache.clerezza.commons.rdf.IRI)2 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 AnnotationProperty (com.hp.hpl.jena.ontology.AnnotationProperty)1 DatatypeProperty (com.hp.hpl.jena.ontology.DatatypeProperty)1 Individual (com.hp.hpl.jena.ontology.Individual)1 ObjectProperty (com.hp.hpl.jena.ontology.ObjectProperty)1 OntClass (com.hp.hpl.jena.ontology.OntClass)1