Package org.apache.stanbol.rules.manager.changes

Examples of org.apache.stanbol.rules.manager.changes.GetRule


                       KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL})
    public Response getRule(@PathParam("uri") String uri, @Context HttpHeaders headers) {

        try {

            GetRule recipe = new GetRule(ruleStore);
            if (uri.equals("all")) {

                HashMap<IRI,String> rule = recipe.getAllRules();
                Iterator<IRI> keys = rule.keySet().iterator();

                if (rule.isEmpty()){
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }else {

                    OWLOntology onto = ruleStore.getOntology();
                    OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
                        onto.getOntologyID());
                    OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();

                    Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
                    List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
                    OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();

                    while (importedonto.hasNext()) {
                        OWLOntology auxonto = importedonto.next();
                        additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
                                .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
                    }

                    if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);

                    while (keys.hasNext()) {
                        OWLNamedIndividual ind = factory.getOWLNamedIndividual(keys.next());
                        Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
                        newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
                    }

                    // try {
                    // OWLManager.createOWLOntologyManager().saveOntology(
                    // newmodel,
                    // newmodel.getOWLOntologyManager()
                    // .getOntologyFormat(newmodel),
                    // System.out);
                    // } catch (OWLOntologyStorageException e) {
                    // // TODO Auto-generated catch block
                    // e.printStackTrace();
                    // }

                    ResponseBuilder rb = Response.ok(newmodel);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

            } else {

                HashMap<IRI,String> rule = recipe.getRule(IRI.create(uri));

                if (rule == null) {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
View Full Code Here


    @Path("/of-recipe/{uri:.+}")
    @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
                       KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
    public Response getRulesOfRecipe(@PathParam("uri") String recipeURI,@Context HttpHeaders headers) {

        GetRule kReSGetRule = new GetRule(ruleStore);
        String recipeURIEnc;
        try {
            recipeURIEnc = URLEncoder.encode(
                "http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyRecipeA", "UTF-8");
            log.debug("Recipe: " + recipeURIEnc);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        log.debug("Recipe IRI: " + IRI.create(recipeURI));
        OWLOntology ontology = kReSGetRule.getAllRulesOfARecipe(IRI.create(recipeURI));

        ResponseBuilder rb = Response.ok(ontology);
        MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
        if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
        addCORSOrigin(servletContext, rb, headers);
View Full Code Here

            rule = rule.replace(" ", "").trim();

            // The rule is already inside the rule store
            if ((kres_syntax == null)) {
                // Get the rule
                GetRule inrule = new GetRule(ruleStore);
                this.map = inrule.getRule(IRI.create(rule));

                if (map == null) {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Get the recipe
                GetRecipe getrecipe = new GetRecipe(ruleStore);
                this.map = getrecipe.getRecipe(IRI.create(recipe));
                if (map != null) {
                    this.desc = getrecipe.getDescription(IRI.create(recipe));
                    if (desc == null) Response.status(Status.NOT_FOUND).build();
                } else {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                String[] sequence = map.get(IRI.create(recipe)).split(",");
                Vector<IRI> ruleseq = new Vector();
                if (!sequence[0].isEmpty()) for (String seq : sequence)
                    ruleseq.add(IRI.create(seq.replace(" ", "").trim()));

                // Add the new rule to the end
                ruleseq.add(IRI.create(rule));
                // Remove the old recipe
                RemoveRecipe remove = new RemoveRecipe(ruleStore);
                boolean ok = remove.removeRecipe(IRI.create(recipe));

                if (!ok){
                    ResponseBuilder rb = Response.status(Status.CONFLICT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Add the recipe with the new rule
                AddRecipe newadd = new AddRecipe(ruleStore);
                ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);

                if (ok) {
                    ruleStore.saveOntology();
                    ResponseBuilder rb = Response.ok();
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                } else {
                    ResponseBuilder rb = Response.status(Status.NO_CONTENT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }
            }

            // The rule is added to the store and to the recipe
            if ((kres_syntax != null) & (description != null)) {
                // Get the rule
                AddRule inrule = new AddRule(ruleStore);
                boolean ok = inrule.addRule(IRI.create(rule), kres_syntax, description);
                if (!ok) {
                    log.error("Problem to add: " + rule);
                    ResponseBuilder rb = Response.status(Status.CONFLICT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
View Full Code Here

            // Delete from the recipe
            if ((recipe != null) && (rule != null)) {
                recipe = recipe.replace(" ", "").trim();
                rule = rule.replace(" ", "").trim();
                // Get the rule
                GetRule getrule = new GetRule(ruleStore);
                this.map = getrule.getRule(IRI.create(rule));
                if (map == null) {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Get the recipe
                GetRecipe getrecipe = new GetRecipe(ruleStore);
                this.map = getrecipe.getRecipe(IRI.create(recipe));
                if (map != null) {
                    this.desc = getrecipe.getDescription(IRI.create(recipe));
                    if (desc.isEmpty()){
                        //return Response.status(Status.NOT_FOUND).build();
                       
                        ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                        rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                        addCORSOrigin(servletContext, rb, headers);
                        return rb.build();
                    }
                } else {
                   
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Remove rule from recipe
                RemoveRule remove = new RemoveRule(ruleStore);
                ok = remove.removeRuleFromRecipe(IRI.create(rule), IRI.create(recipe));

                if (ok) {
                    ruleStore.saveOntology();
                    ResponseBuilder rb = Response.ok();
                    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                } else {
                    ResponseBuilder rb = Response.status(Status.NO_CONTENT);
                    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }
            }

            // Delete from the ontology
            if ((recipe == null) && (rule != null)) {
                rule = rule.replace(" ", "").trim();
                // Get the rule
                GetRule getrule = new GetRule(ruleStore);
                this.map = getrule.getRule(IRI.create(rule));
                if (map == null) {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        owl = load.getStore().getOntology();

        GetRule rule = new GetRule(store);
        HashMap<IRI,String> map = rule.getRule("MyRuleC");
        HashMap<IRI,String> expmap = new HashMap();
        expmap.put(IRI.create(ID + "MyRuleC"), "MyRuleCBody -> MyRuleCHead");
        if (map != null) {
            assertEquals(expmap, map);
            // TODO review the generated test code and remove the default call to fail.
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        owl = load.getStore().getOntology();

        GetRule rule = new GetRule(store);

        HashMap<IRI,String> map = rule.getAllRules();
        HashMap<IRI,String> expmap = new HashMap();
        // MyRuleX
        String rulex = "PREFIX var http://kres.iksproject.eu/rules# ."
                       + "PREFIX dbs http://andriry.altervista.org/tesiSpecialistica/dbs_l1.owl# ."
                       + "PREFIX lmm http://www.ontologydesignpatterns.org/ont/lmm/LMM_L1.owl# ."
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        owl = load.getStore().getOntology();

        GetRule rule = new GetRule(store);
        Vector<IRI> vector = rule.getRuleUsage(IRI.create(ID + "MyRuleC"));

        if (vector != null) {
            assertEquals(2, vector.size());
            // TODO review the generated test code and remove the default call to fail.
        } else {
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        owl = load.getStore().getOntology();

        GetRule rule = new GetRule(store);
        Vector<IRI> vector = rule.getRuleUsage(IRI.create(ID + "MyRuleC"));

        if (vector != null) {
            assertEquals(2, vector.size());
            // TODO review the generated test code and remove the default call to fail.
        } else {
View Full Code Here

TOP

Related Classes of org.apache.stanbol.rules.manager.changes.GetRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.