You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/11/02 19:41:39 UTC
svn commit: r1196752 [3/3] - in /incubator/stanbol/trunk:
explanation/core/src/test/java/org/apache/stanbol/explanation/impl/
ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/ontology/
ontologymanager/ontonet/src/mai...
Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/GetRuleTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/GetRuleTest.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/GetRuleTest.java (original)
+++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/GetRuleTest.java Wed Nov 2 18:41:36 2011
@@ -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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -30,6 +30,7 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
+import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.rules.base.api.RuleStore;
@@ -45,33 +46,31 @@ import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
/**
- *
+ *
* @author elvio
*/
public class GetRuleTest {
- public GetRuleTest() {
- }
+ public GetRuleTest() {}
@BeforeClass
- public static void setUpClass() throws Exception {
- }
+ public static void setUpClass() throws Exception {}
@AfterClass
- public static void tearDownClass() throws Exception {
- }
+ public static void tearDownClass() throws Exception {}
@Before
public void setUp() {
- Dictionary<String, Object> configuration = new Hashtable<String, Object>();
- onm = new ONManagerImpl(null,null,configuration);
- store = new RuleStoreImpl(onm, configuration,"./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ Dictionary<String,Object> configuration = new Hashtable<String,Object>();
+ onm = new ONManagerImpl((TcManager) null, null, configuration);
+ store = new RuleStoreImpl(onm, configuration,
+ "./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
}
@After
public void tearDown() {
- store = null;
- onm = null;
+ store = null;
+ onm = null;
}
public RuleStore store = null;
@@ -82,22 +81,23 @@ public class GetRuleTest {
*/
@Test
public void testGetRule() {
-// RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
OWLOntology owl = store.getOntology();
- String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "")+"#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "") + "#";
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
owl = load.getStore().getOntology();
-
+
GetRule rule = new GetRule(store);
- HashMap<IRI, String> map = rule.getRule("MyRuleC");
- HashMap<IRI, String> expmap = new HashMap();
- expmap.put(IRI.create(ID+"MyRuleC"), "MyRuleCBody -> MyRuleCHead");
- if(map!=null){
- assertEquals(expmap, map);
- // TODO review the generated test code and remove the default call to fail.
- }else{
- fail("Some error occurs for method GetRule of KReSGetRule");
+ HashMap<IRI,String> map = rule.getRule("MyRuleC");
+ HashMap<IRI,String> expmap = new HashMap();
+ expmap.put(IRI.create(ID + "MyRuleC"), "MyRuleCBody -> MyRuleCHead");
+ if (map != null) {
+ assertEquals(expmap, map);
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some error occurs for method GetRule of KReSGetRule");
}
}
@@ -106,45 +106,45 @@ public class GetRuleTest {
*/
@Test
public void testGetAllRule() {
-// RuleStoreImpl store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStoreImpl store = new
+ // RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
OWLOntology owl = store.getOntology();
- String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "")+"#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "") + "#";
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
owl = load.getStore().getOntology();
GetRule rule = new GetRule(store);
-
- HashMap<IRI, String> map = rule.getAllRules();
- HashMap<IRI, String> expmap = new HashMap();
- //MyRuleX
- String rulex = "PREFIX var http://kres.iksproject.eu/rules# ." +
- "PREFIX dbs http://andriry.altervista.org/tesiSpecialistica/dbs_l1.owl# ." +
- "PREFIX lmm http://www.ontologydesignpatterns.org/ont/lmm/LMM_L1.owl# ." +
- "rule1[dbs:Table(?x) -> lmm:Meaning(?x)]";
-
- expmap.put(IRI.create(ID+"MyRuleA"), "MyRuleABody -> MyRuleAHead");
- expmap.put(IRI.create(ID+"MyRuleB"), "MyRuleBBody -> MyRuleBHead");
- expmap.put(IRI.create(ID+"MyRuleC"), "MyRuleCBody -> MyRuleCHead");
- expmap.put(IRI.create(ID+"MyRuleD"), "MyRuleDBody -> MyRuleDHead");
- expmap.put(IRI.create(ID+"MyRuleE"), "MyRuleEBody -> MyRuleEHead");
- expmap.put(IRI.create(ID+"MyRuleF"), "MyRuleFBody -> MyRuleFHead");
- expmap.put(IRI.create(ID+"MyRuleX"),rulex);
- if(map!=null){
+ HashMap<IRI,String> map = rule.getAllRules();
+ HashMap<IRI,String> expmap = new HashMap();
+ // MyRuleX
+ String rulex = "PREFIX var http://kres.iksproject.eu/rules# ."
+ + "PREFIX dbs http://andriry.altervista.org/tesiSpecialistica/dbs_l1.owl# ."
+ + "PREFIX lmm http://www.ontologydesignpatterns.org/ont/lmm/LMM_L1.owl# ."
+ + "rule1[dbs:Table(?x) -> lmm:Meaning(?x)]";
+
+ expmap.put(IRI.create(ID + "MyRuleA"), "MyRuleABody -> MyRuleAHead");
+ expmap.put(IRI.create(ID + "MyRuleB"), "MyRuleBBody -> MyRuleBHead");
+ expmap.put(IRI.create(ID + "MyRuleC"), "MyRuleCBody -> MyRuleCHead");
+ expmap.put(IRI.create(ID + "MyRuleD"), "MyRuleDBody -> MyRuleDHead");
+ expmap.put(IRI.create(ID + "MyRuleE"), "MyRuleEBody -> MyRuleEHead");
+ expmap.put(IRI.create(ID + "MyRuleF"), "MyRuleFBody -> MyRuleFHead");
+ expmap.put(IRI.create(ID + "MyRuleX"), rulex);
+
+ if (map != null) {
Iterator<IRI> key = map.keySet().iterator();
int m = 0;
- while(key.hasNext()){
+ while (key.hasNext()) {
IRI k = key.next();
- if(expmap.keySet().contains(k))
- if(expmap.get(k).equals(map.get(k)))
- m++;
+ if (expmap.keySet().contains(k)) if (expmap.get(k).equals(map.get(k))) m++;
}
- assertEquals(expmap.size(),m);
- // TODO review the generated test code and remove the default call to fail.
- }else{
- fail("Some error occurs for method GetAllRule of KReSGetRule");
+ assertEquals(expmap.size(), m);
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some error occurs for method GetAllRule of KReSGetRule");
}
}
@@ -153,43 +153,46 @@ public class GetRuleTest {
*/
@Test
public void testGetRuleUsage() {
-// RuleStoreImpl store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStoreImpl store = new
+ // RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
OWLOntology owl = store.getOntology();
- String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "")+"#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "") + "#";
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
owl = load.getStore().getOntology();
GetRule rule = new GetRule(store);
Vector<IRI> vector = rule.getRuleUsage(IRI.create(ID + "MyRuleC"));
-
- if(vector!=null){
- assertEquals(2, vector.size());
- // TODO review the generated test code and remove the default call to fail.
- }else{
- fail("Some error occurs for method getRuleUsage of KReSGetRule");
+
+ if (vector != null) {
+ assertEquals(2, vector.size());
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some error occurs for method getRuleUsage of KReSGetRule");
}
}
-
+
@Test
public void testGetRulesOfRecipe() {
-// RuleStoreImpl store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStoreImpl store = new
+ // RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
OWLOntology owl = store.getOntology();
- String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "")+"#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ String ID = owl.getOntologyID().toString().replace("<", "").replace(">", "") + "#";
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
owl = load.getStore().getOntology();
GetRule rule = new GetRule(store);
Vector<IRI> vector = rule.getRuleUsage(IRI.create(ID + "MyRuleC"));
-
- if(vector!=null){
- assertEquals(2, vector.size());
- // TODO review the generated test code and remove the default call to fail.
- }else{
- fail("Some error occurs for method getRuleUsage of KReSGetRule");
+
+ if (vector != null) {
+ assertEquals(2, vector.size());
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some error occurs for method getRuleUsage of KReSGetRule");
}
}
-
}
\ No newline at end of file
Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/LoadRuleFileTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/LoadRuleFileTest.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/LoadRuleFileTest.java (original)
+++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/LoadRuleFileTest.java Wed Nov 2 18:41:36 2011
@@ -29,6 +29,7 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
+import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.rules.base.api.RuleStore;
@@ -80,13 +81,13 @@ public class LoadRuleFileTest {
@Test
public void testKReSLoadRuleFile() throws OWLOntologyStorageException {
Dictionary<String,Object> configuration = new Hashtable<String,Object>();
- ONManager onm = new ONManagerImpl(null, null, configuration);
+ ONManager onm = new ONManagerImpl((TcManager) null, null, configuration);
Dictionary<String,Object> configuration2 = new Hashtable<String,Object>();
// configuration2.put(RuleStoreImpl.RULE_ONTOLOGY, "");
configuration2.put(RuleStore.RULE_NAMESPACE, "http://kres.iks-project.eu/ontology/meta/rmi.owl#");
RuleStore store = new RuleStoreImpl(onm, configuration2,
"./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
- RuleStore newstore = new RuleStoreImpl(new ONManagerImpl(null, null, configuration),
+ RuleStore newstore = new RuleStoreImpl(new ONManagerImpl((TcManager) null, null, configuration),
configuration2, store.getOntology());
// Load the example file
LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRecipeTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRecipeTest.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRecipeTest.java (original)
+++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRecipeTest.java Wed Nov 2 18:41:36 2011
@@ -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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.rules.base.api.RuleStore;
@@ -43,33 +44,31 @@ import org.semanticweb.owlapi.model.OWLO
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
/**
- *
+ *
* @author elvio
*/
public class RemoveRecipeTest {
- public RemoveRecipeTest() {
- }
+ public RemoveRecipeTest() {}
@BeforeClass
- public static void setUpClass() throws Exception {
- }
+ public static void setUpClass() throws Exception {}
@AfterClass
- public static void tearDownClass() throws Exception {
- }
+ public static void tearDownClass() throws Exception {}
@Before
public void setUp() {
- Dictionary<String, Object> configuration = new Hashtable<String, Object>();
- onm = new ONManagerImpl(null,null,configuration);
- store = new RuleStoreImpl(onm, configuration,"./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ Dictionary<String,Object> configuration = new Hashtable<String,Object>();
+ onm = new ONManagerImpl((TcManager) null, null, configuration);
+ store = new RuleStoreImpl(onm, configuration,
+ "./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
}
@After
public void tearDown() {
- store = null;
- onm = null;
+ store = null;
+ onm = null;
}
public RuleStore store = null;
@@ -80,22 +79,25 @@ public class RemoveRecipeTest {
*/
@Test
public void testRemoveRule_String() throws OWLOntologyCreationException {
-// RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
String owlID = store.getOntology().getOntologyID().toString().replace("<", "").replace(">", "") + "#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
OWLOntology owlstart = load.getStore().getOntology();
- String recipeName = owlID+"MyRecipe";
+ String recipeName = owlID + "MyRecipe";
RemoveRecipe instance = new RemoveRecipe(load.getStore());
boolean expResult = true;
boolean result = instance.removeRecipe(IRI.create(recipeName));
OWLOntology owlend = instance.getStore().getOntology();
- if(result){
- assertEquals(expResult,(owlstart.getAxiomCount()>owlend.getAxiomCount()));
- // TODO review the generated test code and remove the default call to fail.
- }else{fail("Some errors occur with removeRule of KReSRemoveRule.");}
+ if (result) {
+ assertEquals(expResult, (owlstart.getAxiomCount() > owlend.getAxiomCount()));
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some errors occur with removeRule of KReSRemoveRule.");
+ }
}
/**
@@ -103,23 +105,24 @@ public class RemoveRecipeTest {
*/
@Test
public void testRemoveRuleName_String() throws OWLOntologyCreationException {
-// RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ // RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
OWLOntology owlstart = load.getStore().getOntology();
- String recipeName ="MyRecipe";
+ String recipeName = "MyRecipe";
RemoveRecipe instance = new RemoveRecipe(load.getStore());
boolean expResult = true;
boolean result = instance.removeRecipe(recipeName);
OWLOntology owlend = instance.getStore().getOntology();
- if(result){
- assertEquals(expResult,(owlstart.getAxiomCount()>owlend.getAxiomCount()));
- // TODO review the generated test code and remove the default call to fail.
- }else{fail("Some errors occur with removeRule of KReSRemoveRule.");}
+ if (result) {
+ assertEquals(expResult, (owlstart.getAxiomCount() > owlend.getAxiomCount()));
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some errors occur with removeRule of KReSRemoveRule.");
+ }
}
-
-
}
\ No newline at end of file
Modified: incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRuleTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRuleTest.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRuleTest.java (original)
+++ incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/RemoveRuleTest.java Wed Nov 2 18:41:36 2011
@@ -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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.rules.base.api.RuleStore;
@@ -43,33 +44,31 @@ import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
/**
- *
+ *
* @author elvio
*/
public class RemoveRuleTest {
- public RemoveRuleTest() {
- }
+ public RemoveRuleTest() {}
@BeforeClass
- public static void setUpClass() throws Exception {
- }
+ public static void setUpClass() throws Exception {}
@AfterClass
- public static void tearDownClass() throws Exception {
- }
+ public static void tearDownClass() throws Exception {}
@Before
public void setUp() {
- Dictionary<String, Object> configuration = new Hashtable<String, Object>();
- onm = new ONManagerImpl(null,null,configuration);
- store = new RuleStoreImpl(onm, configuration,"./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ Dictionary<String,Object> configuration = new Hashtable<String,Object>();
+ onm = new ONManagerImpl((TcManager) null, null, configuration);
+ store = new RuleStoreImpl(onm, configuration,
+ "./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
}
@After
public void tearDown() {
- store = null;
- onm = null;
+ store = null;
+ onm = null;
}
public RuleStore store = null;
@@ -80,20 +79,23 @@ public class RemoveRuleTest {
*/
@Test
public void testRemoveRule() {
-// RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
-
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
+ // RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
AddRule rule = new AddRule(load.getStore());
- rule.addRule("MyRuleProva","Body -> Head",null);
+ rule.addRule("MyRuleProva", "Body -> Head", null);
String ruleName = "MyRuleProva";
RemoveRule instance = new RemoveRule(rule.getStore());
boolean expResult = true;
boolean result = instance.removeRule(ruleName);
- if(result){
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- }else{fail("Some errors occur with removeRule of KReSRemoveRule.");}
+ if (result) {
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some errors occur with removeRule of KReSRemoveRule.");
+ }
}
/**
@@ -101,21 +103,24 @@ public class RemoveRuleTest {
*/
@Test
public void testRemoveSingleRule() throws OWLOntologyStorageException {
-// RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
+ // RuleStore store = new RuleStoreImpl("./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
String owlID = store.getOntology().getOntologyID().toString().replace("<", "").replace(">", "") + "#";
- //Load the example file
- LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",store);
- IRI rule = IRI.create(owlID+"MyRuleB");
- IRI recipe = IRI.create(owlID+"MyRecipe");
+ // Load the example file
+ LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
+ store);
+ IRI rule = IRI.create(owlID + "MyRuleB");
+ IRI recipe = IRI.create(owlID + "MyRecipe");
RemoveRule instance = new RemoveRule(load.getStore());
boolean expResult = true;
boolean result = instance.removeRuleFromRecipe(rule, recipe);
-
- if(result){
+
+ if (result) {
assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- }else{fail("Some errors occur with removeRule of KReSRemoveRule.");}
+ // TODO review the generated test code and remove the default call to fail.
+ } else {
+ fail("Some errors occur with removeRule of KReSRemoveRule.");
+ }
}
}
\ No newline at end of file
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=1196752&r1=1196751&r2=1196752&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 Nov 2 18:41:36 2011
@@ -30,6 +30,7 @@ import java.io.File;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import org.apache.stanbol.rules.base.api.RuleStore;
import org.apache.stanbol.rules.manager.changes.RuleStoreImpl;
@@ -65,9 +66,10 @@ public class RuleStoreTest {
@Before
public void setUp() {
Dictionary<String,Object> configuration = new Hashtable<String,Object>();
- store = new RuleStoreImpl(new ONManagerImpl(null, null, configuration), configuration,
+ store = new RuleStoreImpl(new ONManagerImpl((TcManager) null, null, configuration), configuration,
"./src/main/resources/RuleOntology/TestKReSOntologyRules.owl");
- blankStore = new RuleStoreImpl(new ONManagerImpl(null, null, configuration), configuration, "");
+ blankStore = new RuleStoreImpl(new ONManagerImpl((TcManager) null, null, configuration),
+ configuration, "");
}
@After
Modified: incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RecipeResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RecipeResource.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RecipeResource.java (original)
+++ incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RecipeResource.java Wed Nov 2 18:41:36 2011
@@ -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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -22,7 +22,6 @@
package org.apache.stanbol.rules.web.resources;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -45,13 +44,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.format.KRFormat;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
-import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
-import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
import org.apache.stanbol.rules.base.api.RuleStore;
import org.apache.stanbol.rules.manager.changes.AddRecipe;
import org.apache.stanbol.rules.manager.changes.GetRecipe;
@@ -85,7 +81,6 @@ public class RecipeResource extends Base
private Logger log = LoggerFactory.getLogger(getClass());
private RuleStoreImpl kresRuleStore;
- private ClerezzaOntologyStorage storage;
/**
* To get the RuleStoreImpl where are stored the rules and the recipes
@@ -94,9 +89,9 @@ public class RecipeResource extends Base
* {To get the context where the REST service is running.}
*/
public RecipeResource(@Context ServletContext servletContext) {
- this.kresRuleStore = (RuleStoreImpl) ContextHelper.getServiceFromContext(RuleStore.class, servletContext);
+ this.kresRuleStore = (RuleStoreImpl) ContextHelper.getServiceFromContext(RuleStore.class,
+ servletContext);
this.onm = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
- this.storage = onm.getOntologyStore();
}
/**
@@ -113,11 +108,13 @@ public class RecipeResource extends Base
*/
@GET
@Path("/{uri:.+}")
- @Produces(value = {KRFormat.RDF_XML, KRFormat.RDF_JSON, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,KRFormat.MANCHESTER_OWL, KRFormat.TURTLE})
+ @Produces(value = {KRFormat.RDF_XML, KRFormat.RDF_JSON, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+ KRFormat.MANCHESTER_OWL, KRFormat.TURTLE})
public Response getRecipe(@PathParam("uri") String uri) throws OWLOntologyCreationException {
try {
-
- GetRecipe rule = new GetRecipe(kresRuleStore);;
+
+ GetRecipe rule = new GetRecipe(kresRuleStore);
+ ;
// String ID =
// kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";
@@ -248,8 +245,10 @@ public class RecipeResource extends Base
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
- public Response addRecipe(@FormParam(value = "recipe") String recipe, @FormParam(value = "description") String description) {
+ @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+ KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
+ public Response addRecipe(@FormParam(value = "recipe") String recipe,
+ @FormParam(value = "description") String description) {
try {
Modified: incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleResource.java?rev=1196752&r1=1196751&r2=1196752&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleResource.java (original)
+++ incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleResource.java Wed Nov 2 18:41:36 2011
@@ -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.
+ */
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@@ -24,7 +24,6 @@ package org.apache.stanbol.rules.web.res
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -47,13 +46,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.format.KRFormat;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
-import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
-import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
import org.apache.stanbol.rules.base.api.RuleStore;
import org.apache.stanbol.rules.manager.changes.AddRecipe;
import org.apache.stanbol.rules.manager.changes.AddRule;
@@ -74,442 +70,407 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ *
* @author elvio, andrea.nuzzolese
*
*/
@Path("/rule")
-public class RuleResource extends BaseStanbolResource{
+public class RuleResource extends BaseStanbolResource {
- protected ONManager onm;
- protected ClerezzaOntologyStorage storage;
+ protected ONManager onm;
- private Logger log = LoggerFactory.getLogger(getClass());
+ private Logger log = LoggerFactory.getLogger(getClass());
- private RuleStore kresRuleStore;
- private HashMap<IRI, String> map;
+ private RuleStore kresRuleStore;
+ private HashMap<IRI,String> map;
private String desc;
- /**
+ /**
* To get the RuleStoreImpl where are stored the rules and the recipes
- *
- * @param servletContext
- * {To get the context where the REST service is running.}
+ *
+ * @param servletContext
+ * {To get the context where the REST service is running.}
*/
- public RuleResource(@Context ServletContext servletContext){
- this.kresRuleStore = (RuleStoreImpl) ContextHelper.getServiceFromContext(RuleStore.class, servletContext);
+ public RuleResource(@Context ServletContext servletContext) {
+ this.kresRuleStore = (RuleStoreImpl) ContextHelper.getServiceFromContext(RuleStore.class,
+ servletContext);
this.onm = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
- this.storage = this.onm.getOntologyStore();
}
- /**
- * Get a rule from the rule base (that is the ontology that contains the
- * rules and the recipe). curl -v -X GET
- * http://localhost:8080/kres/rule/http
- * ://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRule
- *
- * @param uri
- * {A string contains the IRI full name of the rule.}
+ /**
+ * Get a rule from the rule base (that is the ontology that contains the rules and the recipe). curl -v -X
+ * GET http://localhost:8080/kres/rule/http ://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRule
+ *
+ * @param uri
+ * {A string contains the IRI full name of the rule.}
* @return Return: <br/>
- * 200 The rule is retrieved (import declarations point to KReS
- * Services) <br/>
- * 404 The rule does not exists in the manager <br/>
- * 500 Some error occurred
- *
+ * 200 The rule is retrieved (import declarations point to KReS Services) <br/>
+ * 404 The rule does not exists in the manager <br/>
+ * 500 Some error occurred
+ *
*/
@GET
@Path("/{uri:.+}")
- @Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL})
- public Response getRule(@PathParam("uri") String uri){
-
- try{
-
- GetRule recipe = new GetRule(kresRuleStore);
- if(uri.equals("all")){
-
- HashMap<IRI, String> rule = recipe.getAllRules();
- Iterator<IRI> keys = rule.keySet().iterator();
-
- if(rule==null){
- return Response.status(Status.NOT_FOUND).build();
- }else{
-
- OWLOntology onto = kresRuleStore.getOntology();
- OWLOntology newmodel = OWLManager
- .createOWLOntologyManager().createOntology(
- onto.getOntologyID());
- OWLDataFactory factory = onto.getOWLOntologyManager()
- .getOWLDataFactory();
-
- Iterator<OWLOntology> importedonto = onto
- .getDirectImports().iterator();
- List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
- OWLDataFactory auxfactory = onto.getOWLOntologyManager()
- .getOWLDataFactory();
-
- while(importedonto.hasNext()){
- OWLOntology auxonto = importedonto.next();
- additions.add(new AddImport(newmodel, auxfactory
- .getOWLImportsDeclaration(auxonto
- .getOWLOntologyManager()
- .getOntologyDocumentIRI(auxonto))));
- }
+ @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.RDF_JSON,
+ KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL})
+ public Response getRule(@PathParam("uri") String uri) {
- if(!additions.isEmpty())
- newmodel.getOWLOntologyManager()
- .applyChanges(additions);
-
- while(keys.hasNext()){
- OWLNamedIndividual ind = factory
- .getOWLNamedIndividual(keys.next());
- Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
- newmodel.getOWLOntologyManager()
- .addAxioms(newmodel, ax);
- }
+ try {
-// try {
-// OWLManager.createOWLOntologyManager().saveOntology(
-// newmodel,
-// newmodel.getOWLOntologyManager()
-// .getOntologyFormat(newmodel),
-// System.out);
-// } catch (OWLOntologyStorageException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
+ GetRule recipe = new GetRule(kresRuleStore);
+ if (uri.equals("all")) {
- return Response.ok(newmodel).build();
- }
+ HashMap<IRI,String> rule = recipe.getAllRules();
+ Iterator<IRI> keys = rule.keySet().iterator();
- }else{
+ if (rule == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ } else {
- HashMap<IRI, String> rule = recipe.getRule(IRI.create(uri));
-
- if(rule==null){
- return Response.status(Status.NOT_FOUND).build();
- }else{
- OWLOntology onto = kresRuleStore.getOntology();
-
- OWLDataFactory factory = onto.getOWLOntologyManager()
- .getOWLDataFactory();
- OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI
- .create(uri));
- Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
- OWLOntology newmodel = OWLManager
- .createOWLOntologyManager().createOntology(
- onto.getOntologyID());
-
- Iterator<OWLOntology> importedonto = onto
- .getDirectImports().iterator();
- List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
- OWLDataFactory auxfactory = onto.getOWLOntologyManager()
- .getOWLDataFactory();
-
- while(importedonto.hasNext()){
- OWLOntology auxonto = importedonto.next();
- additions.add(new AddImport(newmodel, auxfactory
- .getOWLImportsDeclaration(auxonto
- .getOWLOntologyManager()
- .getOntologyDocumentIRI(auxonto))));
- }
+ OWLOntology onto = kresRuleStore.getOntology();
+ OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
+ onto.getOntologyID());
+ OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+ Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
+ List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+ OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+ while (importedonto.hasNext()) {
+ OWLOntology auxonto = importedonto.next();
+ additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
+ .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+ }
+
+ if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);
+
+ while (keys.hasNext()) {
+ OWLNamedIndividual ind = factory.getOWLNamedIndividual(keys.next());
+ Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+ newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
+ }
+
+ // try {
+ // OWLManager.createOWLOntologyManager().saveOntology(
+ // newmodel,
+ // newmodel.getOWLOntologyManager()
+ // .getOntologyFormat(newmodel),
+ // System.out);
+ // } catch (OWLOntologyStorageException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+
+ return Response.ok(newmodel).build();
+ }
+
+ } else {
+
+ HashMap<IRI,String> rule = recipe.getRule(IRI.create(uri));
- if(!additions.isEmpty())
- newmodel.getOWLOntologyManager()
- .applyChanges(additions);
-
- newmodel.getOWLOntologyManager().addAxioms(newmodel,ax);
-
-// try {
-// OWLManager.createOWLOntologyManager().saveOntology(
-// newmodel,
-// newmodel.getOWLOntologyManager()
-// .getOntologyFormat(newmodel),
-// System.out);
-// } catch (OWLOntologyStorageException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
+ if (rule == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ } else {
+ OWLOntology onto = kresRuleStore.getOntology();
+
+ OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();
+ OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(uri));
+ Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+ OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
+ onto.getOntologyID());
+
+ Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
+ List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+ OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+ while (importedonto.hasNext()) {
+ OWLOntology auxonto = importedonto.next();
+ additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
+ .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+ }
+
+ if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);
+
+ newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
+
+ // try {
+ // OWLManager.createOWLOntologyManager().saveOntology(
+ // newmodel,
+ // newmodel.getOWLOntologyManager()
+ // .getOntologyFormat(newmodel),
+ // System.out);
+ // } catch (OWLOntologyStorageException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
- return Response.ok(newmodel).build();
+ return Response.ok(newmodel).build();
+ }
+ }
+ } catch (Exception e) {
+ // Some error occurred
+ throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
- }
- }catch (Exception e){
- //Some error occurred
- throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
- }
}
-
+
@GET
@Path("/of-recipe/{uri:.+}")
- @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
- public Response getRulesOfRecipe(@PathParam("uri") String recipeURI){
-
- GetRule kReSGetRule = new GetRule(kresRuleStore);
- String recipeURIEnc;
- try {
- recipeURIEnc = URLEncoder
- .encode(
- "http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyRecipeA",
- "UTF-8");
- log.debug("Recipe: "+recipeURIEnc);
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- log.debug("Recipe IRI: "+IRI.create(recipeURI));
- OWLOntology ontology = kReSGetRule.getAllRulesOfARecipe(IRI
- .create(recipeURI));
-
- return Response.ok(ontology).build();
-
+ @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+ KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
+ public Response getRulesOfRecipe(@PathParam("uri") String recipeURI) {
+
+ GetRule kReSGetRule = new GetRule(kresRuleStore);
+ String recipeURIEnc;
+ try {
+ recipeURIEnc = URLEncoder.encode(
+ "http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyRecipeA", "UTF-8");
+ log.debug("Recipe: " + recipeURIEnc);
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ log.debug("Recipe IRI: " + IRI.create(recipeURI));
+ OWLOntology ontology = kReSGetRule.getAllRulesOfARecipe(IRI.create(recipeURI));
+
+ return Response.ok(ontology).build();
+
}
- /**
- * To add a rule to a recipe at the end of the sequence. curl -v -X POST -F
- * "recipe=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaParentRecipe"
- * -F "rule=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaRuleNEW"
- * -F "kres-syntax=body -> head" -F "description=prova di aggiunta regola"
- * http://localhost:8080/kres/rule
- *
- * @param recipe
- * {A string contains the IRI of the recipe where to add the
- * rule}
- * @param rule
- * {A string contains the IRI of the rule to be added at the
- * recipe}
- * @param kres_syntax
- * {A string contains the body and the head of the kres rule. If
- * not specified the rule is search in the Ontology otherwise is
- * added as new.}
- * @param description
- * {A string contains a description of the rule}
+ /**
+ * To add a rule to a recipe at the end of the sequence. curl -v -X POST -F
+ * "recipe=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaParentRecipe" -F
+ * "rule=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaRuleNEW" -F "kres-syntax=body -> head" -F
+ * "description=prova di aggiunta regola" http://localhost:8080/kres/rule
+ *
+ * @param recipe
+ * {A string contains the IRI of the recipe where to add the rule}
+ * @param rule
+ * {A string contains the IRI of the rule to be added at the recipe}
+ * @param kres_syntax
+ * {A string contains the body and the head of the kres rule. If not specified the rule is
+ * search in the Ontology otherwise is added as new.}
+ * @param description
+ * {A string contains a description of the rule}
* @return Return: <br/>
- * 200 The rule has been added <br/>
- * 204 The rule has not been added <br/>
- * 400 The rule and recipe are not specified<br/>
- * 404 Recipe or rule not found<br/>
- * 409 The rule has not been added<br/>
- * 500 Some error occurred
+ * 200 The rule has been added <br/>
+ * 204 The rule has not been added <br/>
+ * 400 The rule and recipe are not specified<br/>
+ * 404 Recipe or rule not found<br/>
+ * 409 The rule has not been added<br/>
+ * 500 Some error occurred
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
- public Response addRuleToRecipe(@FormParam(value = "recipe") String recipe,
- @FormParam(value = "rule") String rule,
- @FormParam(value = "kres-syntax") String kres_syntax,
- @FormParam(value = "description") String description) {
-
-// System.err.println("recipe "+recipe);
-// System.err.println("rule " + rule);
-// System.err.println("kres-syntax "+kres_syntax);
-// System.err.println("description "+description);
-//
-// return Response.ok().build();
-
- try{
+ @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+ KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
+ public Response addRuleToRecipe(@FormParam(value = "recipe") String recipe,
+ @FormParam(value = "rule") String rule,
+ @FormParam(value = "kres-syntax") String kres_syntax,
+ @FormParam(value = "description") String description) {
+
+ // System.err.println("recipe "+recipe);
+ // System.err.println("rule " + rule);
+ // System.err.println("kres-syntax "+kres_syntax);
+ // System.err.println("description "+description);
+ //
+ // return Response.ok().build();
+
+ try {
- if((recipe==null)&&(rule==null)){
+ if ((recipe == null) && (rule == null)) {
return Response.status(Status.BAD_REQUEST).build();
- }
+ }
- recipe = recipe.replace(" ","").trim();
- rule = rule.replace(" ","").trim();
+ recipe = recipe.replace(" ", "").trim();
+ rule = rule.replace(" ", "").trim();
- //The rule is already inside the rule store
- if((kres_syntax==null)){
- //Get the rule
- GetRule inrule = new GetRule(kresRuleStore);
- this.map = inrule.getRule(IRI.create(rule));
-
- if(map==null){
- return Response.status(Status.NOT_FOUND).build();
- }
+ // The rule is already inside the rule store
+ if ((kres_syntax == null)) {
+ // Get the rule
+ GetRule inrule = new GetRule(kresRuleStore);
+ this.map = inrule.getRule(IRI.create(rule));
- //Get the recipe
- GetRecipe getrecipe = new GetRecipe(kresRuleStore);
- this.map = getrecipe.getRecipe(IRI.create(recipe));
- if(map!=null){
- this.desc = getrecipe.getDescription(IRI.create(recipe));
- if(desc==null)
- Response.status(Status.NOT_FOUND).build();
- }else{
- return Response.status(Status.NOT_FOUND).build();
- }
+ if (map == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ // Get the recipe
+ GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+ this.map = getrecipe.getRecipe(IRI.create(recipe));
+ if (map != null) {
+ this.desc = getrecipe.getDescription(IRI.create(recipe));
+ if (desc == null) Response.status(Status.NOT_FOUND).build();
+ } else {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ String[] sequence = map.get(IRI.create(recipe)).split(",");
+ Vector<IRI> ruleseq = new Vector();
+ if (!sequence[0].isEmpty()) for (String seq : sequence)
+ ruleseq.add(IRI.create(seq.replace(" ", "").trim()));
+
+ // Add the new rule to the end
+ ruleseq.add(IRI.create(rule));
+ // Remove the old recipe
+ RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
+ boolean ok = remove.removeRecipe(IRI.create(recipe));
+
+ if (!ok) return Response.status(Status.CONFLICT).build();
+
+ // Add the recipe with the new rule
+ AddRecipe newadd = new AddRecipe(kresRuleStore);
+ ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
- String[] sequence = map.get(IRI.create(recipe)).split(",");
- Vector<IRI> ruleseq = new Vector();
- if(!sequence[0].isEmpty())
- for(String seq : sequence)
- ruleseq.add(IRI.create(seq.replace(" ","").trim()));
-
- //Add the new rule to the end
- ruleseq.add(IRI.create(rule));
- //Remove the old recipe
- RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
- boolean ok = remove.removeRecipe(IRI.create(recipe));
-
- if(!ok)
- return Response.status(Status.CONFLICT).build();
-
- //Add the recipe with the new rule
- AddRecipe newadd = new AddRecipe(kresRuleStore);
- ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
-
- if(ok){
+ if (ok) {
kresRuleStore.saveOntology();
return Response.ok().build();
- }else{
+ } else {
return Response.status(Status.NO_CONTENT).build();
+ }
}
- }
- //The rule is added to the store and to the recipe
- if((kres_syntax!=null)&(description!=null)){
- //Get the rule
- AddRule inrule = new AddRule(kresRuleStore);
- boolean ok = inrule.addRule(IRI.create(rule), kres_syntax, description);
- if(!ok){
- log.error("Problem to add: "+rule);
- System.err.println("PROBLEM TO ADD: "+rule);
- return Response.status(Status.CONFLICT).build();
- }
-
- //Get the recipe
- GetRecipe getrecipe = new GetRecipe(kresRuleStore);
- this.map = getrecipe.getRecipe(IRI.create(recipe));
- if(map!=null){
- this.desc = getrecipe.getDescription(IRI.create(recipe));
-
- if(desc==null)
- return Response.status(Status.NOT_FOUND).build();
- }else{
- return Response.status(Status.NOT_FOUND).build();
- }
+ // The rule is added to the store and to the recipe
+ if ((kres_syntax != null) & (description != null)) {
+ // Get the rule
+ AddRule inrule = new AddRule(kresRuleStore);
+ boolean ok = inrule.addRule(IRI.create(rule), kres_syntax, description);
+ if (!ok) {
+ log.error("Problem to add: " + rule);
+ System.err.println("PROBLEM TO ADD: " + rule);
+ return Response.status(Status.CONFLICT).build();
+ }
+
+ // Get the recipe
+ GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+ this.map = getrecipe.getRecipe(IRI.create(recipe));
+ if (map != null) {
+ this.desc = getrecipe.getDescription(IRI.create(recipe));
- String[] sequence = map.get(IRI.create(recipe)).split(",");
- Vector<IRI> ruleseq = new Vector();
- if(!sequence[0].isEmpty())
- for(String seq : sequence)
- ruleseq.add(IRI.create(seq.replace(" ","").trim()));
-
- //Add the new rule to the end
- ruleseq.add(IRI.create(rule));
- //Remove the old recipe
- RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
- ok = remove.removeRecipe(IRI.create(recipe));
- if(!ok){
- System.err.println("ERROR TO REMOVE OLD RECIPE: "+recipe);
- return Response.status(Status.CONFLICT).build();
- }
+ if (desc == null) return Response.status(Status.NOT_FOUND).build();
+ } else {
+ return Response.status(Status.NOT_FOUND).build();
+ }
- //Add the recipe with the new rule
- AddRecipe newadd = new AddRecipe(kresRuleStore);
- ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
- if(ok){
+ String[] sequence = map.get(IRI.create(recipe)).split(",");
+ Vector<IRI> ruleseq = new Vector();
+ if (!sequence[0].isEmpty()) for (String seq : sequence)
+ ruleseq.add(IRI.create(seq.replace(" ", "").trim()));
+
+ // Add the new rule to the end
+ ruleseq.add(IRI.create(rule));
+ // Remove the old recipe
+ RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
+ ok = remove.removeRecipe(IRI.create(recipe));
+ if (!ok) {
+ System.err.println("ERROR TO REMOVE OLD RECIPE: " + recipe);
+ return Response.status(Status.CONFLICT).build();
+ }
+
+ // Add the recipe with the new rule
+ AddRecipe newadd = new AddRecipe(kresRuleStore);
+ ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
+ if (ok) {
kresRuleStore.saveOntology();
return Response.ok().build();
- }else{
+ } else {
return Response.status(Status.NO_CONTENT).build();
+ }
+ } else {
+ return Response.status(Status.BAD_REQUEST).build();
}
- }else{
- return Response.status(Status.BAD_REQUEST).build();
- }
- }catch (Exception e){
+ } catch (Exception e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
- /**
- * To delete a rule from a recipe or from the ontology. If the recipe is not
- * specified the rule is deleted from the ontology. curl -v -X DELETE -G \
- * -d recipe=
- * "http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRecipe" \ -d
- * rule
- * ="http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentNewRule" \
+ /**
+ * To delete a rule from a recipe or from the ontology. If the recipe is not specified the rule is deleted
+ * from the ontology. curl -v -X DELETE -G \ -d recipe=
+ * "http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRecipe" \ -d rule
+ * ="http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentNewRule" \
* http://localhost:port/kres/rule
- *
+ *
* @Param rule {A string contains an IRI of the rule to be removed}
- * @param recipe
- * {A string contains an IRI of the recipe where remove the rule}
+ * @param recipe
+ * {A string contains an IRI of the recipe where remove the rule}
* @return Return: <br/>
- * 200 The rule has been deleted<br/>
- * 204 The rule has not been deleted<br/>
- * 404 Recipe or rule not found<br/>
- * 409 The recipe has not been deleted<br/>
- * 500 Some error occurred
+ * 200 The rule has been deleted<br/>
+ * 204 The rule has not been deleted<br/>
+ * 404 Recipe or rule not found<br/>
+ * 409 The recipe has not been deleted<br/>
+ * 500 Some error occurred
*/
@DELETE
- //@Consumes(MediaType.TEXT_PLAIN)
+ // @Consumes(MediaType.TEXT_PLAIN)
@Produces(KRFormat.TEXT_PLAIN)
- public Response removeRule(@QueryParam(value = "rule") String rule,
- @QueryParam(value = "recipe") String recipe) {
+ public Response removeRule(@QueryParam(value = "rule") String rule,
+ @QueryParam(value = "recipe") String recipe) {
boolean ok;
- try{
-
- //Delete from the recipe
- if((recipe!=null)&&(rule!=null)){
- recipe = recipe.replace(" ","").trim();
- rule = rule.replace(" ","").trim();
- //Get the rule
- GetRule getrule = new GetRule(kresRuleStore);
- this.map = getrule.getRule(IRI.create(rule));
- if(map==null){
- return Response.status(Status.NOT_FOUND).build();
- }
+ try {
- //Get the recipe
- GetRecipe getrecipe = new GetRecipe(kresRuleStore);
- this.map = getrecipe.getRecipe(IRI.create(recipe));
- if(map!=null){
- this.desc = getrecipe.getDescription(IRI.create(recipe));
- if(desc.isEmpty())
+ // Delete from the recipe
+ if ((recipe != null) && (rule != null)) {
+ recipe = recipe.replace(" ", "").trim();
+ rule = rule.replace(" ", "").trim();
+ // Get the rule
+ GetRule getrule = new GetRule(kresRuleStore);
+ this.map = getrule.getRule(IRI.create(rule));
+ if (map == null) {
return Response.status(Status.NOT_FOUND).build();
- }else{
- return Response.status(Status.NOT_FOUND).build();
- }
-
- //Remove rule from recipe
- RemoveRule remove = new RemoveRule(kresRuleStore);
- ok = remove.removeRuleFromRecipe(IRI.create(rule), IRI.create(recipe));
-
- if(ok){
- kresRuleStore.saveOntology();
- return Response.status(Status.OK).build();
- }else{
- return Response.status(Status.NO_CONTENT).build();
- }
- }
+ }
+
+ // Get the recipe
+ GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+ this.map = getrecipe.getRecipe(IRI.create(recipe));
+ if (map != null) {
+ this.desc = getrecipe.getDescription(IRI.create(recipe));
+ if (desc.isEmpty()) return Response.status(Status.NOT_FOUND).build();
+ } else {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ // Remove rule from recipe
+ RemoveRule remove = new RemoveRule(kresRuleStore);
+ ok = remove.removeRuleFromRecipe(IRI.create(rule), IRI.create(recipe));
- //Delete from the ontology
- if((recipe==null)&&(rule!=null)){
- rule = rule.replace(" ","").trim();
- //Get the rule
- GetRule getrule = new GetRule(kresRuleStore);
- this.map = getrule.getRule(IRI.create(rule));
- if(map==null){
- return Response.status(Status.NOT_FOUND).build();
+ if (ok) {
+ kresRuleStore.saveOntology();
+ return Response.status(Status.OK).build();
+ } else {
+ return Response.status(Status.NO_CONTENT).build();
+ }
}
- //Remove the old rule
- RemoveRule remove = new RemoveRule(kresRuleStore);
- ok = remove.removeRule(IRI.create(rule));
- if(ok){
- kresRuleStore.saveOntology();
- return Response.status(Status.OK).build();
- }else{
- return Response.status(Status.NO_CONTENT).build();
+ // Delete from the ontology
+ if ((recipe == null) && (rule != null)) {
+ rule = rule.replace(" ", "").trim();
+ // Get the rule
+ GetRule getrule = new GetRule(kresRuleStore);
+ this.map = getrule.getRule(IRI.create(rule));
+ if (map == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ // Remove the old rule
+ RemoveRule remove = new RemoveRule(kresRuleStore);
+ ok = remove.removeRule(IRI.create(rule));
+ if (ok) {
+ kresRuleStore.saveOntology();
+ return Response.status(Status.OK).build();
+ } else {
+ return Response.status(Status.NO_CONTENT).build();
+ }
+ } else {
+ return Response.status(Status.BAD_REQUEST).build();
}
- }else{
- return Response.status(Status.BAD_REQUEST).build();
- }
-
- }catch(Exception e){
- throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+
+ } catch (Exception e) {
+ throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}