QuaternaryGAF.java from Texai at Krugle
Show QuaternaryGAF.java syntax highlighted
/*
* QuaternaryGAF.java
*
* Created on March 31, 2007, 3:48 AM
*
* Description: QuaternaryGAF is a persistent ternary ground atomic formula (unary propostion) in the Texai logical representation language.
*
* Copyright (C) 2007 Stephen L. Reed.
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.texai.kb.entity;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.texai.kb.Constants;
import org.texai.kb.ejb.session.shared.KBPartitionFacadeLocal;
import org.texai.util.TexaiException;
/**
*
* @author reed
*/
@Entity
public class QuaternaryGAF extends AbstractGAF {
/** the first argument term type */
private byte arg1TermType;
/** the first argument term id */
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private int arg1TermId;
/** the second argument term type */
private byte arg2TermType;
/** the second argument term id */
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private int arg2TermId;
/** the third argument term type */
private byte arg3TermType;
/** the third argument term id */
private int arg3TermId;
/** the fourth argument term type */
private byte arg4TermType;
/** the fourth argument term id */
private int arg4TermId;
/** Creates a new instance of QuaternaryGAF. */
public QuaternaryGAF() {
super();
}
/** Creates a new instance of QuaternaryGAF.
*
* @param termId the database term ID
* @param predicate the predicate
* @param args the argument terms
* @param context the assertion context (i.e. Cyc microtheory)
* @param strength the assertion strength
* @param generatedPhrase the generated phrase for this ground atomic formula
* @param creator the creator
* @param creationPurpose the creation purpose
* @param creationDate the creation date
*/
public QuaternaryGAF(
final int termId,
final AbstractReifiedTerm predicate,
final List<AbstractTerm> args,
final AbstractReifiedTerm context,
final double strength,
final String generatedPhrase,
final AbstractReifiedTerm creator,
final AbstractReifiedTerm creationPurpose,
final Date creationDate) {
this(
termId,
predicate.getTermType(),
predicate.getTermId(),
args.get(Constants.ARG1_INDEX).getTermType(),
args.get(Constants.ARG1_INDEX).getTermId(),
args.get(Constants.ARG2_INDEX).getTermType(),
args.get(Constants.ARG2_INDEX).getTermId(),
args.get(Constants.ARG3_INDEX).getTermType(),
args.get(Constants.ARG3_INDEX).getTermId(),
args.get(Constants.ARG4_INDEX).getTermType(),
args.get(Constants.ARG4_INDEX).getTermId(),
context.getTermType(),
context.getTermId(),
strength,
generatedPhrase,
creator == null ? (byte) 0 : creator.getTermType(),
creator == null ? 0 : creator.getTermId(),
creationPurpose == null ? (byte) 0 : creationPurpose.getTermType(),
creationPurpose == null ? 0 : creationPurpose.getTermId(),
creationDate);
}
/** Creates a new instance of QuaternaryGAF.
*
* @param termId the database term ID
* @param predicateTermType the predicate term type
* @param predicateTermId the predicate term id
* @param arg1TermType the first argument term type
* @param arg1TermId the first argument term id
* @param arg2TermType the second argument term type
* @param arg2TermId the second argument term id
* @param arg3TermType the third argument term type
* @param arg3TermId the third argument term id
* @param arg4TermType the fourth argument term type
* @param arg4TermId the fourth argument term id
* @param contextTermType the assertion context (i.e. Cyc microtheory) term type
* @param contextTermId the assertion context (i.e. Cyc microtheory) term id
* @param strength the assertion strength
* @param generatedPhrase the generated phrase for this ground atomic formula
* @param creatorTermType the creator term type of this ground atomic formula
* @param creatorTermId the creator term id of this ground atomic formula
* @param creationPurposeTermType the creation purpose term type of this ground atomic formula
* @param creationPurposeTermId the creation purpose term id of this ground atomic formula
* @param creationDate the creation date
*/
public QuaternaryGAF(
final int termId,
final byte predicateTermType,
final int predicateTermId,
final byte arg1TermType,
final int arg1TermId,
final byte arg2TermType,
final int arg2TermId,
final byte arg3TermType,
final int arg3TermId,
final byte arg4TermType,
final int arg4TermId,
final byte contextTermType,
final int contextTermId,
final double strength,
final String generatedPhrase,
final byte creatorTermType,
final int creatorTermId,
final byte creationPurposeTermType,
final int creationPurposeTermId,
final Date creationDate) {
super(
termId,
predicateTermType,
predicateTermId,
contextTermType,
contextTermId,
strength,
generatedPhrase,
creatorTermType,
creatorTermId,
creationPurposeTermType,
creationPurposeTermId,
creationDate);
//Preconditions
assert arg1TermType != 0 : "arg1TermType must not be zero";
assert arg1TermId != 0 : "arg1TermId must not be zero";
assert arg2TermType != 0 : "arg2TermType must not be zero";
assert arg2TermId != 0 : "arg2TermId must not be zero";
assert arg3TermType != 0 : "arg3TermType must not be zero";
assert arg3TermId != 0 : "arg3TermId must not be zero";
assert arg4TermType != 0 : "arg4TermType must not be zero";
assert arg4TermId != 0 : "arg4TermId must not be zero";
this.arg1TermType = arg1TermType;
this.arg1TermId = arg1TermId;
this.arg2TermType = arg2TermType;
this.arg2TermId = arg2TermId;
this.arg3TermType = arg3TermType;
this.arg3TermId = arg3TermId;
this.arg4TermType = arg4TermType;
this.arg4TermId = arg4TermId;
}
/** Gets the term type.
*
* @return the term type
*/
public byte getTermType() {
return Constants.QUATERNARY_GAF;
}
/** Returns the arguments.
*
* @param kbPartitionFacade the KB partition facade
* @return the arguments
*/
public List<AbstractTerm> getArgs(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
assert kbPartitionFacade != null : "kbPartitionFacade must not be null";
final List<AbstractTerm> args = new ArrayList<AbstractTerm>(Constants.QUATERNARY_ARGS_SIZE);
final AbstractTerm arg1 = getArg1(kbPartitionFacade);
assert arg1 != null : "arg1 must not be null, type " + arg1TermType + ", term id " + arg1TermId;
args.add(arg1);
final AbstractTerm arg2 = getArg2(kbPartitionFacade);
assert arg2 != null : "arg2 must not be null, type " + arg2TermType + ", term id " + arg2TermId;
args.add(arg2);
final AbstractTerm arg3 = getArg3(kbPartitionFacade);
assert arg3 != null : "arg3 must not be null, type " + arg3TermType + ", term id " + arg3TermId;
args.add(arg3);
final AbstractTerm arg4 = getArg4(kbPartitionFacade);
assert arg4 != null : "arg4 must not be null, type " + arg4TermType + ", term id " + arg4TermId;
args.add(arg4);
return args;
}
/** Gets the arg1 term type.
*
* @return the arg1 term type
*/
public byte getArg1TermType() {
return arg1TermType;
}
/** Sets the arg1 term type.
*
* @param arg1TermType the arg1 term type
*/
public void setArg1TermType(final byte arg1TermType) {
this.arg1TermType = arg1TermType;
}
/** Gets the arg1 term id.
*
* @return the arg1 term id
*/
public int getArg1TermId() {
return arg1TermId;
}
/** Sets the arg1 term id.
*
* @param arg1TermId the arg1 term id
*/
public void setArg1TermId(final int arg1TermId) {
//Preconditions
assert arg1TermId !=0 : "arg1TermId must not be zero";
this.arg1TermId = arg1TermId;
}
/** Gets the first argument
*
* @param kbPartitionFacade the KB partition facade
* @return the first argument
*/
public AbstractTerm getArg1(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
if (kbPartitionFacade == null) {
throw new TexaiException("kbPartitionFacade must not be null");
}
return kbPartitionFacade.findTermByTermTypeAndId(arg1TermType, arg1TermId);
}
/** Sets the first argument.
*
* @param arg1 the first argument
*/
public void setArg1(final AbstractTerm arg1) {
//Preconditions
assert arg1 != null : "arg1 must not be null";
arg1TermType = arg1.getTermType();
arg1TermId = arg1.getTermId();
}
/** Gets the arg2 term type
*
* @return the arg2 term type
*/
public byte getArg2TermType() {
return arg2TermType;
}
/** Gets the arg2 term type.
*
* @return the arg2 term type
*/
public void setArg2TermType(final byte arg2TermType) {
this.arg2TermType = arg2TermType;
}
/** Gets the arg2 term id.
*
* @return the arg2 term id
*/
public int getArg2TermId() {
return arg2TermId;
}
/** Sets the arg2 term id.
*
* @param arg2TermId the arg2 term id
*/
public void setArg2TermId(final int arg2TermId) {
//Preconditions
assert arg1TermId != 0 : "arg1TermId must not be zero";
this.arg2TermId = arg2TermId;
}
/** Gets the second argument
*
* @param kbPartitionFacade the KB partition facade
* @return the second argument
*/
public AbstractTerm getArg2(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
if (kbPartitionFacade == null) {
throw new TexaiException("kbPartitionFacade must not be null");
}
return kbPartitionFacade.findTermByTermTypeAndId(arg2TermType, arg2TermId);
}
/** Sets the second argument.
*
* @param arg2 the second argument
*/
public void setArg2(final AbstractTerm arg2) {
//Preconditions
assert arg2 != null : "arg2 must not be null";
arg2TermType = arg2.getTermType();
arg2TermId = arg2.getTermId();
}
/** Gets the arg3 term type
*
* @return the arg3 term type
*/
public byte getArg3TermType() {
return arg3TermType;
}
/** Gets the arg3 term type.
*
* @return the arg3 term type
*/
public void setArg3TermType(final byte arg3TermType) {
this.arg3TermType = arg3TermType;
}
/** Gets the arg3 term id.
*
* @return the arg3 term id
*/
public int getArg3TermId() {
return arg3TermId;
}
/** Sets the arg3 term id.
*
* @param arg3TermId the arg3 term id
*/
public void setArg3TermId(final int arg3TermId) {
//Preconditions
assert arg3TermId != 0 : "arg3TermId must not be zero";
this.arg3TermId = arg3TermId;
}
/** Gets the third argument
*
* @param kbPartitionFacade the KB partition facade
* @return the third argument
*/
public AbstractTerm getArg3(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
if (kbPartitionFacade == null) {
throw new TexaiException("kbPartitionFacade must not be null");
}
return kbPartitionFacade.findTermByTermTypeAndId(arg3TermType, arg3TermId);
}
/** Sets the third argument.
*
* @param arg3 the third argument
*/
public void setArg3(final AbstractTerm arg3) {
//Preconditions
assert arg3 != null : "arg3 must not be null";
arg3TermType = arg3.getTermType();
arg3TermId = arg3.getTermId();
}
/** Gets the arg4 term type
*
* @return the arg4 term type
*/
public byte getArg4TermType() {
return arg4TermType;
}
/** Gets the arg4 term type.
*
* @return the arg4 term type
*/
public void setArg4TermType(final byte arg4TermType) {
this.arg4TermType = arg4TermType;
}
/** Gets the arg4 term id.
*
* @return the arg4 term id
*/
public int getArg4TermId() {
return arg4TermId;
}
/** Sets the arg4 term id.
*
* @param arg4TermId the arg4 term id
*/
public void setArg4TermId(final int arg4TermId) {
//Preconditions
assert arg4TermId != 0 : "arg4TermId must not be zero";
this.arg4TermId = arg4TermId;
}
/** Gets the fourth argument
*
* @param kbPartitionFacade the KB partition facade
* @return the fourth argument
*/
public AbstractTerm getArg4(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
if (kbPartitionFacade == null) {
throw new TexaiException("kbPartitionFacade must not be null");
}
return kbPartitionFacade.findTermByTermTypeAndId(arg4TermType, arg4TermId);
}
/** Sets the fourth argument.
*
* @param arg4 the fourth argument
*/
public void setArg4(final AbstractTerm arg4) {
//Preconditions
assert arg4 != null : "arg4 must not be null";
arg4TermType = arg4.getTermType();
arg4TermId = arg4.getTermId();
}
/**
* Returns a hash code value for the object.
* @return a hash code value for this object
*/
@Override
public int hashCode() {
return getTermId();
}
/**
* Determines whether another object is equal to this object.
*
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(final Object object) {
if (!(object instanceof QuaternaryGAF)) {
return false;
}
final QuaternaryGAF that = (QuaternaryGAF) object;
return this.getTermId() == that.getTermId();
}
/** Returns a string representation of this object.
*
* @param kbPartitionFacade the KB partition facade
* @return a string representation of this object
*/
public String toString(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
assert kbPartitionFacade != null : "kbPartitionFacade must not be null";
final StringBuilder stringBuilder = new StringBuilder(Constants.STRING_BUILDER_SIZE);
stringBuilder.append(getPredicate(kbPartitionFacade).toString(kbPartitionFacade));
stringBuilder.append("(");
final List<AbstractTerm> args = getArgs(kbPartitionFacade);
final int arity = args.size();
for (int i = 0; i < arity; i++) {
stringBuilder.append(args.get(i).toString());
if (i < arity - 1) {
stringBuilder.append(", ");
}
}
stringBuilder.append(")");
return stringBuilder.toString();
}
/** Returns a CycL representation of this object.
*
* @param kbPartitionFacade the KB partition facade
* @return a CycL representation of this object
*/
public String toCycLString(final KBPartitionFacadeLocal kbPartitionFacade) {
//Preconditions
assert kbPartitionFacade != null : "kbPartitionFacade must not be null";
final StringBuilder stringBuilder = new StringBuilder(Constants.STRING_BUILDER_SIZE);
stringBuilder.append("(");
stringBuilder.append(getPredicate(kbPartitionFacade).toCycLString(kbPartitionFacade));
final List<AbstractTerm> args = getArgs(kbPartitionFacade);
final int arity = args.size();
for (int i = 0; i < arity; i++) {
stringBuilder.append(" ");
stringBuilder.append(args.get(i).toCycLString(kbPartitionFacade));
}
stringBuilder.append(")");
return stringBuilder.toString();
}
}
See more files for this project here