Package org.apache.stanbol.rules.base.api

Examples of org.apache.stanbol.rules.base.api.Recipe


        }

    }

    private void getNotExistingRuleByIdInRecipeTest() throws Exception {
        Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));

        try {
            recipe.getRule(new UriRef("http://foo.org/ruleX"));
            Assert.fail();
        } catch (NoSuchRuleInRecipeException e) {
            Assert.assertTrue(true);
        }
View Full Code Here


        }

    }

    private void getExistingRuleByIdInRecipeTest() throws Exception {
        Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));

        try {
            Rule rule = recipe.getRule(recipe.listRuleIDs().get(0));
            Assert.assertNotNull(rule);
        } catch (NoSuchRuleInRecipeException e) {
            Assert.fail();
        }
View Full Code Here

        }

    }

    private void getExistingRuleByNameInRecipeTest() throws Exception {
        Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));

        try {
            Rule rule = recipe.getRule(recipe.listRuleNames().get(0));
            Assert.assertNotNull(rule);
        } catch (NoSuchRuleInRecipeException e) {
            Assert.fail();
        }
View Full Code Here

            Assert.assertTrue(true);
        }
    }

    private void removeRuleInRecipeTest() throws Exception {
        Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));

        String tmp = recipe.toString();
        Rule rule = recipe.getRule(recipe.listRuleNames().get(0));

        store.removeRule(recipe, rule);

        Recipe recipe2 = store
                .getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));

        String tmp2 = recipe2.toString();

        Assert.assertNotSame(tmp, tmp2);

    }
View Full Code Here

        RecipeList recipeListInitial = store.listRecipes();
        Recipe[] initialRecipes = new Recipe[recipeListInitial.size()];
        initialRecipes = recipeListInitial.toArray(initialRecipes);

        Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA"));
        store.removeRecipe(recipe);

        RecipeList recipeListFinal = store.listRecipes();
        Recipe[] finalRecipes = new Recipe[recipeListInitial.size()];
        finalRecipes = recipeListFinal.toArray(finalRecipes);
View Full Code Here

              log.info("[start] Prepare rules for OWLApi ");

           // If recipe exists, return it as a list of SWRL rules
              rules = new ArrayList<SWRLRule>();
              try {
                  Recipe recipe = null;
                  synchronized (store) {
                      try {
              recipe = store.getRecipe(new UriRef(recipeId));
            } catch (RecipeConstructionException e) {
              log.error("An error occurred while generating the recipe.", e);
            }                   
                  }
                  log.debug("Recipe is: {}", recipe);
                 
                  /*
                   * We ask to the adapter manager to get the right adapter in order to transform
                   * recipes into SWRLRule objects.
                   */
                  RuleAdapter adapter;
          try {
            adapter = adapterManager.getAdapter(recipe, SWRLRule.class);
            rules = (List<SWRLRule>) adapter.adaptTo(recipe, SWRLRule.class);
          } catch (UnavailableRuleObjectException e) {
            log.error(e.getMessage(), e);
          } catch (RuleAtomCallExeption e) {
            log.error(e.getMessage(), e);
          } catch (UnsupportedTypeForExportException e) {
            log.error(e.getMessage(), e);
          }
                 
                 
                  /*
                  RuleList ruleList = recipe.getRuleList();
                  log.debug("RuleList is: {}",ruleList);
                  for(org.apache.stanbol.rules.base.api.Rule r : ruleList ){
                      SWRLRule swrl = r.toSWRL(OWLManager.getOWLDataFactory());
                      log.debug("Prepared rule: {}",swrl);
                      rules.add(swrl);
                  }*/
              } catch (NoSuchRecipeException e) {
                  log.error("Recipe {} does not exists", recipeId);
                  throw new IOException(e);
              }

              long end = System.currentTimeMillis();
              log.info("[end] Prepared {} rules for OWLApi in {} ms.", rules.size(), (end - start));
             
          }
          if(rules == null){
              log.error("No rules have been loaded");
              throw new IOException("No rules loaded");
          }
          final Iterator<SWRLRule> iterator = Collections.unmodifiableList(rules).iterator();
          return new Iterator<T>(){

              @Override
              public boolean hasNext() {
                  return iterator.hasNext();
              }

              @SuppressWarnings("unchecked")
              @Override
              public T next() {
                  return (T) iterator.next();
              }

              @Override
              public void remove() {
                  log.error("Cannot remove items from this iterator. This may be cused by an error in the program");
                  throw new UnsupportedOperationException("Cannot remove items from this iterator");
              }
             
          };
    case Jena:
      List<Rule> jenaRules = null;
          if (recipeId != null) {
              long start = System.currentTimeMillis();
              log.info("[start] Prepare rules for Jena ");

              try {
                  Recipe recipe = null;
                  synchronized (store) {
                      try {
              recipe = store.getRecipe(new UriRef(recipeId));
            } catch (RecipeConstructionException e) {
              log.error("An error occurred while generating the recipe.", e);
View Full Code Here

             * We pass the ontology and the recipe IRI to the Refactor that returns the refactored graph
             * expressed by using the given vocabulary.
             *
             * To perform the refactoring of the ontology to a given vocabulary we use the Stanbol Refactor.
             */
            Recipe recipe = ruleStore.getRecipe(new UriRef(engineConfiguration.getRecipeId()));

            log.debug("Recipe {} contains {} rules.", recipe, recipe.getRuleList().size());
            log.debug("The ontology to be refactor is {}", ontology);

            TripleCollection tc = refactorer.graphRefactoring(
                OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(ontology), recipe);

View Full Code Here

        UriRef recipeId = new UriRef(engineConfiguration.getRecipeId());
        try {
            // step 1: get all the rules
            log.debug("Recipe {} and its associated rules will be removed from the rule store.", recipeId);
            Recipe recipe = null;
            try {
                recipe = ruleStore.getRecipe(recipeId);
            } catch (RecipeConstructionException e) {
                log.error(e.getMessage());
            }
View Full Code Here

        /*
         * The first thing to do is to create a recipe in the rule store that can be used by the engine to
         * refactor the enhancement graphs.
         */
        String recipeId = engineConfiguration.getRecipeId();
        Recipe recipe = null;
        try {
            recipe = ruleStore.createRecipe(new UriRef(recipeId), null);
        } catch (AlreadyExistingRecipeException e1) {
            log.error("A recipe with ID {} already exists in the store.", recipeId);
        }
View Full Code Here

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

TOP

Related Classes of org.apache.stanbol.rules.base.api.Recipe

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.