Search in sources :

Example 1 with Rule

use of org.apache.stanbol.rules.base.api.Rule in project stanbol by apache.

the class SPARQLAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<SPARQLObject> sparqlObjects = null;
    if (type == SPARQLObject.class) {
        RuleList ruleList = recipe.getRuleList();
        Iterator<Rule> ruleIterator = ruleList.iterator();
        sparqlObjects = new ArrayList<SPARQLObject>();
        for (int i = 0; ruleIterator.hasNext(); i++) {
            sparqlObjects.add((SPARQLObject) adaptRuleTo(ruleIterator.next(), type));
        }
    } else {
        throw new UnsupportedTypeForExportException("The SPARQL Export Provider does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) sparqlObjects;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 2 with Rule

use of org.apache.stanbol.rules.base.api.Rule in project stanbol by apache.

the class ClerezzaAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<ConstructQuery> constructQueries = null;
    if (type == ConstructQuery.class) {
        constructQueries = new ArrayList<ConstructQuery>();
        RuleList ruleList = recipe.getRuleList();
        Iterator<Rule> ruleIterator = ruleList.iterator();
        for (int i = 0; ruleIterator.hasNext(); i++) {
            constructQueries.add((ConstructQuery) adaptRuleTo(ruleIterator.next(), type));
        }
    } else {
        throw new UnsupportedTypeForExportException("The adapter for Clerezza does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) constructQueries;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) Rule(org.apache.stanbol.rules.base.api.Rule) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) SimpleConstructQuery(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery)

Example 3 with Rule

use of org.apache.stanbol.rules.base.api.Rule in project stanbol by apache.

the class SWRLAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<SWRLRule> swrlRules = null;
    if (type == SWRLRule.class) {
        RuleList ruleList = recipe.getRuleList();
        swrlRules = new ArrayList<SWRLRule>();
        if (ruleList != null && !ruleList.isEmpty()) {
            Iterator<Rule> ruleIterator = ruleList.iterator();
            while (ruleIterator.hasNext()) {
                Rule rule = ruleIterator.next();
                swrlRules.add(adaptRuleTo(rule, SWRLRule.class));
            }
        }
    } else {
        throw new UnsupportedTypeForExportException("The SPARQL Export Provider does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) swrlRules;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) Rule(org.apache.stanbol.rules.base.api.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 4 with Rule

use of org.apache.stanbol.rules.base.api.Rule in project stanbol by apache.

the class RuleList method removeAll.

public boolean removeAll(Collection<?> c) {
    if (contains(c)) {
        for (Object o : c) {
            boolean removed = false;
            for (int i = 0; i < rules.length && !removed; i++) {
                Rule semionRule = rules[i];
                if (semionRule.equals(o)) {
                    Rule[] semionRulesCopy = new Rule[rules.length - 1];
                    System.arraycopy(rules, 0, semionRulesCopy, 0, i);
                    System.arraycopy(rules, i + 1, semionRulesCopy, 0, semionRulesCopy.length - i);
                    rules = semionRulesCopy;
                    removed = true;
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : Rule(org.apache.stanbol.rules.base.api.Rule)

Example 5 with Rule

use of org.apache.stanbol.rules.base.api.Rule in project stanbol by apache.

the class RuleIterator method next.

public Rule next() {
    Rule semionRule = semionRules[currentIndex];
    currentIndex++;
    return semionRule;
}
Also used : Rule(org.apache.stanbol.rules.base.api.Rule)

Aggregations

Rule (org.apache.stanbol.rules.base.api.Rule)29 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)13 IRI (org.apache.clerezza.commons.rdf.IRI)12 NoSuchRuleInRecipeException (org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException)9 Recipe (org.apache.stanbol.rules.base.api.Recipe)8 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)5 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)5 Graph (org.apache.clerezza.commons.rdf.Graph)4 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 Path (javax.ws.rs.Path)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Literal (org.apache.clerezza.commons.rdf.Literal)2 ParseException (org.apache.clerezza.rdf.core.sparql.ParseException)2 ResultSet (org.apache.clerezza.rdf.core.sparql.ResultSet)2 SolutionMapping (org.apache.clerezza.rdf.core.sparql.SolutionMapping)2 SelectQuery (org.apache.clerezza.rdf.core.sparql.query.SelectQuery)2