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

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


        ServiceReference serviceReference = event.getServiceReference();

        Object service = componentContext.getBundleContext().getService(serviceReference);

        if (service instanceof RuleAdapter) {
            RuleAdapter RuleAdapter = (RuleAdapter) componentContext.getBundleContext().getService(
                serviceReference);

            switch (event.getType()) {
                case ServiceEvent.MODIFIED:

                    try {
                        removeRuleAdapter(RuleAdapter);
                        log.info("Removed Rule Adapter " + RuleAdapter.getClass().getCanonicalName());

                        addRuleAdapter(RuleAdapter);
                        log.info("Added Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }
                    break;
                case ServiceEvent.REGISTERED:
                    try {
                        addRuleAdapter(RuleAdapter);
                        log.info("Added Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }

                    break;
                case ServiceEvent.UNREGISTERING:
                    try {
                        removeRuleAdapter(RuleAdapter);
                        log.info("Removed Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }
                    break;
View Full Code Here


            return false;
        }
    }
   
    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 UriRef("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){
View Full Code Here

        }
    }
   
   
    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 UriRef("http://sssw.org/2012/rules/"), "Recipe", kb.getRuleList());
           
View Full Code Here

        Recipe recipe;
        try {
            try {
                recipe = ruleStore.getRecipe(recipeID);

                RuleAdapter ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
                List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe,
                    ConstructQuery.class);

                MGraph mGraph = tcManager.createMGraph(refactoredOntologyID);
                for (ConstructQuery constructQuery : constructQueries) {
                    mGraph.addAll(this.sparqlConstruct(constructQuery, datasetID));
View Full Code Here

        Recipe recipe;
        try {
            recipe = ruleStore.getRecipe(recipeID);

            RuleAdapter ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);

            List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe,
                ConstructQuery.class);

            unionMGraph = new SimpleMGraph();

            for (ConstructQuery constructQuery : constructQueries) {
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public TripleCollection graphRefactoring(TripleCollection inputGraph, Recipe recipe) throws RefactoringException {

        RuleAdapter ruleAdapter;
        try {
            ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
            List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe,
                ConstructQuery.class);

            for(ConstructQuery constructQuery : constructQueries){
                System.out.println(constructQuery.toString());
            }
View Full Code Here

        ServiceReference serviceReference = event.getServiceReference();

        Object service = componentContext.getBundleContext().getService(serviceReference);

        if (service instanceof RuleAdapter) {
            RuleAdapter RuleAdapter = (RuleAdapter) componentContext.getBundleContext().getService(
                serviceReference);

            switch (event.getType()) {
                case ServiceEvent.MODIFIED:

                    try {
                        removeRuleAdapter(RuleAdapter);
                        log.info("Removed Rule Adapter " + RuleAdapter.getClass().getCanonicalName());

                        addRuleAdapter(RuleAdapter);
                        log.info("Added Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }
                    break;
                case ServiceEvent.REGISTERED:
                    try {
                        addRuleAdapter(RuleAdapter);
                        log.info("Added Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }

                    break;
                case ServiceEvent.UNREGISTERING:
                    try {
                        removeRuleAdapter(RuleAdapter);
                        log.info("Removed Rule Adapter " + RuleAdapter.getClass().getCanonicalName());
                    } catch (UnavailableRuleObjectException e) {
                        log.error("Unavailable Rule Object " + e.getMessage());
                    }
                    break;
View Full Code Here

                 
                  /*
                   * 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);
            }                   
                  }
                 
                 
                  if(recipe != null){
                    log.debug("Recipe is: {}", recipe);
                   
                    /*
                     * We ask to the adapter manager to get the right adapter in order to transform
                     * recipes into Jena Rule objects.
                     */
                    RuleAdapter adapter;
            try {
              adapter = adapterManager.getAdapter(recipe, Rule.class);
              jenaRules = (List<Rule>) adapter.adaptTo(recipe, Rule.class);
            } catch (UnavailableRuleObjectException e) {
              log.error(e.getMessage(), e);
            } catch (RuleAtomCallExeption e) {
              log.error(e.getMessage(), e);
            } catch (UnsupportedTypeForExportException e) {
View Full Code Here

        recipe = "urn:" + recipe;
        log.info("The recipe ID is a URI without scheme. The ID is set to " + recipe);
      }
           
            Recipe rcp = ruleStore.getRecipe(new UriRef(recipe));
            RuleAdapter adapter = adapterManager.getAdapter(rcp, classToLoad);

            Object adaptedRecipe = adapter.adaptTo(rcp, classToLoad);

            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("recipe", rcp.getRecipeID().toString());
                jsonObject.put("adaptedTo", format);
View Full Code Here

TOP

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

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.