Search in sources :

Example 6 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 7 with RecipeImpl

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

the class RulesResource method getRule.

/**
     * Get a recipe from the rule base (that is the ontology that contains the rules and the recipe). <br/>
     * If the second parameter is not null then the method returns the rule in the recipe identified by that
     * parameter. <br/>
     * 
     * curl -v -X GET http://localhost:8080/kres/rule/http
     * ://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRule
     * 
     * @param uri
     *            {A string contains the IRI full name of the rule.}
     * @return Return: <br/>
     *         200 The rule is retrieved (import declarations point to KReS Services) <br/>
     *         404 The rule does not exists in the manager <br/>
     *         500 Some error occurred
     * 
     */
@GET
@Path("/recipe/{recipe:.+}")
@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, MediaType.TEXT_PLAIN })
public Response getRule(@PathParam("recipe") String recipeID, @QueryParam("rule") String ruleID, @Context HttpHeaders headers) {
    Recipe recipe;
    Rule rule;
    ResponseBuilder responseBuilder;
    try {
        URI uri = new URI(recipeID);
        if (uri.getScheme() == null) {
            recipeID = "urn:" + recipeID;
            log.info("The recipe ID is a URI without scheme. The ID is set to " + recipeID);
        }
        recipe = ruleStore.getRecipe(new IRI(recipeID));
        if (ruleID != null && !ruleID.isEmpty()) {
            rule = ruleStore.getRule(recipe, new IRI(ruleID));
            RuleList ruleList = new RuleList();
            ruleList.add(rule);
            recipe = new RecipeImpl(recipe.getRecipeID(), recipe.getRecipeDescription(), ruleList);
        }
        responseBuilder = Response.ok(recipe);
    } catch (NoSuchRecipeException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NOT_FOUND);
    } catch (RecipeConstructionException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NO_CONTENT);
    } catch (NoSuchRuleInRecipeException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NOT_FOUND);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(Status.NOT_ACCEPTABLE);
    }
    //        addCORSOrigin(servletContext, responseBuilder, headers);
    return responseBuilder.build();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RuleList(org.apache.stanbol.rules.base.api.util.RuleList) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) Rule(org.apache.stanbol.rules.base.api.Rule) URISyntaxException(java.net.URISyntaxException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with RecipeImpl

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

the class ClerezzaAdapter method main.

public static void main(String[] args) {
    RuleAdapter ruleAdapter = new ClerezzaAdapter();
    try {
        KB kb = RuleParserImpl.parse("http://sssw.org/2012/rules/", new FileInputStream("/Users/mac/Documents/CNR/SSSW2012/construct/exercise3"));
        System.out.println("Rules: " + kb.getRuleList().size());
        Recipe recipe = new RecipeImpl(new IRI("http://sssw.org/2012/rules/"), "Recipe", kb.getRuleList());
        //List<ConstructQuery> jenaRules = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.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);
        String spqral = "CONSTRUCT " + "{ ?city a <http://www.mytravels.com/Itinerary/MovieCityItinerary> . " + "   ?city <http://www.w3.org/2000/01/rdf-schema#label> ?cLabel . " + "   ?event a <http://linkedevents.org/ontology/Event> . " + "   ?event <http://linkedevents.org/ontology/atPlace> ?location . " + "   ?location <http://www.w3.org/2000/01/rdf-schema#label> ?lLabel . " + "   ?location <http://www.w3.org/2002/07/owl#sameAs> ?city" + "} " + "WHERE " + "{ " + "   ?city a <http://www.mytravels.com/Itinerary/MovieCityItinerary> . " + "   ?city <http://www.w3.org/2000/01/rdf-schema#label> ?cLabel . " + "   ?event a <http://linkedevents.org/ontology/Event> . " + "   ?event <http://linkedevents.org/ontology/atPlace> ?location . " + "   ?location <http://www.w3.org/2000/01/rdf-schema#label> ?lLabel . " + "   FILTER(?lLabel = ?cLabel) " + "}";
        Model m = ModelFactory.createDefaultModel();
        Model model = FileManager.get().loadModel("/Users/mac/Documents/CNR/SSSW2012/datasets_new/Exercise5_tmp.rdf");
        //for(ConstructQuery constructQuery : jenaRules){
        //Query query = QueryFactory.create(constructQuery.toString(), Syntax.syntaxARQ);
        Query query = QueryFactory.create(spqral, Syntax.syntaxARQ);
        QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
        //System.out.println(constructQuery.toString());
        m.add(queryExecution.execConstruct());
        //}
        FileOutputStream max = new FileOutputStream("/Users/mac/Documents/CNR/SSSW2012/datasets_new/example5.rdf");
        m.write(max);
    } 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) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) SimpleConstructQuery(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery) Recipe(org.apache.stanbol.rules.base.api.Recipe) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) QueryExecution(com.hp.hpl.jena.query.QueryExecution) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) FileOutputStream(java.io.FileOutputStream) Model(com.hp.hpl.jena.rdf.model.Model) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter) AbstractRuleAdapter(org.apache.stanbol.rules.adapters.AbstractRuleAdapter)

Example 9 with RecipeImpl

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

the class SPARQLAdpterTest 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)

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