SimpleConstruction.java from Texai at Krugle
Show SimpleConstruction.java syntax highlighted
/*
* SimpleConstruction.java
*
* Created on January 17, 2007, 1:06 PM
*
* Description: Provides a construction to decorate another constituent, typically an instance contains word sense
* information for a constitutent that is a word.
*
* 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 org.texai.grammar.Constituent;
import org.texai.grammar.understanding.ActiveConstituent;
import org.texai.grammar.understanding.ActiveSimpleConstruction;
import org.texai.kb.Constants;
import org.texai.kb.ejb.entity.AtomicTerm;
import org.texai.kb.persistence.DomainEntity;
import org.texai.kb.persistence.DomainProperty;
/**
*
* @author reed
*/
@DomainEntity(typeOf={Constants.TERM_NAME_LINGUISTIC_OBJECT_TYPE}, subClassOf={Constants.TERM_NAME_CXG_COMPOSED_CONSTRUCTION})
public class SimpleConstruction extends AbstractComposedConstruction {
/** the simple constituent adapter */
@DomainProperty(name="cxgSimpleConstituentAdapter", domain=Constants.TERM_NAME_CXG_COMPOSED_CONSTRUCTION)
private ConstituentAdapter simpleConstituentAdapter;
/** Creates a new instance of SimpleConstruction. */
public SimpleConstruction() {
super();
setLoggerUsingClass(this.getClass());
}
/** Creates a new instance of SimpleConstruction.
*
* @param name the construction name that identifies this instance
* @param naturalLanguage the natural language to which this construction applies
*/
public SimpleConstruction(final String name, final AtomicTerm naturalLanguage) {
super(name, naturalLanguage);
setLoggerUsingClass(this.getClass());
}
/**
* Sets the simple constituent adapter.
*
* @param simpleConstituentAdapter the simple constituent adapter
*/
public void setSimpleConstituentAdapter(final ConstituentAdapter simpleConstituentAdapter) {
//Preconditions
assert simpleConstituentAdapter != null : "simpleConstituentAdapter must not be null";
this.simpleConstituentAdapter = simpleConstituentAdapter;
}
/** Gets the simple constituent adapter.
*
* @return the simple constituent adapter
*/
public ConstituentAdapter getSimpleConstituentAdapter() {
return simpleConstituentAdapter;
}
/** Gets the simple construction constituent.
*
* @return the simple construction constituent
*/
public Constituent getSimpleConstituent() {
return simpleConstituentAdapter.getConstituent();
}
/** Decorates this construction with an active construction that contains the
* behavior and transient state for parsing text.
*
* @return an ActiveSimpleConstruction that decorates this object
*/
public ActiveConstituent decorate() {
return new ActiveSimpleConstruction(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 simpleConstituentAdapter != null : "simpleConstituentAdapter must not be null";
if (simpleConstituentAdapter.getConstituent().equals(constituent)) {
return simpleConstituentAdapter;
} else {
return null;
}
}
/** Returns a hash code for this object.
*
* @return a hash code for this object
*/
@Override
public int hashCode() {
if (getTermId() == null) {
return super.hashCode();
} else {
return getTermId().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 SimpleConstruction) {
final SimpleConstruction that = (SimpleConstruction) obj;
return this.getTermId().equals(that.getTermId());
} else {
return false;
}
}
}
See more files for this project here