Modified: incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/parse/TokenMgrError.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/parse/TokenMgrError.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/parse/TokenMgrError.java (original) +++ incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/parse/TokenMgrError.java Wed Mar 28 15:00:06 2012 @@ -1,163 +1,165 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ /* JavaCCOptions: */ package org.apache.stanbol.rules.manager.parse; /** Token Manager Error. */ -public class TokenMgrError extends Error -{ +public class TokenMgrError extends Error { - /** - * The version identifier for this Serializable class. - * Increment only if the <i>serialized</i> form of the - * class changes. - */ - private static final long serialVersionUID = 1L; - - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occurred. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt was made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * Replaces unprintable characters by their escaped (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } + /** + * The version identifier for this Serializable class. Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) { + case 0: + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); } - return retval.toString(); - } - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexical error - * curLexState : lexical state in which this error occurred - * errorLine : line number when the error occurred - * errorColumn : column number when the error occurred - * errorAfter : prefix that was seen before this error occurred - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - /** No arg constructor. */ - public TokenMgrError() { - } - - /** Constructor with message and reason. */ - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - /** Full Constructor. */ - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } + /** + * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical + * error. Parameters : EOFSeen : indicates if EOF caused the lexical error curLexState : lexical state in + * which this error occurred errorLine : line number when the error occurred errorColumn : column number + * when the error occurred errorAfter : prefix that was seen before this error occurred curchar : the + * offending character Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, + int lexState, + int errorLine, + int errorColumn, + String errorAfter, + char curChar) { + return ("Lexical error at line " + + errorLine + + ", column " + + errorColumn + + ". Encountered: " + + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + + (int) curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. For example, cases like + * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like + * : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() {} + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, + int lexState, + int errorLine, + int errorColumn, + String errorAfter, + char curChar, + int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } } /* JavaCC - OriginalChecksum=b290e2629e47f0260a40d57d321bc81b (do not edit this line) */
Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RuleStoreTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RuleStoreTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RuleStoreTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RuleStoreTest.java Wed Mar 28 15:00:06 2012 @@ -21,35 +21,34 @@ package org.apache.stanbol.rules.manager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; import java.util.Dictionary; import java.util.Hashtable; +import java.util.List; +import org.apache.clerezza.rdf.core.UriRef; import org.apache.clerezza.rdf.core.access.TcManager; -import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl; +import org.apache.clerezza.rdf.core.access.WeightedTcProvider; +import org.apache.clerezza.rdf.core.sparql.QueryEngine; +import org.apache.clerezza.rdf.jena.sparql.JenaSparqlEngine; +import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider; +import org.apache.stanbol.rules.base.api.NoSuchRuleInRecipeException; +import org.apache.stanbol.rules.base.api.Recipe; +import org.apache.stanbol.rules.base.api.Rule; import org.apache.stanbol.rules.base.api.RuleStore; -import org.apache.stanbol.rules.manager.changes.RuleStoreImpl; +import org.apache.stanbol.rules.base.api.util.RecipeList; import org.junit.After; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.util.AutoIRIMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * Set of tests for the validation of the features provided by the RuleStore. * - * @author elvio + * @author anuzzolese */ public class RuleStoreTest { @@ -58,53 +57,209 @@ public class RuleStoreTest { public RuleStoreTest() {} @BeforeClass - public static void setUpClass() throws Exception {} + public static void setUpClass() throws Exception { + class SpecialTcManager extends TcManager { + public SpecialTcManager(QueryEngine qe, WeightedTcProvider wtcp) { + super(); + bindQueryEngine(qe); + bindWeightedTcProvider(wtcp); + } + } + + QueryEngine qe = new JenaSparqlEngine(); + WeightedTcProvider wtcp = new SimpleTcProvider(); + TcManager tcm = new SpecialTcManager(qe, wtcp); + + Dictionary<String,Object> configuration = new Hashtable<String,Object>(); + store = new ClerezzaRuleStore(configuration, tcm); + } @AfterClass - public static void tearDownClass() throws Exception {} + public static void tearDownClass() throws Exception { + store = null; + } @Before public void setUp() { - Dictionary<String,Object> configuration = new Hashtable<String,Object>(); - store = new RuleStoreImpl(configuration, "./src/main/resources/RuleOntology/TestKReSOntologyRules.owl"); - blankStore = new RuleStoreImpl(configuration, ""); + } @After public void tearDown() { - store = null; - blankStore = null; + + } + + public static RuleStore store = null; + + @Test + public void createRecipeTest() throws Exception { + Recipe recipe = store.createRecipe(new UriRef( + "http://incubator.apache.com/stanbol/rules/test/recipeA"), "The text recipe named A."); + + if (recipe == null) { + Assert.fail(); + } + + log.debug("Created recipe with ID " + recipe.getRecipeID().toString()); + + } + + @Test + public void addRuleToRecipeTest() throws Exception { + Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA")); + + String separator = System.getProperty("line.separator"); + String rule = "rule1[" + separator + " is(<http://dbpedia.org/ontology/Person>, ?x) . " + separator + + " has(<http://dbpedia.org/ontology/playsInTeam>, ?x, ?y) . " + separator + + " is (<http://dbpedia.org/ontology/FootballTeam>, ?y) " + separator + " -> " + + separator + " is(<http://dbpedia.org/ontology/FootballPlayer>, ?x)" + separator + + "] . " + "rule2[" + separator + + " is(<http://dbpedia.org/ontology/Organisation>, ?x) . " + separator + + " has(<http://dbpedia.org/ontology/hasProduct>, ?x, ?y)" + separator + " -> " + + separator + " is(<http://dbpedia.org/ontology/Company>, ?x)" + separator + "]"; + + store.addRulesToRecipe(recipe, rule, "This is a test rule."); + + if (recipe == null) { + Assert.fail(); + } + + log.debug("Got recipe with ID " + recipe.getRecipeID().toString()); + } - public RuleStore store = null, blankStore = null; + @Test + public void getRecipeTest() throws Exception { + Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA")); + + if (recipe == null) { + Assert.fail(); + } else { + System.out.println("Recipe: " + recipe.toString()); + } + + log.debug("Got recipe with ID " + recipe.getRecipeID().toString()); + + } @Test - public void testKReSRuleStore() throws Exception { - OWLOntology owlmodel = store.getOntology(); - log.debug("Path for default store config is " + blankStore.getFilePath()); - assertNotNull(owlmodel); - OWLOntologyManager owlmanager = OWLManager.createOWLOntologyManager(); - owlmanager.addIRIMapper(new AutoIRIMapper(new File("./src/main/resources/RuleOntology/"), false)); - String src = ""; + public void getNotExistingRuleByNameInRecipeTest() throws Exception { + Recipe recipe = store.getRecipe(new UriRef("http://incubator.apache.com/stanbol/rules/test/recipeA")); + try { - src = "./src/main/resources/RuleOntology/TestKReSOntologyRules.owl"; - assertEquals(owlmodel, owlmanager.loadOntologyFromOntologyDocument(new File(src))); - } catch (Exception e) { - try { - src = "./src/main/resources/RuleOntology/OffLineKReSOntologyRules.owl"; - assertEquals(owlmodel, owlmanager.loadOntologyFromOntologyDocument(new File(src))); - } catch (OWLOntologyCreationException ex) { - fail("OWLOntologyCreationException caught when loading from " + src); - } + recipe.getRule("ruleX"); + Assert.fail(); + } catch (NoSuchRuleInRecipeException e) { + Assert.assertTrue(true); + } + + } + + @Test + public 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); + } + + } + + @Test + public 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(); + } + + } + + @Test + public 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(); + } + + } + + @Test + public void findRecipesByDescriptionTest() throws Exception { + List<Recipe> recipes = store.findRecipesByDescription("recipe named A"); + if (recipes.isEmpty()) { + Assert.fail(); + } else { + Assert.assertTrue(true); + } + + } + + @Test + public void findRulesByDescriptionTest() throws Exception { + List<Rule> rules = store.findRulesByDescription("a test rule."); + if (rules.isEmpty()) { + Assert.fail(); + } else { + Assert.assertTrue(true); } } @Test - public void testKReSRuleStore_2() throws Exception { - OWLOntology owlmodel = blankStore.getOntology(); - log.debug("Path for default store config is " + blankStore.getFilePath()); - assertNotNull(owlmodel); - assertTrue(!owlmodel.isEmpty()); + public void findRulesByNameTest() throws Exception { + List<Rule> rules = store.findRulesByName("1"); + + if (rules.isEmpty()) { + Assert.fail(); + } else { + Assert.assertTrue(true); + } + } + + @Test + public 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); + + } + + @Test + public void removeRecipeTest() throws Exception { + + 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); + + Assert.assertNotSame(initialRecipes, finalRecipes); + } } \ No newline at end of file Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/AtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/AtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/AtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/AtomTest.java Wed Mar 28 15:00:06 2012 @@ -19,48 +19,26 @@ package org.apache.stanbol.rules.manager import static org.junit.Assert.fail; -import org.apache.stanbol.rules.base.api.JenaClauseEntry; -import org.apache.stanbol.rules.base.api.JenaVariableMap; import org.apache.stanbol.rules.base.api.RuleAtom; -import org.apache.stanbol.rules.manager.JenaVariableMapImpl; import org.junit.Before; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.SWRLAtom; public abstract class AtomTest { protected OWLDataFactory factory; - protected JenaVariableMap jenaVariableMap; - @Before public void init() { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); this.factory = manager.getOWLDataFactory(); - this.jenaVariableMap = new JenaVariableMapImpl(); } protected void execTest(RuleAtom ruleAtom) { - String stanbolSyntax = ruleAtom.toKReSSyntax(); + String stanbolSyntax = ruleAtom.toString(); if (stanbolSyntax == null) { - fail(this.getClass().getCanonicalName() + " does not produce any rule in Stanbo syntax."); - } - - String sparql = ruleAtom.toSPARQL().getObject(); - if (sparql == null) { - fail(this.getClass().getCanonicalName() + " does not produce any rule as SPARQL CONSTRUCT."); - } - - SWRLAtom swrlAtom = ruleAtom.toSWRL(factory); - if (swrlAtom == null) { - fail(this.getClass().getCanonicalName() + " does not produce any rule in SWRL."); - } - - JenaClauseEntry jenaEntry = ruleAtom.toJenaClauseEntry(jenaVariableMap); - if (jenaEntry == null) { - fail(this.getClass().getCanonicalName() + " does not produce any rule in JENA."); + fail(this.getClass().getCanonicalName() + " does not produce any rule in Stanbol syntax."); } } Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/ClassAtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/ClassAtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/ClassAtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/ClassAtomTest.java Wed Mar 28 15:00:06 2012 @@ -20,7 +20,6 @@ package org.apache.stanbol.rules.manager import java.net.URI; import org.apache.stanbol.rules.base.api.RuleAtom; -import org.apache.stanbol.rules.base.api.URIResource; import org.junit.Before; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -28,8 +27,8 @@ import org.semanticweb.owlapi.model.OWLO public class ClassAtomTest extends AtomTest { - private URIResource classResource; - private URIResource argument1; + private IObjectAtom classResource; + private IObjectAtom argument1; @Before public void setup() { Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/DatavaluedPropertyAtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/DatavaluedPropertyAtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/DatavaluedPropertyAtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/DatavaluedPropertyAtomTest.java Wed Mar 28 15:00:06 2012 @@ -21,7 +21,6 @@ import java.net.URI; import java.net.URISyntaxException; import org.apache.stanbol.rules.base.api.RuleAtom; -import org.apache.stanbol.rules.base.api.URIResource; import org.junit.Before; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -31,13 +30,13 @@ import com.hp.hpl.jena.vocabulary.XSD; public class DatavaluedPropertyAtomTest extends AtomTest { - private URIResource datatypeProperty; - private URIResource argument1; + private IObjectAtom datatypeProperty; + private IObjectAtom argument1; // argument2 - private Object variable; - private Object literal; - private Object typedLiteral; + private RuleAtom variable; + private RuleAtom literal; + private RuleAtom typedLiteral; @Before public void setup() { @@ -50,10 +49,11 @@ public class DatavaluedPropertyAtomTest variable = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#x"), false); - literal = "some text"; + literal = new StringAtom("some text"); try { - typedLiteral = new TypedLiteralAtom(3.0, new ResourceAtom(new URI(XSD.xdouble.getURI()))); + typedLiteral = new TypedLiteralAtom(new NumberAtom("3.0"), new ResourceAtom(new URI( + XSD.xdouble.getURI()))); } catch (URISyntaxException e) { e.printStackTrace(); } Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/GreaterThanAtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/GreaterThanAtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/GreaterThanAtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/GreaterThanAtomTest.java Wed Mar 28 15:00:06 2012 @@ -30,14 +30,14 @@ import com.hp.hpl.jena.vocabulary.XSD; public class GreaterThanAtomTest extends AtomTest { - private Object variable1; - private Object variable2; + private ExpressionAtom variable1; + private ExpressionAtom variable2; - private Object literal1; - private Object literal2; + private ExpressionAtom literal1; + private ExpressionAtom literal2; - private Object typedLiteral1; - private Object typedLiteral2; + private ExpressionAtom typedLiteral1; + private ExpressionAtom typedLiteral2; @Before public void setup() { @@ -49,12 +49,14 @@ public class GreaterThanAtomTest extends variable2 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#y"), false); - literal1 = "some text"; - literal2 = "some other text"; + literal1 = new StringAtom("some text"); + literal2 = new StringAtom("some other text"); try { - typedLiteral1 = new TypedLiteralAtom(3.0, new ResourceAtom(new URI(XSD.xdouble.getURI()))); - typedLiteral2 = new TypedLiteralAtom(5.0, new ResourceAtom(new URI(XSD.xdouble.getURI()))); + typedLiteral1 = new TypedLiteralAtom(new NumberAtom("3.0"), new ResourceAtom(new URI( + XSD.xdouble.getURI()))); + typedLiteral2 = new TypedLiteralAtom(new NumberAtom("5.0"), new ResourceAtom(new URI( + XSD.xdouble.getURI()))); } catch (URISyntaxException e) { e.printStackTrace(); } Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/IndividualPropertyAtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/IndividualPropertyAtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/IndividualPropertyAtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/IndividualPropertyAtomTest.java Wed Mar 28 15:00:06 2012 @@ -20,7 +20,6 @@ package org.apache.stanbol.rules.manager import java.net.URI; import org.apache.stanbol.rules.base.api.RuleAtom; -import org.apache.stanbol.rules.base.api.URIResource; import org.junit.Before; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -28,9 +27,9 @@ import org.semanticweb.owlapi.model.OWLO public class IndividualPropertyAtomTest extends AtomTest { - private URIResource objectProperty; - private URIResource argument1; - private URIResource argument2; + private IObjectAtom objectProperty; + private IObjectAtom argument1; + private IObjectAtom argument2; @Before public void setup() { Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/LessThanAtomTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/LessThanAtomTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/LessThanAtomTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/atoms/LessThanAtomTest.java Wed Mar 28 15:00:06 2012 @@ -30,14 +30,14 @@ import com.hp.hpl.jena.vocabulary.XSD; public class LessThanAtomTest extends AtomTest { - private Object variable1; - private Object variable2; + private ExpressionAtom variable1; + private ExpressionAtom variable2; - private Object literal1; - private Object literal2; + private ExpressionAtom literal1; + private ExpressionAtom literal2; - private Object typedLiteral1; - private Object typedLiteral2; + private ExpressionAtom typedLiteral1; + private ExpressionAtom typedLiteral2; @Before public void setup() { @@ -49,12 +49,14 @@ public class LessThanAtomTest extends At variable2 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#y"), false); - literal1 = "some text"; - literal2 = "some other text"; + literal1 = new StringAtom("some text"); + literal2 = new StringAtom("some other text"); try { - typedLiteral1 = new TypedLiteralAtom(3.0, new ResourceAtom(new URI(XSD.xdouble.getURI()))); - typedLiteral2 = new TypedLiteralAtom(5.0, new ResourceAtom(new URI(XSD.xdouble.getURI()))); + typedLiteral1 = new TypedLiteralAtom(new NumberAtom("3.0"), new ResourceAtom(new URI( + XSD.xdouble.getURI()))); + typedLiteral2 = new TypedLiteralAtom(new NumberAtom("5.0"), new ResourceAtom(new URI( + XSD.xdouble.getURI()))); } catch (URISyntaxException e) { e.printStackTrace(); } Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/parse/RuleParserTest.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/parse/RuleParserTest.java?rev=1306390&r1=1306389&r2=1306390&view=diff ============================================================================== --- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/parse/RuleParserTest.java (original) +++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/parse/RuleParserTest.java Wed Mar 28 15:00:06 2012 @@ -1,19 +1,19 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.stanbol.rules.manager.parse; import org.apache.stanbol.rules.base.api.Rule; @@ -24,44 +24,43 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * * @author andrea.nuzzolese - * + * */ public class RuleParserTest { - private static String kReSRule; - - private Logger log = LoggerFactory.getLogger(getClass()); - - @BeforeClass - public static void setup() { - kReSRule = "ProvaParent = <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#> . " + - "rule1[ has(ProvaParent:hasParent, ?x, ?y) . has(ProvaParent:hasBrother, ?y, ?z) -> " + - "has(ProvaParent:hasUncle, ?x, ?z) ]"; - } - - @Test - public void testParser(){ - try{ - KB kReSKB = RuleParserImpl.parse(kReSRule); - if(kReSKB != null){ - RuleList kReSRuleList = kReSKB.getkReSRuleList(); - 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(); - } - } - + private static String kReSRule; + + private Logger log = LoggerFactory.getLogger(getClass()); + + @BeforeClass + public static void setup() { + kReSRule = "/* example of " + System.getProperty("line.separator") + "rule */" + + "ProvaParent = <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#> . " + + "rule1[ has(ProvaParent:hasParent, ?x, ?y) . has(ProvaParent:hasBrother, ?y, ?z) -> " + + "has(ProvaParent:hasUncle, ?x, ?z) ]"; + } + + @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(); + } + } + }
