Author: alexdma
Date: Tue Jun 28 17:32:17 2011
New Revision: 1140742
URL: http://svn.apache.org/viewvc?rev=1140742&view=rev
Log:
STANBOL-178 :
- Simplified RuleStoreImpl initialization (preparing it for better offline mode
support)
- introduced metatypes for rule store
Added:
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/metatype.properties
Modified:
incubator/stanbol/trunk/rules/base/src/main/java/org/apache/stanbol/rules/base/api/RuleStore.java
incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/changes/RuleStoreImpl.java
incubator/stanbol/trunk/rules/manager/src/test/java/org/apache/stanbol/rules/manager/LoadRuleFileTest.java
Modified:
incubator/stanbol/trunk/rules/base/src/main/java/org/apache/stanbol/rules/base/api/RuleStore.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/base/src/main/java/org/apache/stanbol/rules/base/api/RuleStore.java?rev=1140742&r1=1140741&r2=1140742&view=diff
==============================================================================
---
incubator/stanbol/trunk/rules/base/src/main/java/org/apache/stanbol/rules/base/api/RuleStore.java
(original)
+++
incubator/stanbol/trunk/rules/base/src/main/java/org/apache/stanbol/rules/base/api/RuleStore.java
Tue Jun 28 17:32:17 2011
@@ -7,37 +7,46 @@ import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
-
public interface RuleStore {
- OWLOntology getOntology();
+ /**
+ * The key used to configure default namespace of Stanbol rules.
+ */
+ String RULE_NAMESPACE = "org.apache.stanbol.rules.base.rule_namespace";
+
+ /**
+ * The key used to configure the path of the default rule ontology.
+ */
+ String RULE_ONTOLOGY = "org.apache.stanbol.rules.base.rule_ontology";
- void setStore(OWLOntology owl);
-
- Set<IRI> listIRIRecipes();
-
- RecipeList listRecipes();
-
- Recipe getRecipe(IRI recipe) throws NoSuchRecipeException;
+ boolean addRecipe(IRI recipeIRI, String recipeDescription);
- String getFilePath();
+ Recipe addRuleToRecipe(Recipe recipe, String kReSRuleInKReSSyntax);
- void saveOntology() throws OWLOntologyStorageException;
-
- String getRuleStoreNamespace();
-
- boolean addRecipe(IRI recipeIRI, String recipeDescription);
-
Recipe addRuleToRecipe(String recipeID, String kReSRuleInKReSSyntax)
throws NoSuchRecipeException;
-
- Recipe addRuleToRecipe(Recipe recipe, String kReSRuleInKReSSyntax);
-
+
void createRecipe(String recipeID, String rulesInKReSSyntax);
- boolean removeRecipe(Recipe recipe);
+ String getFilePath();
+
+ OWLOntology getOntology();
+
+ Recipe getRecipe(IRI recipe) throws NoSuchRecipeException;
+
+ String getRuleStoreNamespace();
+
+ Set<IRI> listIRIRecipes();
+
+ RecipeList listRecipes();
boolean removeRecipe(IRI recipeIRI);
+ boolean removeRecipe(Recipe recipe);
+
boolean removeRule(Rule rule);
-
+
+ void saveOntology() throws OWLOntologyStorageException;
+
+ void setStore(OWLOntology owl);
+
}
Modified:
incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/changes/RuleStoreImpl.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/changes/RuleStoreImpl.java?rev=1140742&r1=1140741&r2=1140742&view=diff
==============================================================================
---
incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/changes/RuleStoreImpl.java
(original)
+++
incubator/stanbol/trunk/rules/manager/src/main/java/org/apache/stanbol/rules/manager/changes/RuleStoreImpl.java
Tue Jun 28 17:32:17 2011
@@ -67,18 +67,25 @@ import org.slf4j.LoggerFactory;
@Service(RuleStore.class)
public class RuleStoreImpl implements RuleStore {
+ public static final String _RULE_ONTOLOGY_DEFAULT = "";
+
+ public static final String _RULE_NAMESPACE_DEFAULT =
"http://kres.iks-project.eu/ontology/meta/rmi.owl#";
+
@Reference
ONManager onManager;
- @Property(value = "")
- public static final String RULE_ONTOLOGY = "rule.ontology";
+ @Property(name = RuleStore.RULE_ONTOLOGY, value = _RULE_ONTOLOGY_DEFAULT)
+ private String ruleOntologyLocation;
+
+ @Property(name = RuleStore.RULE_NAMESPACE, value = _RULE_NAMESPACE_DEFAULT)
+ private String ruleNS;
- @Property(value = "http://kres.iks-project.eu/ontology/meta/rmi.owl#")
- public static final String RULE_ONTOLOGY_NAMESPACE =
"rule.ontology.namespace";
+ // @Property(value = "http://kres.iks-project.eu/ontology/meta/rmi.owl#")
+ // public static final String RULE_ONTOLOGY_NAMESPACE =
"rule.ontology.namespace";
private final Logger log = LoggerFactory.getLogger(getClass());
private OWLOntology owlmodel;
- private String file;
+
private String alias;
private RuleStore ruleStore;
private File owlfile;
@@ -93,21 +100,20 @@ public class RuleStoreImpl implements Ru
* Component Runtime support.
* <p>
* DO NOT USE to manually create instances - the RuleStoreImpl instances
do need to be configured! YOU
- * NEED TO USE {@link #RuleStoreImpl(ONManager, Dictionary)} or its
overloads, to parse the
- * configuration and then initialise the rule store if running outside a
OSGI environment.
+ * NEED TO USE {@link #RuleStoreImpl(ONManager, Dictionary)} or its
overloads, to parse the configuration
+ * and then initialise the rule store if running outside a OSGI
environment.
*/
- public RuleStoreImpl() {
+ public RuleStoreImpl() {}
- /*
- * The constructor should be empty as some issue derives from a filled
one. The old version can be invoked
- * with RuleStoreImpl(null)
+ /**
+ * To be invoked by non-OSGi environments.
+ *
+ * @param configuration
*/
- }
-
public RuleStoreImpl(ONManager onm, Dictionary<String,Object>
configuration) {
this();
this.onManager = onm;
- //activate(configuration);
+ // activate(configuration);
}
/**
@@ -120,8 +126,9 @@ public class RuleStoreImpl implements Ru
/*
* FIXME : This won't work if the activate() method is called at the
end of the constructor, like it
* is for other components. Constructors should not override
activate().
+ *
+ * Normally, this recursive constructor call should also invoke
activate()
*/
- // This recursive constructor call will also invoke activate()
this(onm, configuration);
if (filepath.isEmpty()) {
@@ -130,30 +137,30 @@ public class RuleStoreImpl implements Ru
// Obsolete code
Properties configProps = System.getProperties();
String userdir = configProps.getProperty("user.dir");
-
- String respath = "KReSConf/";//"src/main/resources/";
- String filepath2 ="rmi_config.owl";
//"RuleOntology/rmi_config.owl";
-// userdir = userdir.substring(0, userdir.lastIndexOf("kres.")
+ 5) + "rules/";
-
+
+ String respath = "KReSConf/";// "src/main/resources/";
+ String filepath2 = "rmi_config.owl"; //
"RuleOntology/rmi_config.owl";
+ // userdir = userdir.substring(0, userdir.lastIndexOf("kres.")
+ 5) + "rules/";
+
userdir += "/";
-
- this.file = userdir + respath + filepath2;
- this.owlfile = new File(file);
+
+ this.ruleOntologyLocation = userdir + respath + filepath2;
+ this.owlfile = new File(ruleOntologyLocation);
owlfile.setWritable(true);
-// InputStream is =
this.getClass().getResourceAsStream("/RuleOntology/rmi_config.owl");
-// URL url =
this.getClass().getResource("/RuleOntology/rmi_config.owl");
-// System.err.println("DIOCANE "+url.toURI());
-// this.owlfile = new File(url.toURI());
-// owlfile.setWritable(true);
-
+ // InputStream is =
this.getClass().getResourceAsStream("/RuleOntology/rmi_config.owl");
+ // URL url =
this.getClass().getResource("/RuleOntology/rmi_config.owl");
+ // System.err.println("DIOCANE "+url.toURI());
+ // this.owlfile = new File(url.toURI());
+ // owlfile.setWritable(true);
+
OWLOntologyManager owlmanager =
OWLManager.createOWLOntologyManager();
-
+
// FIXME : awful
URL u = getClass().getResource("/");
OWLOntologyIRIMapper mapper = new AutoIRIMapper(new
File(u.toURI()), true);
owlmanager.addIRIMapper(mapper);
-
+
this.owlmodel = owlmanager.loadOntology(IRI.create(owlfile));
} catch (Exception io) {
@@ -161,8 +168,8 @@ public class RuleStoreImpl implements Ru
this.owlmodel = null;
}
} else {
- this.file = filepath;
- this.owlfile = new File(file);
+ this.ruleOntologyLocation = filepath;
+ this.owlfile = new File(ruleOntologyLocation);
owlfile.setWritable(true);
OWLOntologyManager owlmanager =
OWLManager.createOWLOntologyManager();
try {
@@ -238,31 +245,42 @@ public class RuleStoreImpl implements Ru
}
protected void activate(Dictionary<String,Object> configuration) {
-
- this.file = (String) configuration.get(RULE_ONTOLOGY);
- this.ruleOntologyNS = (String)
configuration.get(RULE_ONTOLOGY_NAMESPACE);
-
- if (file == null || file.equals("")) {
+
+ // TODO This bit is the "good" code, and any non-default constructor
should call it.
+ ruleOntologyLocation = (String)
configuration.get(RuleStore.RULE_ONTOLOGY);
+ if (ruleOntologyLocation == null) ruleOntologyLocation =
_RULE_ONTOLOGY_DEFAULT;
+
+ ruleOntologyNS = (String) configuration.get(RuleStore.RULE_NAMESPACE);
+ if (ruleOntologyNS == null) ruleOntologyNS = _RULE_NAMESPACE_DEFAULT;
+
+ // this.file = (String) configuration.get(RULE_ONTOLOGY);
+ // this.ruleOntologyNS = (String) configuration.get(RULE_NAMESPACE);
+
+ // This about KReSConf is no good
+ if (ruleOntologyLocation == null || ruleOntologyLocation.equals("")) {
String sep = System.getProperty("file.separator");
- String filedir =
System.getProperty("user.dir")+sep+"KReSConf"+sep+"rmi_config.owl";
-
- if((new File(filedir)).exists()){
- this.file = filedir;
+ String filedir = System.getProperty("user.dir") + sep + "KReSConf"
+ sep + "rmi_config.owl";
+
+ if ((new File(filedir)).exists()) {
+ this.ruleOntologyLocation = filedir;
try {
- owlmodel =
OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new
File(file));
+ owlmodel =
OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
+ new File(ruleOntologyLocation));
} catch (OWLOntologyCreationException e) {
log.error("Cannot create the ontology " +
filedir.toString(), e);
} catch (Exception e) {
log.error("1 Rule Store: no rule ontology available.");
}
- }else{
- IRI inputontology =
IRI.create("http://ontologydesignpatterns.org/ont/iks/kres/rmi_config.owl");
+ } else {
+ IRI inputontology = IRI
+
.create("http://ontologydesignpatterns.org/ont/iks/kres/rmi_config.owl");
try {
- owlmodel =
OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(inputontology);
+ owlmodel =
OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
+ inputontology);
} catch (OWLOntologyCreationException e) {
log.error("Cannot create the ontology " +
inputontology.toString(), e);
} catch (Exception e) {
- log.error("Rule Store: no rule ontology available.");
+ log.error("Rule Store: no rule ontology available.");
}
}
@@ -270,11 +288,11 @@ public class RuleStoreImpl implements Ru
File dirs = new File("./KReSConf");
if (!dirs.exists()) dirs.mkdir();
- file = "./KReSConf/rmi_config.owl";
+ ruleOntologyLocation = "./KReSConf/rmi_config.owl";
FileOutputStream fos;
try {
- fos = new FileOutputStream(file);
+ fos = new FileOutputStream(ruleOntologyLocation);
OWLManager.createOWLOntologyManager().saveOntology(owlmodel,
owlmodel.getOWLOntologyManager().getOntologyFormat(owlmodel), fos);
} catch (FileNotFoundException e) {
@@ -284,7 +302,7 @@ public class RuleStoreImpl implements Ru
}
}
} else {
- File pathIri = new File(file);
+ File pathIri = new File(ruleOntologyLocation);
try {
owlmodel =
OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(pathIri);
} catch (OWLOntologyCreationException e) {
@@ -439,7 +457,7 @@ public class RuleStoreImpl implements Ru
*/
@Override
public String getFilePath() {
- return this.file;
+ return this.ruleOntologyLocation;
}
/**
@@ -451,11 +469,12 @@ public class RuleStoreImpl implements Ru
public void saveOntology() {
try {
FileOutputStream fos;
- if (this.file.isEmpty()) {
+ if (this.ruleOntologyLocation.isEmpty()) {
String sep = System.getProperty("file.separator");
- this.file =
System.getProperty("user.dir")+sep+"KReSConf"+sep+"rmi_config.owl";
+ this.ruleOntologyLocation = System.getProperty("user.dir") +
sep + "KReSConf" + sep
+ + "rmi_config.owl";
try {
- fos = new FileOutputStream(file);
+ fos = new FileOutputStream(ruleOntologyLocation);
OWLManager.createOWLOntologyManager().saveOntology(owlmodel,
owlmodel.getOWLOntologyManager().getOntologyFormat(owlmodel), fos);
} catch (FileNotFoundException e) {
@@ -464,7 +483,7 @@ public class RuleStoreImpl implements Ru
log.error("Cannot store the ontology ", e);
}
} else {
- fos = new FileOutputStream(file);
+ fos = new FileOutputStream(ruleOntologyLocation);
this.owlmodel.getOWLOntologyManager().saveOntology(owlmodel,
fos);
}
@@ -567,8 +586,8 @@ public class RuleStoreImpl implements Ru
/**
* Add the rule to the recipe in the rule ontology managed by the
RuleStore. First we define the
- * object property hasRule and then we add the literal that contains
the rule in Rule Syntax to
- * the recipe individual.
+ * object property hasRule and then we add the literal that contains
the rule in Rule Syntax to the
+ * recipe individual.
*/
String ruleNS = "http://kres.iks-project.eu/ontology/meta/rmi.owl#";
OWLObjectProperty hasRule =
factory.getOWLObjectProperty(IRI.create(ruleNS + "hasRule"));
Added:
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/metatype.properties
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1140742&view=auto
==============================================================================
---
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/metatype.properties
(added)
+++
incubator/stanbol/trunk/rules/manager/src/main/resources/OSGI-INF/metatype/metatype.properties
Tue Jun 28 17:32:17 2011
@@ -0,0 +1,11 @@
+#===============================================================================
+#Properties defined by the Rule Store
+#===============================================================================
+org.apache.stanbol.rules.manager.changes.RuleStoreImpl.name = Apache Stanbol
Rule Store
+org.apache.stanbol.rules.manager.changes.RuleStoreImpl.description = A storage
facility for Apache Stanbol rules and recipes.
+
+org.apache.stanbol.rules.base.rule_namespace.name = Rule namespace
+org.apache.stanbol.rules.base.rule_namespace.description = The default
namespace of Stanbol rule instances in the rule ontology.
+
+org.apache.stanbol.rules.base.rule_ontology.name = Rule ontology location
+org.apache.stanbol.rules.base.rule_ontology.description = The URL of the
ontology containing the default rule set. Can be overridden programmatically.
\ 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=1140742&r1=1140741&r2=1140742&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
Tue Jun 28 17:32:17 2011
@@ -72,7 +72,7 @@ public class LoadRuleFileTest {
ONManager onm = new ONManagerImpl(null,null,configuration);
Dictionary<String, Object> configuration2 = new Hashtable<String,
Object>();
// configuration2.put(RuleStoreImpl.RULE_ONTOLOGY, "");
- configuration2.put(RuleStoreImpl.RULE_ONTOLOGY_NAMESPACE,
"http://kres.iks-project.eu/ontology/meta/rmi.owl#");
+ 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),configuration2,store.getOntology());
//Load the example file