ConstituentAdapter.java from Texai at Krugle
Show ConstituentAdapter.java syntax highlighted
/*
* ConstituentAdapter.java
*
* Created on January 24, 2007, 8:09 PM
*
* Description: Provides an adapter to connect a constitutent with its parent composed construction, allowing for a
* composed construction's semantics to be distributed among its 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 java.util.Set;
import javax.persistence.Id;
import net.jcip.annotations.NotThreadSafe;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.texai.grammar.Constituent;
import org.texai.kb.Constants;
import org.texai.kb.persistence.RDFEntity;
import org.texai.kb.persistence.RDFNamespace;
import org.texai.kb.persistence.RDFProperty;
import org.texai.util.ArraySet;
/** Provides an adapter to connect a constitutent with its parent composed construction, allowing for a
* composed construction's semantics to be distributed among its 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.ConstituentAdapter", type="cyc:LinguisticObjectType", subClassOf="cyc:ComputerDataStructure", context="texai:EnglishConstructionGrammarDomainContext")
@NotThreadSafe // but effectively immutable
public class ConstituentAdapter {
/** the id assigned by the persistence framework */
@Id
private URI id; // NOPMD
/** the adapted construction constituent */
@RDFProperty(predicate="texai:cxgConstituent")
private Constituent constituent;
/** the constituent position in an ordered list of constituents */
@RDFProperty(predicate="texai:cxgConstituentPosition")
private int constituentPosition;
/** the set of propositions to add to working memory */
@RDFProperty(predicate="texai:cxgProposition")
private Set<Statement> propositions;
/** Creates a new instance of ConstituentAdapter.
*/
public ConstituentAdapter() {
super();
}
/** Creates a new instance of ConstituentAdapter.
*
* @param constituent the construction constituent
*/
public ConstituentAdapter(final Constituent constituent) {
super();
//Preconditions
assert constituent != null : "constituent must not be null";
this.constituent = constituent;
}
/** Creates a new instance of ConstituentAdapter.
*
* @param constituent the construction constituent
* @param constituentPosition the constituent position in an ordered list of constituents
*/
public ConstituentAdapter(final Constituent constituent, final int constituentPosition) {
super();
//Preconditions
assert constituent != null : "constituent must not be null";
assert constituentPosition > -1 : "constituentPosition must not be negative";
this.constituent = constituent;
this.constituentPosition = constituentPosition;
}
/** Gets the id that identifies this instance.
*
* @return the id that identifies this instance
*/
public URI getId() {
return id;
}
/**
* Sets the construction constituent.
*
* @param oconstituentthe ordered construction constituent
*/
public void setConstituent(final Constituent orderedConstituent) {
//Preconditions
assert orderedConstituent != null : "orderedConstituent must not be null";
this.constituent = orderedConstituent;
}
/** Gets the construction constituent.
*
* @return the construction constituent
*/
public Constituent getConstituent() {
return constituent;
}
/** Sets the constituent position in an ordered list of constituents.
*
* @param constituentPosition the constituent position in an ordered list of constituents
*/
public void setConstituentPosition(final int constituentPosition) {
//Preconditions
assert constituentPosition >= 0 : "constituentPosition must not be negative";
this.constituentPosition = constituentPosition;
}
/** Gets the constituent position in an ordered list of constituents.
*
* @return the constituent position in an ordered list of constituents
*/
public int getConstituentPosition() {
return constituentPosition;
}
/** Sets the set of propositions to add to working memory.
*
* @param propositions the set of propositions to add to working memory
*/
public void setPropositions(final Set<Statement> propositions) {
//Preconditions
assert propositions != null : "propositions must not be null";
this.propositions = propositions;
}
/** Gets the set of propositions to add to working memory.
*
* @return the set of propositions to add to working memory
*/
public Set<Statement> getPropositions() {
if (propositions == null) {
propositions = new ArraySet<Statement>();
}
return propositions;
}
/** Adds a propsition to the set of propositions to add to working memory.
*
* @param proposition the proposition
*/
public void addProposition(final Statement proposition) {
//Preconditions
assert proposition != null : "proposition must not be null";
getPropositions().add(proposition);
}
/** 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 ConstituentAdapter) {
final ConstituentAdapter that = (ConstituentAdapter) obj;
return this.getId().equals(that.getId());
} else {
return false;
}
}
}
See more files for this project here