Search in sources :

Example 16 with Rule

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

the class RuleParserTest method testParser.

@Test
public void testParser() {
    try {
        KB kReSKB = RuleParserImpl.parse("http://incubator.apache.org/stanbol/rules/test/", kReSRule);
        if (kReSKB != null) {
            RuleList kReSRuleList = kReSKB.getRuleList();
            if (kReSRuleList != null) {
                for (Rule kReSRule : kReSRuleList) {
                    log.debug("RULE : " + kReSRule.toString());
                }
            }
            log.debug("RULE LIST IS NULL");
        } else {
            log.debug("KB IS NULL");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) KB(org.apache.stanbol.rules.manager.KB) Rule(org.apache.stanbol.rules.base.api.Rule) Test(org.junit.Test)

Example 17 with Rule

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

the class RuleParserImpl method prefix.

public final void prefix() throws ParseException {
    String nsPrefix;
    Object obj;
    Rule rule;
    nsPrefix = getVariable();
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case EQUAL:
            obj = equality();
            String prefixURI = (String) obj;
            prefixURI = prefixURI.substring(1, prefixURI.length() - 1);
            kb.addPrefix(nsPrefix, prefixURI);
            break;
        case LQUAD:
            obj = rule();
            AtomList[] atoms = (AtomList[]) obj;
            String ruleStorePrefix = kb.getPrefixURI("rmi2");
            ruleStorePrefix = ruleStorePrefix.substring(0, ruleStorePrefix.length());
            if (atoms.length == 1) {
                AtomList body = atoms[0];
                if (body.size() == 1) {
                // FIXME it previously managed SPARQL code injection.
                }
            } else {
                rule = new RuleImpl(new IRI(ruleStorePrefix + nsPrefix), nsPrefix, atoms[0], atoms[1]);
                kb.addRule(rule);
            }
            break;
        default:
            jj_la1[1] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) AtomList(org.apache.stanbol.rules.base.api.util.AtomList) RuleImpl(org.apache.stanbol.rules.manager.RuleImpl) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 18 with Rule

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

the class RuleStoreTest method getExistingRuleByIdInRecipeTest.

private void getExistingRuleByIdInRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("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();
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 19 with Rule

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

the class RuleStoreTest method getExistingRuleByNameInRecipeTest.

private void getExistingRuleByNameInRecipeTest() throws Exception {
    Recipe recipe = store.getRecipe(new IRI("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();
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NoSuchRuleInRecipeException(org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException) Recipe(org.apache.stanbol.rules.base.api.Recipe) Rule(org.apache.stanbol.rules.base.api.Rule)

Example 20 with Rule

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

the class RuleList method remove.

public boolean remove(Object o) {
    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 removed;
}
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