TexaiSamplePhrase.java from Texai at Krugle
Show TexaiSamplePhrase.java syntax highlighted
/*
* TexaiSamplePhrase.java
*
* Created on February 28, 2007, 8:43 PM
*
* Description: Provides a sample phrase entity.
*
* 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.lexicon.domainEntity;
import javax.persistence.Id;
import net.jcip.annotations.NotThreadSafe;
import org.openrdf.model.URI;
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 sample phrase entity.
*
* @author reed
*/
@RDFEntity(
namespaces={
@RDFNamespace(prefix="texai", namespaceURI=Constants.TEXAI_NAMESPACE),
@RDFNamespace(prefix="cyc", namespaceURI=Constants.CYC_NAMESPACE)},
subject="texai:org.texai.lexicon.domainEntity.TexaiEnglishWord", type="cyc:LinguisticObjectType", subClassOf="cyc:AbstractInformationStructure", context="texai:TexaiEnglishLexiconContext")
@NotThreadSafe // but effectively immutable
public class TexaiSamplePhrase {
/** the id assigned by the persistence framework */
@Id
private URI id; // NOPMD
/** the sample phrase */
@RDFProperty(predicate="texai:texaiSamplePhraseText")
private String samplePhrase; // NOPMD
/** the word sense for which this is a sample phrase */
@RDFProperty(predicate="texai:texaiWordSenseSamplePhrase", inverse=true)
private TexaiEnglishWordSense texaiEnglishWordSense;
/** Creates a new instance of TexaiSamplePhrase. */
public TexaiSamplePhrase() {
super();
}
/** Creates a new instance of TexaiSamplePhrase.
*
* @param samplePhrase the sample phrase
* @param texaiEnglishWordSense the word sense for which this is a sample phrase
*/
public TexaiSamplePhrase(final String samplePhrase, final TexaiEnglishWordSense texaiEnglishWordSense) {
super();
//Preconditions
assert samplePhrase != null : "samplePhrase must not be null";
assert !samplePhrase.isEmpty() : "samplePhrase must not be an empty string";
assert texaiEnglishWordSense != null : "texaiEnglishWordSense must not be null";
this.samplePhrase = samplePhrase;
this.texaiEnglishWordSense = texaiEnglishWordSense;
}
/** Gets the id that identifies this instance.
*
* @return the id that identifies this instance
*/
public URI getId() {
return id;
}
/** Gets the sample phrase.
*
* @return the sample phrase
*/
public String getSamplePhrase() {
return samplePhrase;
}
/** Sets the sample phrase.
*
* @param samplePhrase the sample phrase
*/
public void setSamplePhrase(String samplePhrase) {
//Preconditions
assert samplePhrase != null : "samplePhrase must not be null";
assert !samplePhrase.isEmpty() : "samplePhrase must not be an empty string";
this.samplePhrase = samplePhrase;
}
/** Gets the word sense for which this is a sample phrase.
*
* @return the word sense for which this is a sample phrase
*/
public TexaiEnglishWordSense getTexaiEnglishWordSense() {
return texaiEnglishWordSense;
}
/** Sets the word sense for which this is a sample phrase.
*
* @param texaiEnglishWordSense the word sense for which this is a sample phrase
*/
public void setTexaiEnglishWordSense(TexaiEnglishWordSense texaiEnglishWordSense) {
//Preconditions
assert texaiEnglishWordSense != null : "texaiEnglishWordSense must not be null";
this.texaiEnglishWordSense = texaiEnglishWordSense;
}
/** 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 TexaiSamplePhrase) {
final TexaiSamplePhrase that = (TexaiSamplePhrase) obj;
return this.getId().equals(that.getId());
} else {
return false;
}
}
/** 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 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);
stringBuilder.append("[SAMPLE PHRASE \"");
stringBuilder.append(samplePhrase);
stringBuilder.append("\"]");
return stringBuilder.toString();
}
}
See more files for this project here