Code Search for Developers
 
 
  

SequenceConstruction.java from Texai at Krugle


Show SequenceConstruction.java syntax highlighted

/*
 * SequenceConstruction.java
 *
 * Created on January 5, 2007, 3:02 PM
 *
 * Description: Provides SequenceConstruction Grammar (CxG) patterns for the comprehension and production of natural language text.
 *
 * Copyright (C) 2006 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.ArrayList;
import java.util.List;
import javax.persistence.OrderBy;
import net.jcip.annotations.NotThreadSafe;
import org.openrdf.model.URI;
import org.texai.grammar.Constituent;
import org.texai.grammar.understanding.ActiveConstituent;
import org.texai.grammar.understanding.ActiveSequenceConstruction;
import org.texai.kb.Constants;
import org.texai.kb.persistence.RDFEntity;
import org.texai.kb.persistence.RDFNamespace;
import org.texai.kb.persistence.RDFProperty;

/** Provides SequenceConstruction Grammar (CxG) patterns for the comprehension and production of natural language text.
 *
 * @author reed
 */
@RDFEntity(
namespaces={
  @RDFNamespace(prefix="texai", namespaceURI=Constants.TEXAI_NAMESPACE),
  @RDFNamespace(prefix="cyc", namespaceURI=Constants.CYC_NAMESPACE)},
subject="texai:org.texai.grammar.domainEntity.SequenceConstruction", type="cyc:LinguisticObjectType", subClassOf="texai:CxgComposedConstruction", context="texai:EnglishConstructionGrammarDomainContext")
@NotThreadSafe  // but effectively immutable
public class SequenceConstruction extends AbstractComposedConstruction {
  
  /** the ordered construction constituent adapters */
  @OrderBy("constituentPosition")
  @RDFProperty(predicate="texai:cxgOrderedConstituentAdapter", range="texai:org.texai.grammar.domainEntity.ConstituentAdapter")
  private List<ConstituentAdapter> orderedConstituentAdapters;
  
  /**
   * Creates a new instance of SequenceConstruction.
   */
  public SequenceConstruction() {
    super();
    setLoggerUsingClass(this.getClass());
  }
 
  /** Creates a new instance of SequenceConstruction.
   *
   * @param name the construction name that identifies this instance
   * @param naturalLanguage the natural language to which this construction applies
   */
  public SequenceConstruction(final String name, final URI naturalLanguage) {
    super(name, naturalLanguage);
    setLoggerUsingClass(this.getClass());
  }
  
  /**
   * Sets the ordered construction constituent adapters.
   * 
   * @param orderedConstituentAdapters ordered construction constituent adapters
   */
  public void setOrderedConstituentAdapters(final List<ConstituentAdapter> orderedConstituentAdapters) {
    //Preconditions
    assert orderedConstituentAdapters != null : "orderedConstituentAdapters must not be null";
    
    this.orderedConstituentAdapters = orderedConstituentAdapters;
  }
  
  /** Gets the ordered construction constituent adapters.
   *
   * @return the ordered construction constituent adapters
   */
  public List<ConstituentAdapter> getOrderedConstituentAdapters() {
    if (orderedConstituentAdapters == null) {
      orderedConstituentAdapters = new ArrayList<ConstituentAdapter>();
    }
    return orderedConstituentAdapters;
  }
  
  /** Returns the list of construction constituents.
   *
   * @return the list of construction constituents
   */
  public List<Constituent> getConstituents() {
    final List<Constituent> constituents = new ArrayList<Constituent>(getOrderedConstituentAdapters().size());
    for (final ConstituentAdapter constituentAdapter : orderedConstituentAdapters) {
      constituents.add(constituentAdapter.getConstituent());
    }
    return constituents;
  }
  
 /** Decorates this construction with an active construction that contains the 
   * behavior and transient state for parsing text.
   *
   * @return an ActiveSequenceConstruction that decorates this object
   */
  public ActiveConstituent decorate() {
    return new ActiveSequenceConstruction(this);
  }
  
  /** Returns the constituent adapter that contains the given child constituent.
   *
   * @param constituent the given child constituent
   * @return the constituent adapter that contains the given child constituent, or null if not found 
   */
  public ConstituentAdapter findAdapter(final Constituent constituent) {
    //Preconditions
    assert constituent != null : "constituent must not be null";
    assert orderedConstituentAdapters != null : "orderedConstituentAdapters must not be null";
    
    for (final ConstituentAdapter orderedConstituentAdapter : orderedConstituentAdapters) {
      if (orderedConstituentAdapter.getConstituent().equals(constituent)) {
        return orderedConstituentAdapter;
      }    
    }
    return null;
  }
  
  /** Returns a hash code for this object.
   *
   * @return a hash code for this object
   */
  @Override
  public int hashCode() {
    if (getId() == null) {
      return super.hashCode();
    } else {
      return getId().hashCode();
    }
  }
  
  /** Returns whether the given object is equal to this object.
   *
   * @param obj the given object
   * @return whether the given object is equal to this object
   */
  @Override
  public boolean equals(final Object obj) {
    if (obj instanceof SequenceConstruction) {
      final SequenceConstruction that = (SequenceConstruction) obj;
      return this.getId().equals(that.getId());
    } else {
      return false;
    } 
  }
  
}




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