Search in sources :

Example 1 with RecipeImpl

use of org.apache.stanbol.rules.manager.RecipeImpl in project stanbol by apache.

the class JenaAdpterTest method setUp.

@Before
public void setUp() {
    String separator = System.getProperty("line.separator");
    String recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . values(kres:age, ?x, ?age) . endsWith(?t, \"string\") . gt(?age, sum(sub(70, ?k), ?z)) -> is(kres:OldPerson, ?x)]";
    KB kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeGood = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
    recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . same(\"Andrea\", localname(?x)) -> is(kres:OldPerson, ?x)]";
    kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeWrong = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) Before(org.junit.Before)

Example 2 with RecipeImpl

use of org.apache.stanbol.rules.manager.RecipeImpl in project stanbol by apache.

the class ClerezzaAdpterTest method setUp.

@Before
public void setUp() {
    String separator = System.getProperty("line.separator");
    String recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . values(kres:age, ?x, ?age) . endsWith(?t, \"string\") . gt(?age, sum(sub(70, ?k), ?z)) -> is(kres:OldPerson, ?x)]";
    KB kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeGood = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
    recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . same(\"Andrea\", localname(?x)) -> is(kres:OldPerson, ?x)]";
    kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeWrong = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) Before(org.junit.Before)

Example 3 with RecipeImpl

use of org.apache.stanbol.rules.manager.RecipeImpl in project stanbol by apache.

the class JenaAdapter method main.

public static void main(String[] args) {
    RuleAdapter ruleAdapter = new JenaAdapter();
    try {
        KB kb = RuleParserImpl.parse("http://sssw.org/2012/rules/", new FileInputStream("/Users/mac/Documents/CNR/SSSW2012/rules/exercise1"));
        System.out.println("Rules: " + kb.getRuleList().size());
        Recipe recipe = new RecipeImpl(new IRI("http://sssw.org/2012/rules/"), "Recipe", kb.getRuleList());
        List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = (List<com.hp.hpl.jena.reasoner.rulesys.Rule>) ruleAdapter.adaptTo(recipe, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
        String rules = "[ Exercise1: (http://dbpedia.org/resource/Madrid http://dbpedia.org/ontology/locationOf ?location) (?location rdf:type http://dbpedia.org/ontology/Museum) (?location http://dbpedia.org/ontology/numberOfVisitors ?visitors) greaterThan(?visitors '2000000'^^http://www.w3.org/2001/XMLSchema#integer) -> (?location rdf:type http://www.mytravels.com/Itinerary/MadridItinerary) ]";
        //List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = com.hp.hpl.jena.reasoner.rulesys.Rule.parseRules(rules);
        for (com.hp.hpl.jena.reasoner.rulesys.Rule jenaRule : jenaRules) {
            System.out.println(jenaRule.toString());
        }
        Model m = ModelFactory.createDefaultModel();
        Resource configuration = m.createResource();
        configuration.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid");
        //Model model = FileManager.get().loadModel("/Users/mac/Documents/workspaceMyStanbol/sssw2012/events.rdf");
        Model model = FileManager.get().loadModel("/Users/mac/Documents/CNR/SSSW2012/datasets_new/Exercise1.rdf");
        //GenericRuleReasoner reasoner = new GenericRuleReasoner(jenaRules);
        //GenericRuleReasoner reasoner = new GenericRuleReasoner(com.hp.hpl.jena.reasoner.rulesys.Rule.parseRules(rules));
        GenericRuleReasoner reasoner = new GenericRuleReasoner(jenaRules);
        // not needed in RDFS case
        reasoner.setOWLTranslation(true);
        reasoner.setTransitiveClosureCaching(true);
        InfModel infModel = ModelFactory.createInfModel(reasoner, model);
        infModel.prepare();
        infModel.getDeductionsModel().write(System.out);
        //String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MovieCityMuseums> }";
        //String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/CityEventItinerary> }";
        String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MadridItinerary> }";
        //String sparql = "select * where {?s a <http://linkedevents.org/ontology/cazzo> }"; 
        //String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MovieCityItinerary> }";
        Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
        QueryExecution queryExecution = QueryExecutionFactory.create(query, infModel);
        com.hp.hpl.jena.query.ResultSet resultSet = queryExecution.execSelect();
        ResultSetFormatter.out(System.out, resultSet);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RuleAtomCallExeption e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnavailableRuleObjectException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedTypeForExportException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Query(com.hp.hpl.jena.query.Query) Recipe(org.apache.stanbol.rules.base.api.Recipe) FileNotFoundException(java.io.FileNotFoundException) InfModel(com.hp.hpl.jena.rdf.model.InfModel) QueryExecution(com.hp.hpl.jena.query.QueryExecution) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) KB(org.apache.stanbol.rules.manager.KB) List(java.util.List) ArrayList(java.util.ArrayList) AtomList(org.apache.stanbol.rules.base.api.util.AtomList) RuleList(org.apache.stanbol.rules.base.api.util.RuleList) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Resource(com.hp.hpl.jena.rdf.model.Resource) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) FileInputStream(java.io.FileInputStream) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) InfModel(com.hp.hpl.jena.rdf.model.InfModel) Model(com.hp.hpl.jena.rdf.model.Model) GenericRuleReasoner(com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner) Rule(org.apache.stanbol.rules.base.api.Rule) AbstractRuleAdapter(org.apache.stanbol.rules.adapters.AbstractRuleAdapter) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter)

Example 4 with RecipeImpl

use of org.apache.stanbol.rules.manager.RecipeImpl in project stanbol by apache.

the class SWRLAdpterTest method setUp.

@Before
public void setUp() {
    String separator = System.getProperty("line.separator");
    String recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . values(kres:age, ?x, ?age) . gt(?age, sum(sub(70, ?k), ?z)) -> is(kres:OldPerson, ?x)]";
    KB kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeGood = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
    recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . same(\"Andrea\", localname(?x)) -> is(kres:OldPerson, ?x)]";
    kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeWrong = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) Before(org.junit.Before)

Example 5 with RecipeImpl

use of org.apache.stanbol.rules.manager.RecipeImpl in project stanbol by apache.

the class RefactorResource method doRefactoring.

/**
     * Utility method that groups all calls to the refactorer.
     * 
     * @param input
     * @param recipe
     * @return
     * @throws OWLOntologyCreationException
     * @throws RefactoringException
     */
private OWLOntology doRefactoring(InputStream input, KB kb) throws OWLOntologyCreationException, RefactoringException {
    if (kb == null)
        return null;
    RuleList ruleList = kb.getRuleList();
    if (ruleList == null)
        return null;
    Recipe actualRecipe = new RecipeImpl(null, null, ruleList);
    // Parse the input ontology
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology inputOntology = manager.loadOntologyFromOntologyDocument(input);
    Graph tripleCollection = refactorer.graphRefactoring(OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(inputOntology), actualRecipe);
    // Refactor
    return OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(tripleCollection);
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) Graph(org.apache.clerezza.commons.rdf.Graph) Recipe(org.apache.stanbol.rules.base.api.Recipe) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Aggregations

RecipeImpl (org.apache.stanbol.rules.manager.RecipeImpl)9 IRI (org.apache.clerezza.commons.rdf.IRI)8 KB (org.apache.stanbol.rules.manager.KB)6 Recipe (org.apache.stanbol.rules.base.api.Recipe)5 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)4 Before (org.junit.Before)4 Rule (org.apache.stanbol.rules.base.api.Rule)3 Query (com.hp.hpl.jena.query.Query)2 QueryExecution (com.hp.hpl.jena.query.QueryExecution)2 Model (com.hp.hpl.jena.rdf.model.Model)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 AbstractRuleAdapter (org.apache.stanbol.rules.adapters.AbstractRuleAdapter)2 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)2