[Reasoner4j-user] SF.net SVN: reasoner4j:[39] trunk/reasoner4j/src/main/java/net/sf/ reasoner4j/ret
Status: Pre-Alpha
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2010-12-25 03:54:14
|
Revision: 39
http://reasoner4j.svn.sourceforge.net/reasoner4j/?rev=39&view=rev
Author: luc_peuvrier
Date: 2010-12-25 03:54:07 +0000 (Sat, 25 Dec 2010)
Log Message:
-----------
variable table classes no more needed after merge table modification for fact removal
Removed Paths:
-------------
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/AbstractVariableTable.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/IVariableTable.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTable.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTableAndDefault.java
trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/VariableTable.java
Deleted: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/AbstractVariableTable.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/AbstractVariableTable.java 2010-12-25 03:43:14 UTC (rev 38)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/AbstractVariableTable.java 2010-12-25 03:54:07 UTC (rev 39)
@@ -1,86 +0,0 @@
-/*
- * 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.rete.entity;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- *
- * @author luc peuvrier
- *
- * @param <T>
- */
-public abstract class AbstractVariableTable<T> implements IVariableTable<T> {
-
- private final Set<ITableListener<T>> listenerSet = new HashSet<ITableListener<T>>();
-
- protected final VariableKeyValueMapping<T> mapping;
-
- public AbstractVariableTable(final VariableKeyValueMapping<T> mapping) {
- super();
- this.mapping = mapping;
- }
-
- @Override
- public void addListener(final ITableListener<T> listener) {
- listenerSet.add(listener);
- }
-
- @Override
- public void removeListener(final ITableListener<T> listener) {
- listenerSet.remove(listener);
- }
-
- @Override
- public boolean add(final List<T> variableValueSet) {
- final boolean added = addImpl(variableValueSet);
- if (added && !listenerSet.isEmpty()) {
- for (ITableListener<T> listener : listenerSet) {
- listener.added(variableValueSet);
- }
- }
- return added;
- }
-
- protected abstract boolean addImpl(final List<T> variableValueSet);
-
- @Override
- public boolean remove(final List<T> variableValueSet) {
- final boolean removed = removeImpl(variableValueSet);
- if (removed && !listenerSet.isEmpty()) {
- for (ITableListener<T> listener : listenerSet) {
- listener.removed(variableValueSet);
- }
- }
- return removed;
- }
-
- protected abstract boolean removeImpl(final List<T> variableValueSet);
-
- @Override
- public void removed(List<T> value) {
- }
-
-}
Deleted: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/IVariableTable.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/IVariableTable.java 2010-12-25 03:43:14 UTC (rev 38)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/IVariableTable.java 2010-12-25 03:54:07 UTC (rev 39)
@@ -1,51 +0,0 @@
-/*
- * 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.rete.entity;
-
-import java.util.List;
-
-/**
- *
- * @author luc peuvrier
- *
- * @param <T>
- */
-public interface IVariableTable<T> extends ITable<T> {
-
- /**
- *
- * @param variableValueSet
- * FIXMELUC value
- * @return <tt>true</tt> if this set did not already contains the specified
- * element
- */
- boolean add(List<T> variableValueSet);
-
- /**
- *
- * @param variableValueSet
- * FIXMELUC value
- * @return <tt>true</tt> if this set contained the specified element
- */
- boolean remove(List<T> variableValueSet);
-}
Deleted: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTable.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTable.java 2010-12-25 03:43:14 UTC (rev 38)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTable.java 2010-12-25 03:54:07 UTC (rev 39)
@@ -1,159 +0,0 @@
-/*
- * 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.rete.entity;
-
-import java.util.Iterator;
-import java.util.List;
-
-import net.sf.reasoner4j.Fortest;
-import net.sf.reasoner4j.fact.IFact;
-import net.sf.reasoner4j.fact.IFactSet;
-import net.sf.reasoner4j.rule.IPremise;
-
-/**
- *
- * @author luc peuvrier
- *
- * @param <T>
- */
-public class PremiseVariableTable<T> extends AbstractVariableTable<T> {
-
- protected final IFactSet<T> factSet;
-
- private final IPremise<T> premise;
-
- public PremiseVariableTable(final VariableKeyValueMapping<T> mapping,
- final IFactSet<T> factSet, final IPremise<T> premise) {
- super(mapping);
- this.factSet = factSet;
- this.premise = premise;
- }
-
- @Override
- protected boolean addImpl(final List<T> variableValueSet) {
- return true;
- }
-
- @Override
- protected boolean removeImpl(final List<T> variableValueSet) {
- return true;
- }
-
- private class SelectionIterator implements Iterator<List<T>> {
-
- private final Iterator<IFact<T>> iterator;
-
- public SelectionIterator(final IFactSet<T> view) {
- iterator = view.iterator();
- }
-
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public List<T> next() {
- final IFact<T> fact = iterator.next();
- return premise.createVariableValueSet(fact);
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- @Override
- public Iterator<List<T>> select(final List<T> value) {
- final Iterator<T> iterator = value.iterator();
- final T subject;
- if (premise.getSubjectVariableName() == null) {
- subject = premise.getSubject();
- } else {
- subject = iterator.next();
- }
- final T predicate;
- if (premise.getPredicateVariableName() == null) {
- predicate = premise.getPredicate();
- } else {
- predicate = iterator.next();
- }
- final T object;
- if (premise.getObjectVariableName() == null) {
- object = premise.getObject();
- } else {
- object = iterator.next();
- }
- final IFactSet<T> view = selectionView(subject, predicate, object);
- return new SelectionIterator(view);
- }
-
- protected IFactSet<T> selectionView(final T subject, final T predicate,
- final T object) {
- return factSet.view(subject, predicate, object);
- }
-
- // @Override
- // public Iterator<List<T>> removeSelect(final List<T> value) {
- // return select(value);
- // }
-
- private class FactIterator implements Iterator<List<T>> {
-
- private final Iterator<IFact<T>> iterator;
-
- public FactIterator() {
- super();
- iterator = factSet.iterator();
- }
-
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public List<T> next() {
- final IFact<T> nextFact = iterator.next();
- return premise.createVariableValueSet(nextFact);
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- @Override
- public Iterator<List<T>> iterator() {
- return new FactIterator();
- }
-
- @Fortest
- @Override
- public void accept(final ITableVisitor<T> visitor) {
- visitor.beginVisit(this);
- visitor.endVisit(this);
- }
-}
Deleted: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTableAndDefault.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTableAndDefault.java 2010-12-25 03:43:14 UTC (rev 38)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/PremiseVariableTableAndDefault.java 2010-12-25 03:54:07 UTC (rev 39)
@@ -1,71 +0,0 @@
-/*
- * 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.rete.entity;
-
-import net.sf.reasoner4j.fact.CauseIdentifiedFact;
-import net.sf.reasoner4j.fact.IFactSet;
-import net.sf.reasoner4j.fact.SingleFactSet;
-import net.sf.reasoner4j.rule.AbstractPremiseAndDefault;
-
-/**
- *
- * @author luc peuvrier
- *
- * @param <T>
- */
-public class PremiseVariableTableAndDefault<T> extends PremiseVariableTable<T> {
-
- private final T defaultSubject;
-
- private final T defaultPredicate;
-
- private final T defaultObject;
-
- public PremiseVariableTableAndDefault(
- final VariableKeyValueMapping<T> mapping,
- final IFactSet<T> factSet,
- final AbstractPremiseAndDefault<T> premise) {
- super(mapping, factSet, premise);
- defaultSubject = premise.getDefaultSubject();
- defaultPredicate = premise.getDefaultPredicate();
- defaultObject = premise.getDefaultObject();
- }
-
- @Override
- protected IFactSet<T> selectionView(final T subject, final T predicate,
- final T object) {
- IFactSet<T> view = factSet.view(subject, predicate, object);
- if (view.isEmpty()) {
- T dsubject = subject == null ? defaultSubject : subject;
- T dpredicate = predicate == null ? defaultPredicate : predicate;
- T dobject = object == null ? defaultObject : object;
- // FIXMELUC a local minimum implementation of fact set
- view = new SingleFactSet<T>(null, dsubject, dpredicate, dobject);
- view.addFact(new CauseIdentifiedFact<T>(dsubject, dpredicate,
- dobject, 0/*
- * 0 as dummy value , fact not in knowledge base
- */), false);
- }
- return view;
- }
-}
Deleted: trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/VariableTable.java
===================================================================
--- trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/VariableTable.java 2010-12-25 03:43:14 UTC (rev 38)
+++ trunk/reasoner4j/src/main/java/net/sf/reasoner4j/rete/entity/VariableTable.java 2010-12-25 03:54:07 UTC (rev 39)
@@ -1,200 +0,0 @@
-/*
- * 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.rete.entity;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import net.sf.reasoner4j.Fortest;
-
-/**
- *
- * @author luc peuvrier
- *
- * @param <T>
- */
-public class VariableTable<T> extends AbstractVariableTable<T> {
-
- @SuppressWarnings("unchecked")
- private final Set<List<T>> emptySet = Collections.EMPTY_SET;
-
- protected final Map<List<T>, Set<List<T>>> table = new HashMap<List<T>, Set<List<T>>>();
-
- public VariableTable(final VariableKeyValueMapping<T> mapping) {
- super(mapping);
- }
-
- protected boolean addImpl(final List<T> variableValueSet) {
- final List<T> key = mapping.createKey(variableValueSet);
- final List<T> indexedValue = mapping
- .createIndexedValue(variableValueSet);
- Set<List<T>> indexedValueSetForKey = table.get(key);
- if (indexedValueSetForKey == null) {
- indexedValueSetForKey = new HashSet<List<T>>();
- table.put(key, indexedValueSetForKey);
- }
- return indexedValueSetForKey.add(indexedValue);
- }
-
- protected boolean removeImpl(final List<T> variableValueSet) {
- final List<T> key = mapping.createKey(variableValueSet);
- final List<T> indexedValue = mapping
- .createIndexedValue(variableValueSet);
- final Set<List<T>> indexedValueSetForKey = table.get(key);
- final boolean removed;
- if (indexedValueSetForKey == null) {
- removed = false;
- } else {
- removed = indexedValueSetForKey.remove(indexedValue);
- if (indexedValueSetForKey.isEmpty()) {
- table.remove(key);
- }
- }
- return removed;
- }
-
- class SelectionIterator implements Iterator<List<T>> {
-
- private final Iterator<List<T>> iterator;
-
- private final List<T> key;
-
- public SelectionIterator(final List<T> key,
- final Set<List<T>> valueListForKey) {
- super();
- this.key = key;
- iterator = valueListForKey.iterator();
- }
-
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public List<T> next() {
- final List<T> indexedValues = iterator.next();
- return mapping.createValue(key, indexedValues);
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- @Override
- public Iterator<List<T>> select(final List<T> value) {
- final List<T> key = mapping.createKey(value);
- Set<List<T>> valueListForKey = table.get(key);
- if (valueListForKey == null) {
- valueListForKey = emptySet;
- }
- return new SelectionIterator(key, valueListForKey);
- }
-
- // @Override
- // public Iterator<List<T>> removeSelect(final List<T> value) {
- // final List<T> key = mapping.createKey(value);
- // Set<List<T>> valueListForKey = table.remove(key);
- // if (valueListForKey == null) {
- // valueListForKey = emptySet;
- // }
- // return new SelectionIterator(key, valueListForKey);
- // }
-
- private class TableIterator implements Iterator<List<T>> {
-
- private List<T> next;
-
- private Iterator<Entry<List<T>, Set<List<T>>>> mapIterator;
-
- private Iterator<List<T>> keyIterator;
-
- private List<T> key;
-
- public TableIterator() {
- super();
- mapIterator = table.entrySet().iterator();
- computeNext();
- }
-
- @Override
- public boolean hasNext() {
- return next != null;
- }
-
- @Override
- public List<T> next() {
- final List<T> result = next;
- computeNext();
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private void computeNext() {
- if (keyIterator == null || !keyIterator.hasNext()) {
- while (mapIterator.hasNext()) {
- final Entry<List<T>, Set<List<T>>> entry = mapIterator
- .next();
- key = entry.getKey();
- keyIterator = entry.getValue().iterator();
- if (keyIterator.hasNext()) {
- next = mapping.createValue(key, keyIterator.next());
- return;
- }
- }
- next = null;
- } else {
- next = mapping.createValue(key, keyIterator.next());
- }
- }
- }
-
- @Override
- public Iterator<List<T>> iterator() {
- return new TableIterator();
- }
-
- @Fortest
- @Override
- public void accept(final ITableVisitor<T> visitor) {
- visitor.beginVisit(this);
- visitor.endVisit(this);
- }
-
- @Override
- public String toString() {
- return "VariableTable [table=" + table + "]";
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|