Code Search for Developers
 
 
  

UnaryGAF.java from Texai at Krugle


Show UnaryGAF.java syntax highlighted

/*
 * UnaryGAF.java
 *
 * Created on March 30, 2007, 3:19 PM
 *
 * Description: UnaryGAF is a persistent unary 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 UnaryGAF extends AbstractGAF {

  /** the first argument term type */
  private byte arg1TermType;                     

  /** the first argument term id */
  @SecondaryKey(relate=Relationship.MANY_TO_ONE)
  private int arg1TermId;                    

  /** Creates a new instance of UnaryGAF. */
  public UnaryGAF() {
    super();
  }
  
  /** Creates a new instance of UnaryGAF. 
   *
   * @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 UnaryGAF(
          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(),
            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 UnaryGAF. 
   *
   * @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 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 UnaryGAF(
          final int termId,
          final byte predicateTermType,
          final int predicateTermId,
          final byte arg1TermType,
          final int arg1TermId,
          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";

    this.arg1TermType = arg1TermType;
    this.arg1TermId = arg1TermId;
  }
  
  /** Gets the term type.
   *
   * @return the term type
   */
  public byte getTermType() {
    return Constants.UNARY_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.UNARY_ARGS_SIZE);
    final AbstractTerm arg1 = getArg1(kbPartitionFacade);
    assert arg1 != null : "arg1 must not be null, type " + arg1TermType + ", term id " + arg1TermId;
    args.add(arg1);
    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();
  }
  
  /**
   * 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 UnaryGAF)) {
      return false;
    }
    final UnaryGAF that = (UnaryGAF) 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) {
    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) {
    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

Texai

Texai is an chatbot that intelligently seeks to acquire knowledge and friendly behaviors.

Project homepage: http://sourceforge.net/projects/texai
Programming language(s): Java,Shell Script,XML
License: other

  AbstractBookkeepingTerm.java
  AbstractGAF.java
  AbstractReifiedTerm.java
  AbstractTerm.java
  AtomicTerm.java
  BinaryGAF.java
  Formula.java
  LocalTermIdReference.java
  NonAtomicTerm.java
  PByteArray.java
  PDate.java
  PDouble.java
  PLong.java
  PString.java
  PVariable.java
  QuaternaryGAF.java
  QuintaryGAF.java
  RemoteTermIdReference.java
  Rule.java
  StubReifiedTerm.java
  StubTerm.java
  Symbol.java
  TermIdSequence.java
  TernaryGAF.java
  UnaryGAF.java