Search in sources :

Example 6 with KB

use of org.apache.stanbol.rules.manager.KB 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 7 with KB

use of org.apache.stanbol.rules.manager.KB in project stanbol by apache.

the class RuleParserImpl method parse.

public static KB parse(String namespace, InputStream inStream) {
    kb = new KB(namespace);
    Reader reader = new InputStreamReader(inStream);
    RuleParserImpl parser = new RuleParserImpl(reader);
    try {
        parser.start();
    } catch (TokenMgrError e) {
        throw new IllegalStateException(e);
    } catch (ParseException e) {
        throw new IllegalStateException(e);
    }
    return kb;
}
Also used : InputStreamReader(java.io.InputStreamReader) KB(org.apache.stanbol.rules.manager.KB) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader)

Example 8 with KB

use of org.apache.stanbol.rules.manager.KB in project stanbol by apache.

the class SPARQLAdpterTest method setUp.

@Before
public void setUp() {
    String separator = System.getProperty("line.separator");
    String recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . values(kres:age, ?x, ?age) . endsWith(?t, \"string\") . gt(?age, sum(sub(70, ?k), ?z)) -> is(kres:OldPerson, ?x)]";
    KB kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeGood = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
    recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . same(\"Andrea\", localname(?x)) -> is(kres:OldPerson, ?x)]";
    kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeWrong = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) Before(org.junit.Before)

Aggregations

KB (org.apache.stanbol.rules.manager.KB)8 IRI (org.apache.clerezza.commons.rdf.IRI)6 RecipeImpl (org.apache.stanbol.rules.manager.RecipeImpl)6 Before (org.junit.Before)4 Query (com.hp.hpl.jena.query.Query)2 QueryExecution (com.hp.hpl.jena.query.QueryExecution)2 Model (com.hp.hpl.jena.rdf.model.Model)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 AbstractRuleAdapter (org.apache.stanbol.rules.adapters.AbstractRuleAdapter)2 Recipe (org.apache.stanbol.rules.base.api.Recipe)2 Rule (org.apache.stanbol.rules.base.api.Rule)2 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)2 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)2 InfModel (com.hp.hpl.jena.rdf.model.InfModel)1 Resource (com.hp.hpl.jena.rdf.model.Resource)1 GenericRuleReasoner (com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1