Code Search for Developers
 
 
  

AbstractConstruction.java from Texai at Krugle


Show AbstractConstruction.java syntax highlighted

/*
 * AbstractConstruction.java
 *
 * Created on January 15, 2007, 7:35 PM
 *
 * Description: Provides the abstract construction that contains common variables and behavior.
 *
 * 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.grammar.domainEntity;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Id;
import net.jcip.annotations.NotThreadSafe;
import org.apache.log4j.Logger;
import org.openrdf.model.URI;
import org.texai.grammar.ComposedConstruction;
import org.texai.grammar.Constituent;
import org.texai.kb.Constants;
import org.texai.kb.persistence.RDFProperty;

/** Provides the abstract construction that contains common variables and behavior.
 *
 * @author reed
 */
@NotThreadSafe  // but effectively immutable
public abstract class AbstractConstruction implements Constituent {
  
  /** the id assigned by the persistence framework */
  @Id
  private URI id;                                          // NOPMD
  
  /** the construction name that identifies this instance */
  @RDFProperty(predicate="texai:cxgConstructionName")
  private String name;
  
  /** the natural language to which this construction applies */
  @RDFProperty(predicate="texai:cxgConstructionNaturalLanguage")
  private URI naturalLanguage;
  
  /** the parent composed constructions that have this as a child */
  @RDFProperty(predicate="texai:cxgParentComposedConstruction", range="texai:CxgComposedConstruction")
  private Set<ComposedConstruction> parentComposedConstructions;
  
  /** the set of composed constructions that are activated by this word */
  @RDFProperty(predicate="texai:cxgActivatedComposedConstruction", range="texai:CxgComposedConstruction")
  public Set<ComposedConstruction> activatedComposedConstructions;
  
  /** the concrete subclass used for naming the logger */
  private Class subclass;
  
  /** the logger */
  private Logger logger;                         // NOPMD
  
  /** Creates a new instance of AbstractConstruction. */
  public AbstractConstruction() {
    super();
  }
  
  /** Creates a new instance of AbstractConstruction.
   *
   * @param name the construction name that identifies this instance
   * @param naturalLanguage the natural language to which this construction applies
   */
  public AbstractConstruction(final String name, final URI naturalLanguage) {
    super();
    //Preconditions
    assert name != null : "name must not be null";
    assert name.length() > 0 : "name must not be an empty string";
    assert naturalLanguage != null : "naturalLanguage must not be null";
    
    this.name = name;
    this.naturalLanguage = naturalLanguage;
  }
  
  /** Gets the id that identifies this instance.
   *
   * @return the id that identifies this instance
   */
  public URI getId() {
    return id;
  }
  
  /** Sets the construction name.
   *
   * @param name the construction name
   */
  public void setName(final String name) {
    //Preconditions
    assert name != null : "name must not be null";
    assert name.length() > 0 : "name must not be an empty string";
    
    this.name = name;
  }
  
  /** Gets the construction name.
   *
   * @return the construction name
   */
  public String getName() {
    return name;
  }
  
  /** Sets the natural language to which this construction applies.
   *
   * @param naturalLanguage the natural language to which this construction applies
   */
  public void setNaturalLanguage(final URI naturalLanguage) {
    //Preconditions
    assert naturalLanguage != null : "naturalLanguage must not be null";
    
    this.naturalLanguage = naturalLanguage;
  }
  
  /** Gets the natural language to which this construction applies.
   *
   * @return naturalLanguage
   */
  public URI getNaturalLanguage() {
    return naturalLanguage;
  }
  
  /** Sets the parent composed constructions that have this as a child.
   *
   * @param parentComposedConstructions the parent composed constructions that have this as a child
   */
  public void setParentComposedConstructions(final Set<ComposedConstruction> parentComposedConstructions) {
    //Preconditions
    assert parentComposedConstructions != null : "parentComposedConstructions must not be null";
    
    this.parentComposedConstructions = parentComposedConstructions;
  }
  
  /** Gets the parent composed constructions that have this as a child.
   *
   * @return the parent composed constructions that have this as a child
   */
  public Set<ComposedConstruction> getParentComposedConstructions() {
    if (parentComposedConstructions == null) {
      parentComposedConstructions = new HashSet<ComposedConstruction>();
    }
    return parentComposedConstructions;
  }
  
  /**
   * Sets the set of composed constructions that are activated by this word.
   *
   * @param activatedComposedConstructions the set of composed constructions that are activated by this word
   */
  public void setActivatedComposedConstructions(final Set<ComposedConstruction> activatedComposedConstructions) {
    //Preconditions
    assert activatedComposedConstructions != null : "activatedComposedConstructions must not be null";
    
    this.activatedComposedConstructions = activatedComposedConstructions;
  }
  
  /** Gets the set of composed constructions that are activated by this word.
   *
   * @return the set of composed constructions that are activated by this word
   */
  public Set<ComposedConstruction> getActivatedComposedConstructions() {
    if (activatedComposedConstructions == null) {
      activatedComposedConstructions = new HashSet<ComposedConstruction>();
    }
    return activatedComposedConstructions;
  }
  
  /** Returns a string representation of this object.
   *
   * @return a string representation of this object
   */
  @Override
  public String toString() {
    final StringBuilder stringBuilder = new StringBuilder(Constants.STRING_BUILDER_SIZE_SMALL);
    stringBuilder.append("[");
    final String className = this.getClass().getName();
    final int index = className.lastIndexOf('.');
    if (index == -1) {
      stringBuilder.append(className);
    } else {
      stringBuilder.append(className.substring(index + 1));
    }
    stringBuilder.append(": ");
    if (name != null) {
      stringBuilder.append(name);
    }
    stringBuilder.append("]");
    return stringBuilder.toString();
  }
  
  /** Sets the logger.
   *
   * @param subclass the class that provides the logger name
   */
  protected void setLoggerUsingClass(final Class subclass) {
    //Preconditions
    assert subclass != null : "subclass must not be null";
    
    this.logger = Logger.getLogger(subclass);
  }
  
  /** Gets the logger.
   *
   * @return the logger
   */
  protected Logger getLogger() {
    return logger;
  }
}




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

  AbstractComposedConstruction.java
  AbstractConstruction.java
  AlternativeConstruction.java
  CategoryConstruction.java
  ConstituentAdapter.java
  OptionalConstruction.java
  RegularExpression.java
  RegularExpression_GroupVariableInfo.java
  RepetitiveConstruction.java
  SequenceConstruction.java
  SimpleConstruction.java
  ValidateGrammarEntities.java
  WordFormConstruction.java
  WordSenseConstruction.java
  XMLTagWord.java