📄 tmpclause.java
字号:
package org.mandarax.reference;
/*
* Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.apache.commons.collections.iterators.IteratorChain;
import org.mandarax.kernel.AbstractClause;
import org.mandarax.kernel.Clause;
import org.mandarax.kernel.ClauseSet;
import org.mandarax.kernel.Fact;
import org.mandarax.kernel.Replacement;
/**
* Simple clause class for internal use in the inference engine.
* @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
* @version 3.4 <7 March 05>
* @since 1.0
* Prova re-integration modifications
* @author <A HREF="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</A>
* @version 3.4 <7 March 05>
*/
public final class TmpClause extends AbstractClause {
public List negativeLiterals = null;
public List positiveLiterals = null;
/**
* Constructor.
*/
public TmpClause() {
super ();
}
/**
* Constructor.
* @param posLit positive literals
* @param negLit negative literals
*/
public TmpClause(List posLit, List negLit) {
this ();
negativeLiterals = negLit;
positiveLiterals = posLit;
}
/**
* Apply a set of substitutions.
* @return a clause that is the result of applying the replacements
* @param r a collection of replacements
*/
public Clause apply(Collection r) {
TmpClause c = new TmpClause ();
c.positiveLiterals = new Vector (positiveLiterals.size ());
c.negativeLiterals = new Vector (negativeLiterals.size ());
for(Iterator it = positiveLiterals.iterator (); it.hasNext (); ) {
c.positiveLiterals.add (((Fact) it.next ()).apply (r));
}
for(Iterator it = negativeLiterals.iterator (); it.hasNext (); ) {
c.negativeLiterals.add (((Fact) it.next ()).apply (r));
}
return c;
}
/**
* Apply a substitutions.
* @return a clause that is the result of applying the replacement
* @param r a replacement
*/
public Clause apply(Replacement r) {
TmpClause c = new TmpClause ();
c.positiveLiterals = new Vector (positiveLiterals.size ());
c.negativeLiterals = new Vector (negativeLiterals.size ());
for(Iterator it = positiveLiterals.iterator (); it.hasNext (); ) {
c.positiveLiterals.add (((Fact) it.next ()).apply (r));
}
for(Iterator it = negativeLiterals.iterator (); it.hasNext (); ) {
c.negativeLiterals.add (((Fact) it.next ()).apply (r));
}
return c;
}
/**
* Get the key.
* @return the key object
*/
public Object getKey() {
try {
return((Fact) negativeLiterals.get (0)).getPredicate ();
} catch(Throwable t) {
LOG_KB.error("Error getting key of a clause !",t);
}
return null;
}
public boolean isBound() {
return false;
}
/**
* Get the negative literals.
* @return a list containing the negative literals
*/
public List getNegativeLiterals() {
return negativeLiterals;
}
/**
* Get the positive literals.
* @return a list containing the positive literals
*/
public List getPositiveLiterals() {
return positiveLiterals;
}
/**
* Indicates whether the clause is atomic.
* @return a boolean
*/
public boolean isAtomic() {
return true;
}
/**
* Indicate whether this is the empty clause.
* @return true if there are no literals, false otherwise
*/
public boolean isEmpty() {
return negativeLiterals.isEmpty () && positiveLiterals.isEmpty ();
}
/**
* Indicates whether the object (usually a term or a clause set) can be performed
* using the java semantics.
* @return a boolean
*/
public boolean isExecutable() {
return false;
}
/**
* Convert the receiver to a string.
* @return the string representation of this object
*/
public String toString() {
StringBuffer buf = new StringBuffer ();
boolean first = true;
buf.append ("+[");
if(positiveLiterals != null) {
for(Iterator it = positiveLiterals.iterator (); it.hasNext (); ) {
if(first) {
first = false;
} else {
buf.append (",");
}
buf.append (it.next ().toString ());
}
}
buf.append ("] , -[");
first = true;
if(negativeLiterals != null) {
for(Iterator it = negativeLiterals.iterator (); it.hasNext (); ) {
if(first) {
first = false;
} else {
buf.append (",");
}
buf.append (it.next ().toString ());
}
}
buf.append ("]");
return new String (buf);
}
/**
* Get an iterator iterating over the predicates contained in this clause set.
* @return an iterator
*/
public Iterator predicates() {
List chain = new ArrayList();
if (negativeLiterals!=null) {
for (int i=0;i<negativeLiterals.size();i++) {
chain.add(((ClauseSet)negativeLiterals.get(i)).predicates());
}
}
if (positiveLiterals!=null) {
for (int i=0;i<positiveLiterals.size();i++) {
chain.add(((ClauseSet)positiveLiterals.get(i)).predicates());
}
}
return new IteratorChain(chain);
}
/**
* Indicates whether the clause is ground (= does not have variables).
* @return a boolean
*/
public boolean isGround() {
if (this.positiveLiterals!=null) {
for (int i=0;i<this.positiveLiterals.size();i++) {
if (!((Clause)this.positiveLiterals.get(i)).isGround()) return false;
}
}
if (this.negativeLiterals!=null) {
for (int i=0;i<this.negativeLiterals.size();i++) {
if (!((Clause)this.negativeLiterals.get(i)).isGround()) return false;
}
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -