RepetitiveConstruction.java from Texai at Krugle
Show RepetitiveConstruction.java syntax highlighted
/*
* RepetitiveConstruction.java
*
* Created on January 16, 2007, 7:48 PM
*
* Description: Provides a construction with repetitive constituents.
*
* 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 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.ActiveRepetitiveConstruction;
import org.texai.kb.Constants;
import org.texai.kb.persistence.RDFEntity;
import org.texai.kb.persistence.RDFNamespace;
import org.texai.kb.persistence.RDFProperty;
/** Provides a construction with repetitive constituents.
*
* @author reed
*/
@RDFEntity(
namespaces={
@RDFNamespace(prefix="texai", namespaceURI=Constants.TEXAI_NAMESPACE),
@RDFNamespace(prefix="cyc", namespaceURI=Constants.CYC_NAMESPACE)},
subject="texai:org.texai.grammar.domainEntity.RepetitiveConstruction", type="cyc:LinguisticObjectType", subClassOf="texai:CxgComposedConstruction", context="texai:EnglishConstructionGrammarDomainContext")
@NotThreadSafe // but effectively immutable
public class RepetitiveConstruction extends AbstractComposedConstruction {
/** the repetitive constituent adapter */
@RDFProperty(predicate="cxgRepetitiveConstituentAdapter")
private ConstituentAdapter repetitiveConstituentAdapter;
/** Creates a new instance of RepetitiveConstruction. */
public RepetitiveConstruction() {
super();
setLoggerUsingClass(this.getClass());
}
/** Creates a new instance of OptionalConstruction.
*
* @param name the construction name that identifies this instance
* @param naturalLanguage the natural language to which this construction applies
*/
public RepetitiveConstruction(final String name, final URI naturalLanguage) {
super(name, naturalLanguage);
setLoggerUsingClass(this.getClass());
}
/**
* Sets the repetitive constituent adapter.
*
* @param repetitiveConstituentAdapterthe repetitive constituent adapter
*/
public void setRepetitiveConstituentAdapter(final ConstituentAdapter repetitiveConstituentAdapter) {
//Preconditions
assert repetitiveConstituentAdapter != null : "repetitiveConstituentAdapter must not be null";
this.repetitiveConstituentAdapter = repetitiveConstituentAdapter;
}
/** Gets the repetitive constituent adapter.
*
* @return the repetitive constituent adapter
*/
public ConstituentAdapter getRepetitiveConstituentAdapter() {
return repetitiveConstituentAdapter;
}
/** Gets the optional construction constituent.
*
* @return the optional construction constituent
*/
public Constituent getOptionalConstituent() {
return repetitiveConstituentAdapter.getConstituent();
}
/** Decorates this construction with an active construction that contains the
* behavior and transient state for parsing text.
*
* @return an ActiveRepetitiveConstruction that decorates this object
*/
public ActiveConstituent decorate() {
return new ActiveRepetitiveConstruction(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 repetitiveConstituentAdapter != null : "repetitiveConstituentAdapter must not be null";
if (repetitiveConstituentAdapter.getConstituent().equals(constituent)) {
return repetitiveConstituentAdapter;
} else {
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 RepetitiveConstruction) {
final RepetitiveConstruction that = (RepetitiveConstruction) obj;
return this.getId().equals(that.getId());
} else {
return false;
}
}
}
See more files for this project here