[Reasoner4j-user] SF.net SVN: reasoner4j:[54] trunk/reasoner4j
Status: Pre-Alpha
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-01-07 03:48:41
|
Revision: 54
http://reasoner4j.svn.sourceforge.net/reasoner4j/?rev=54&view=rev
Author: luc_peuvrier
Date: 2011-01-07 03:48:34 +0000 (Fri, 07 Jan 2011)
Log Message:
-----------
isRemovable added in IFactSet
Modified Paths:
--------------
trunk/reasoner4j/doc/todo.txt
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/TermIdentifierConstant.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultBuiltinProvider.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractSubFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AllFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/IFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ISubFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ObjectOfSubjectPredicate.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateObjectOfSubject.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateOfSubjectObject.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SingleFactSet.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectObjectOfPredicate.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectOfPredicateObject.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectPredicateOfObject.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/IMotor.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/Motor.java
Added Paths:
-----------
trunk/reasoner4j/doc/last_of_list.txt
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogEqualsToBuiltin.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogNotEqualsToBuiltin.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultRuleDefinitionProvider.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/IRuleDefinitionProvider.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/ruledef/
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/ruledef/ListRuleDefinition.java
Added: trunk/reasoner4j/doc/last_of_list.txt
===================================================================
--- trunk/reasoner4j/doc/last_of_list.txt (rev 0)
+++ trunk/reasoner4j/doc/last_of_list.txt 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,25 @@
+?LL containsLastOfList ?L
+?LL listRest ?LR
+?LR logNotEquals nil
+=>
+?LR containsLastOfList ?L
+
+?LL containsLastOfList ?L
+?LL listRest ?LR
+?LR logEquals nil
+?LL listFirst ?E
+=>
+?LR lastOfList ?E (replace object)
+
+?L lastOfList ?E
+?L lastOfList ?CE (not listening, default nil object)
+?E logNotSameAs ?CE
+?LL containsLastOfList ?L
+?LL listRest ?LR
+?LR logEquals nil
+nil blankNode ?NLR
+=>
+?LL listRest ?NLR (replace object)
+?NLR listFirst ?E
+?NLR listRest nil
+
Modified: trunk/reasoner4j/doc/todo.txt
===================================================================
--- trunk/reasoner4j/doc/todo.txt 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/doc/todo.txt 2011-01-07 03:48:34 UTC (rev 54)
@@ -18,12 +18,6 @@
motor#addBuitinProvider
motor#defaultBuitinProvider(boolean enabled); //disabled by default
-to test
--------
-
-builtin mathSum
-builtin listAppend
-
inList builtin
--------------
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/TermIdentifierConstant.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/TermIdentifierConstant.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/TermIdentifierConstant.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -29,6 +29,8 @@
*/
public final class TermIdentifierConstant {
+ public static final String NIL_IDENTIFIER = "nil";
+
public static final String EMPTY_TERM = "";
public static final String BLANK_NODE_PREDICATE_IDENTIFIER = "blankNode";
@@ -37,8 +39,10 @@
public static final String MATH_PRODUCT_PREDICATE_IDENTIFIER = "mathProduct";
- public static final String NIL_IDENTIFIER = "nil";
+ public static final String LOG_EQUALS_TO = "logEqualsTo";
+ public static final String LOG_NOT_EQUALS_TO = "logNotEqualsTo";
+
// FIXMELUC ListBuiltin no more needed
@Deprecated
public static final String LIST_PREDICATE_IDENTIFIER = "list";
@@ -53,6 +57,8 @@
public static final String LIST_REST_PREDICATE_IDENTIFIER = "listRest";
+ public static final String LAST_OF_LIST_PREDICATE_IDENTIFIER = "lastOfList";
+
private TermIdentifierConstant() {
super();
}
Added: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogEqualsToBuiltin.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogEqualsToBuiltin.java (rev 0)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogEqualsToBuiltin.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010 Luc Peuvrier
+ *
+ * This file is a part of reasoner4j.
+ *
+ * reasoner4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * reasoner4j is distributed in the hope that it will be useful, but
+ * 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 net.sf.reasoner4j.builtin.impl.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.reasoner4j.ReasonerException;
+import net.sf.reasoner4j.builtin.TermIdentifierConstant;
+import net.sf.reasoner4j.builtin.impl.AbstractBuiltin;
+import net.sf.reasoner4j.fact.Fact;
+import net.sf.reasoner4j.fact.IFact;
+
+/**
+ * @author luc peuvrier
+ *
+ * @param <T>
+ */
+public class LogEqualsToBuiltin<T> extends AbstractBuiltin<T> {
+
+ public LogEqualsToBuiltin() {
+ super(null, TermIdentifierConstant.LOG_EQUALS_TO, null);
+ }
+
+ @Override
+ public List<IFact<T>> compute(final int ruleIdentifier, final T subject,
+ final T predicate, final T object) {
+ if (subject == null) {
+ throw new ReasonerException("subject must be defined");
+ }
+ if (object == null) {
+ throw new ReasonerException("object must be defined");
+ }
+ final List<IFact<T>> resultFactList = new ArrayList<IFact<T>>(1);
+ final IFact<T> resultFact;
+ if (subject.equals(object)) {
+ resultFact = new Fact<T>(subject, predicate, object);
+ } else {
+ resultFact = null;
+ }
+ if (resultFact != null) {
+ resultFactList.add(resultFact);
+ }
+ return resultFactList;
+ }
+}
Added: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogNotEqualsToBuiltin.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogNotEqualsToBuiltin.java (rev 0)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/impl/log/LogNotEqualsToBuiltin.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010 Luc Peuvrier
+ *
+ * This file is a part of reasoner4j.
+ *
+ * reasoner4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * reasoner4j is distributed in the hope that it will be useful, but
+ * 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 net.sf.reasoner4j.builtin.impl.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.reasoner4j.ReasonerException;
+import net.sf.reasoner4j.builtin.TermIdentifierConstant;
+import net.sf.reasoner4j.builtin.impl.AbstractBuiltin;
+import net.sf.reasoner4j.fact.Fact;
+import net.sf.reasoner4j.fact.IFact;
+
+/**
+ * @author luc peuvrier
+ *
+ * @param <T>
+ */
+public class LogNotEqualsToBuiltin<T> extends AbstractBuiltin<T> {
+
+ public LogNotEqualsToBuiltin() {
+ super(null, TermIdentifierConstant.LOG_EQUALS_TO, null);
+ }
+
+ @Override
+ public List<IFact<T>> compute(final int ruleIdentifier, final T subject,
+ final T predicate, final T object) {
+ if (subject == null) {
+ throw new ReasonerException("subject must be defined");
+ }
+ if (object == null) {
+ throw new ReasonerException("object must be defined");
+ }
+ final List<IFact<T>> resultFactList = new ArrayList<IFact<T>>(1);
+ final IFact<T> resultFact;
+ if (subject.equals(object)) {
+ resultFact = null;
+ } else {
+ resultFact = new Fact<T>(subject, predicate, object);
+ }
+ if (resultFact != null) {
+ resultFactList.add(resultFact);
+ }
+ return resultFactList;
+ }
+}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultBuiltinProvider.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultBuiltinProvider.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultBuiltinProvider.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -30,6 +30,8 @@
import net.sf.reasoner4j.builtin.impl.list.InListBuiltin;
import net.sf.reasoner4j.builtin.impl.list.ListAppendBuiltin;
import net.sf.reasoner4j.builtin.impl.list.ListRemoveBuiltin;
+import net.sf.reasoner4j.builtin.impl.log.LogEqualsToBuiltin;
+import net.sf.reasoner4j.builtin.impl.log.LogNotEqualsToBuiltin;
import net.sf.reasoner4j.builtin.impl.math.MathProductBuiltin;
import net.sf.reasoner4j.builtin.impl.math.MathSumBuiltin;
@@ -48,6 +50,8 @@
builtinList.add(new BlankNodeBuiltin<T>());
builtinList.add(new MathProductBuiltin<T>(builtinComputer));
builtinList.add(new MathSumBuiltin<T>(builtinComputer));
+ builtinList.add(new LogEqualsToBuiltin<T>());
+ builtinList.add(new LogNotEqualsToBuiltin<T>());
// FIXMELUC ListBuiltin no more needed
// builtinList.add(new ListBuiltin<T>());
builtinList.add(new InListBuiltin<T>());
Added: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultRuleDefinitionProvider.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultRuleDefinitionProvider.java (rev 0)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/DefaultRuleDefinitionProvider.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of reasoner4j.
+ *
+ * reasoner4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * reasoner4j is distributed in the hope that it will be useful, but
+ * 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 net.sf.reasoner4j.builtin.provider;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import net.sf.reasoner4j.builtin.ruledef.ListRuleDefinition;
+import net.sf.reasoner4j.rule.Rule;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ * @param <T>
+ */
+public class DefaultRuleDefinitionProvider<T> implements
+ IRuleDefinitionProvider<T> {
+
+ private List<Rule<T>> ruleList;
+
+ @Override
+ public List<Rule<T>> getRules(
+ final IBuitinTermProvider<T> buitinTermProvider) {
+ if (ruleList == null) {
+ ruleList = new LinkedList<Rule<T>>();
+ ruleList.addAll(new ListRuleDefinition<T>(buitinTermProvider));
+ }
+ return ruleList;
+ }
+}
Added: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/IRuleDefinitionProvider.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/IRuleDefinitionProvider.java (rev 0)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/provider/IRuleDefinitionProvider.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of reasoner4j.
+ *
+ * reasoner4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * reasoner4j is distributed in the hope that it will be useful, but
+ * 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 net.sf.reasoner4j.builtin.provider;
+
+import java.util.List;
+
+import net.sf.reasoner4j.rule.Rule;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ * @param <T>
+ */
+public interface IRuleDefinitionProvider<T> {
+
+ List<Rule<T>> getRules(IBuitinTermProvider<T> buitinTermProvider);
+}
Added: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/ruledef/ListRuleDefinition.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/ruledef/ListRuleDefinition.java (rev 0)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/builtin/ruledef/ListRuleDefinition.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2011 Luc Peuvrier
+ *
+ * This file is a part of reasoner4j.
+ *
+ * reasoner4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (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.gnu.org/licenses/lgpl.html
+ *
+ * reasoner4j is distributed in the hope that it will be useful, but
+ * 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 net.sf.reasoner4j.builtin.ruledef;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.reasoner4j.builtin.TermIdentifierConstant;
+import net.sf.reasoner4j.builtin.provider.IBuitinTermProvider;
+import net.sf.reasoner4j.rule.AssertConclusion;
+import net.sf.reasoner4j.rule.IConclusion;
+import net.sf.reasoner4j.rule.IPremise;
+import net.sf.reasoner4j.rule.Premise;
+import net.sf.reasoner4j.rule.ReplaceConclusion;
+import net.sf.reasoner4j.rule.Rule;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ * @param <T>
+ */
+public class ListRuleDefinition<T> extends AbstractList<Rule<T>> {
+
+ private static final String CONTAINS_LAST_OF_LIST = "containsLastOfList";
+
+ private final List<Rule<T>> ruleList = new ArrayList<Rule<T>>();
+
+ public ListRuleDefinition(final IBuitinTermProvider<T> buitinTermProvider) {
+ super();
+ final T containsLastOfListTerm = buitinTermProvider
+ .getTerm(CONTAINS_LAST_OF_LIST);
+ final T listRestTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.LIST_REST_PREDICATE_IDENTIFIER);
+ final T listFirstTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.LIST_FIRST_PREDICATE_IDENTIFIER);
+ final T lastOfListTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.LAST_OF_LIST_PREDICATE_IDENTIFIER);
+ final T logEqualsToTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.LOG_EQUALS_TO);
+ final T logNotEqualsToTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.LOG_NOT_EQUALS_TO);
+ final T nilTerm = buitinTermProvider
+ .getTerm(TermIdentifierConstant.NIL_IDENTIFIER);
+
+ Rule<T> rule;
+ IPremise<T> premise;
+ IConclusion<T> conclusion;
+
+ // ?LL containsLastOfList ?L
+ // ?LL listRest ?LR
+ // ?LR logNotEquals nil
+ // =>
+ // ?LR containsLastOfList ?L
+
+ rule = new Rule<T>();
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, containsLastOfListTerm,
+ /* object */"?L", null);
+ rule.addPremise(premise);
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, listRestTerm,
+ /* object */"?LR", null);
+ rule.addPremise(premise);
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, logNotEqualsToTerm,
+ /* object */null, nilTerm);
+ rule.addPremise(premise);
+
+ conclusion = new AssertConclusion<T>(
+ /* subject */"?LR", null,
+ /* predicate */null, containsLastOfListTerm,
+ /* object */"?L", null);
+ rule.addConclusion(conclusion);
+ ruleList.add(rule);
+
+ // ?LL containsLastOfList ?L
+ // ?LL listRest ?LR
+ // ?LR logEquals nil
+ // ?LL listFirst ?E
+ // =>
+ // ?LR lastOfList ?E (replace object)
+
+ rule = new Rule<T>();
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, containsLastOfListTerm,
+ /* object */"?L", null);
+ rule.addPremise(premise);
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, listRestTerm,
+ /* object */"?LR", null);
+ rule.addPremise(premise);
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, logEqualsToTerm,
+ /* object */null, nilTerm);
+ rule.addPremise(premise);
+
+ premise = new Premise<T>(
+ /* subject */"?LL", null,
+ /* predicate */null, listFirstTerm,
+ /* object */"?E", null);
+ rule.addPremise(premise);
+
+ conclusion = new ReplaceConclusion<T>(
+ /* subject */"?LR", null, false,
+ /* predicate */null, lastOfListTerm, false,
+ /* object */"?E", null, true);
+ rule.addConclusion(conclusion);
+ ruleList.add(rule);
+
+ // ?L lastOfList ?E
+ // ?L lastOfList ?CE (not listening, default nil object)
+ // ?E logNotSameAs ?CE
+ // ?LL containsLastOfList ?L
+ // ?LL listRest ?LR
+ // ?LR logEquals nil
+ // nil blankNode ?NLR
+ // =>
+ // ?LL listRest ?NLR (replace object)
+ // ?NLR listFirst ?E
+ // ?NLR listRest nil
+
+ }
+
+ @Override
+ public Rule<T> get(final int index) {
+ return ruleList.get(index);
+ }
+
+ @Override
+ public int size() {
+ return ruleList.size();
+ }
+}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -52,8 +52,8 @@
@Override
public void removeListener(final IFactSetListener<T> listener) {
listenerSet.remove(listener);
- if (!hasListener() && isEmpty()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
@@ -61,7 +61,7 @@
* call when remove last listener of empty fact set, or remove last fact of
* fact set and has no listener
*/
- protected abstract void fireNoListenerAndEmpty();
+ protected abstract void fireRemovable();
@Override
public boolean hasListener() {
@@ -102,4 +102,9 @@
public boolean contains(T subject, T predicate, T object) {
return get(subject, predicate, object) != null;
}
+
+ @Override
+ public boolean isRemovable() {
+ return !hasListener() && isEmpty();
+ }
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractSubFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractSubFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AbstractSubFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -59,9 +59,9 @@
}
@Override
- protected void fireNoListenerAndEmpty() {
- // notify this is empty and has not listener, parent must clean itself
- parentFactSet.fireNoListenerAndEmpty(this);
+ protected void fireRemovable() {
+ // notify this is removable, parent must clean itself
+ parentFactSet.fireRemovable(this);
}
@Override
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AllFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AllFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/AllFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -198,7 +198,7 @@
// throw new ReasonerException("no single fact set for " + fact);
// FIXMELUC _for TestExpressionCompute
} else if (singleFactSet.removeFact(causeIdentifiedFact, doFire)) {
- if (!singleFactSet.hasListener() && singleFactSet.isEmpty()) {
+ if (singleFactSet.isRemovable()) {
singleFacSetMap.remove(fact);
singleFactSet.close();
}
@@ -210,8 +210,7 @@
if (predicateObjectOfSubject != null) {
removed = predicateObjectOfSubject.removeFact(singleFactSet,
causeIdentifiedFact, doFire);
- if (predicateObjectOfSubject.isEmpty()
- && !predicateObjectOfSubject.hasListener()) {
+ if (predicateObjectOfSubject.isRemovable()) {
predicateObjectBySubjectMap.remove(subject).close();
}
}
@@ -219,8 +218,7 @@
if (subjectObjectOfPredicate != null) {
removed = subjectObjectOfPredicate.removeFact(singleFactSet,
causeIdentifiedFact, doFire);
- if (subjectObjectOfPredicate.isEmpty()
- && !subjectObjectOfPredicate.hasListener()) {
+ if (subjectObjectOfPredicate.isRemovable()) {
subjectObjectByPredicateMap.remove(predicate).close();
}
}
@@ -230,7 +228,7 @@
&& !subjectPredicateOfObject.hasListener()) {
removed = subjectPredicateOfObject.removeFact(singleFactSet,
causeIdentifiedFact, doFire);
- if (subjectPredicateOfObject.isEmpty()) {
+ if (subjectPredicateOfObject.isRemovable()) {
subjectPredicateByObjectMap.remove(object).close();
}
}
@@ -250,12 +248,12 @@
}
@Override
- protected void fireNoListenerAndEmpty() {
+ protected void fireRemovable() {
// nothing to do, no parent sub fact set to clean
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T subject = subFactSet.getSubject();
if (subject != null) {
predicateObjectBySubjectMap.remove(subject).close();
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/IFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/IFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/IFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -65,4 +65,10 @@
boolean removeFact(CauseIdentifiedFact<T> causeIdentifiedFact,
boolean doFire);
+ /**
+ * removable is has no listener and is empty
+ *
+ * @return true if removable
+ */
+ boolean isRemovable();
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ISubFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ISubFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ISubFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -32,7 +32,7 @@
SingleFactSet<T> getOrCreateSingleFactSet(T subject, T predicate, T object);
- void fireNoListenerAndEmpty(ISubFactSet<T> subFactSet);
+ void fireRemovable(ISubFactSet<T> subFactSet);
/**
*
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ObjectOfSubjectPredicate.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ObjectOfSubjectPredicate.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/ObjectOfSubjectPredicate.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -123,12 +123,12 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T object = subFactSet.getObject();
if (object != null) {
factByObjectMap.remove(object).close();
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateObjectOfSubject.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateObjectOfSubject.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateObjectOfSubject.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -129,8 +129,7 @@
if (objectOfSubjectPredicate != null) {
removed = objectOfSubjectPredicate.removeFact(singleFactSet, fact,
doFire);
- if (objectOfSubjectPredicate.isEmpty()
- && !objectOfSubjectPredicate.hasListener()) {
+ if (objectOfSubjectPredicate.isRemovable()) {
objectOfSubjectPredicateByPredicateMap.remove(predicate)
.close();
}
@@ -141,8 +140,7 @@
if (predicateOfSubjectObject != null) {
removed = predicateOfSubjectObject.removeFact(singleFactSet, fact,
doFire);
- if (predicateOfSubjectObject.isEmpty()
- && !predicateOfSubjectObject.hasListener()) {
+ if (predicateOfSubjectObject.isRemovable()) {
predicateOfSubjectObjectByObjectMap.remove(object).close();
}
}
@@ -159,7 +157,7 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T predicate = subFactSet.getPredicate();
if (predicate != null) {
objectOfSubjectPredicateByPredicateMap.remove(predicate).close();
@@ -168,8 +166,8 @@
if (object != null) {
predicateOfSubjectObjectByObjectMap.remove(object).close();
}
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateOfSubjectObject.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateOfSubjectObject.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/PredicateOfSubjectObject.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -122,12 +122,12 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T predicate = subFactSet.getPredicate();
if (predicate != null) {
factByPredicate.remove(predicate).close();
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SingleFactSet.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SingleFactSet.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SingleFactSet.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -163,7 +163,7 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
// this has not sub fact set
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectObjectOfPredicate.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectObjectOfPredicate.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectObjectOfPredicate.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -129,8 +129,7 @@
if (objectOfSubjectPredicate != null) {
removed = objectOfSubjectPredicate.removeFact(singleFactSet, fact,
doFire);
- if (objectOfSubjectPredicate.isEmpty()
- && !objectOfSubjectPredicate.hasListener()) {
+ if (objectOfSubjectPredicate.isRemovable()) {
objectOfSubjectPredicateBySubjectMap.remove(subject).close();
}
}
@@ -140,8 +139,7 @@
if (subjectOfPredicateObject != null) {
removed = subjectOfPredicateObject.removeFact(singleFactSet, fact,
doFire);
- if (subjectOfPredicateObject.isEmpty()
- && !subjectOfPredicateObject.hasListener()) {
+ if (subjectOfPredicateObject.isRemovable()) {
subjectOfPredicateObjectByPredicateMap.remove(object).close();
}
}
@@ -158,7 +156,7 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T subject = subFactSet.getSubject();
if (subject != null) {
objectOfSubjectPredicateBySubjectMap.remove(subject).close();
@@ -167,8 +165,8 @@
if (object != null) {
subjectOfPredicateObjectByPredicateMap.remove(object).close();
}
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectOfPredicateObject.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectOfPredicateObject.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectOfPredicateObject.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -122,12 +122,12 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T subject = subFactSet.getSubject();
if (subject != null) {
factBySubject.remove(subject).close();
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectPredicateOfObject.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectPredicateOfObject.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/fact/SubjectPredicateOfObject.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -129,8 +129,7 @@
if (objectOfSubjectPredicate != null) {
removed = objectOfSubjectPredicate.removeFact(singleFactSet, fact,
doFire);
- if (objectOfSubjectPredicate.isEmpty()
- && !objectOfSubjectPredicate.hasListener()) {
+ if (objectOfSubjectPredicate.isRemovable()) {
predicateOfSubjectObjectBySubjectMap.remove(subject).close();
}
}
@@ -140,8 +139,7 @@
if (subjectOfPredicateObject != null) {
removed = subjectOfPredicateObject.removeFact(singleFactSet, fact,
doFire);
- if (subjectOfPredicateObject.isEmpty()
- && !objectOfSubjectPredicate.hasListener()) {
+ if (subjectOfPredicateObject.isRemovable()) {
subjectOfPredicateObjectByPredicateMap.remove(predicate)
.close();
}
@@ -159,7 +157,7 @@
}
@Override
- public void fireNoListenerAndEmpty(final ISubFactSet<T> subFactSet) {
+ public void fireRemovable(final ISubFactSet<T> subFactSet) {
final T subject = subFactSet.getSubject();
if (subject != null) {
predicateOfSubjectObjectBySubjectMap.remove(subject).close();
@@ -168,8 +166,8 @@
if (predicate != null) {
subjectOfPredicateObjectByPredicateMap.remove(predicate).close();
}
- if (isEmpty() && !hasListener()) {
- fireNoListenerAndEmpty();
+ if (isRemovable()) {
+ fireRemovable();
}
}
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/IMotor.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/IMotor.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/IMotor.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -24,6 +24,7 @@
import net.sf.reasoner4j.builtin.IBuiltin;
import net.sf.reasoner4j.builtin.provider.IBuiltinProvider;
+import net.sf.reasoner4j.builtin.provider.IRuleDefinitionProvider;
import net.sf.reasoner4j.fact.IFact;
import net.sf.reasoner4j.kb.IKnowledgeBase;
import net.sf.reasoner4j.rule.Rule;
@@ -49,6 +50,8 @@
*/
void addRule(Rule<T> rule);
+ void addRule(IRuleDefinitionProvider<T> ruleDefinitionProvider);
+
void removeRule(Rule<T> rule);
void assertFact(IFact<T> fact);
Modified: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/Motor.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/Motor.java 2011-01-05 03:18:32 UTC (rev 53)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/motor/Motor.java 2011-01-07 03:48:34 UTC (rev 54)
@@ -39,6 +39,7 @@
import net.sf.reasoner4j.builtin.impl.BuiltinSupport;
import net.sf.reasoner4j.builtin.provider.IBuiltinProvider;
import net.sf.reasoner4j.builtin.provider.IBuitinTermProvider;
+import net.sf.reasoner4j.builtin.provider.IRuleDefinitionProvider;
import net.sf.reasoner4j.fact.CauseIdentifiedFact;
import net.sf.reasoner4j.fact.Fact;
import net.sf.reasoner4j.fact.IFact;
@@ -152,6 +153,13 @@
}
@Override
+ public void addRule(final IRuleDefinitionProvider<T> ruleDefinitionProvider) {
+ for (Rule<T> rule : ruleDefinitionProvider.getRules(buitinTermProvider)) {
+ addRule(rule);
+ }
+ }
+
+ @Override
public void removeRule(final Rule<T> rule) {
// TODO
// TODO retract fact conclusion of removed rule
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|