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

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


        String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "") + "#";
        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        owl = load.getStore().getOntology();
        GetRecipe rule = new GetRecipe(store);
        HashMap<IRI,String> map = rule.getRecipe(IRI
                .create("http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRecipe"));
        HashMap<IRI,String> expmap = new HashMap();
        expmap.put(
            IRI.create(ID + "MyRecipe"),
            "http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleC, http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleB, http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleA");
View Full Code Here


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

        GetRecipe rule = new GetRecipe(store);

        HashMap<IRI,String> map = rule.getAllRecipes();
        HashMap<IRI,String> expmap = new HashMap();
        expmap.put(
            IRI.create(ID + "MyRecipe"),
            "http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleC, http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleB, http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleA");
        expmap.put(
View Full Code Here

                    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);
                    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){
                        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

                    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");
View Full Code Here

    @Produces(value = {KRFormat.RDF_XML, KRFormat.RDF_JSON, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,KRFormat.MANCHESTER_OWL, KRFormat.TURTLE})
    public Response getRecipe(@PathParam("uri") String uri,
                              @Context HttpHeaders headers) throws OWLOntologyCreationException {
        try {
       
            GetRecipe rule = new GetRecipe(ruleStore);;   
            // String ID =
            // kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";

            if (uri.equals("all")) {
                Vector<IRI> recipe = rule.getGeneralRecipes();
                if (recipe == null) {
                    // The recipe does not exists in the manager
                    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 {

                    // The recipe is retrieved (import declarations point to
                    // KReS Services)
                    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);

                    for (int i = 0; i < recipe.size(); i++) {
                        OWLNamedIndividual ind = factory.getOWLNamedIndividual(recipe.get(i));
                        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> recipe = rule.getRecipe(IRI.create(uri));

                if (recipe == null) {
                    // The recipe deos not exists in the manager
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
View Full Code Here

TOP

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

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.