WordSenseConstruction.java from Texai at Krugle
Show WordSenseConstruction.java syntax highlighted
/*
* WordSenseConstruction.java
*
* Created on February 10, 2007, 6:01 PM
*
* Description: Provides a word sense construction.
*
* 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.kb.Constants;
import org.texai.kb.persistence.RDFEntity;
import org.texai.kb.persistence.RDFNamespace;
import org.texai.kb.persistence.RDFProperty;
import org.texai.lexicon.domainEntity.TexaiEnglishWordSense;
/** Provides a word sense construction.
*
* @author reed
*/
@RDFEntity(
namespaces={
@RDFNamespace(prefix="texai", namespaceURI=Constants.TEXAI_NAMESPACE),
@RDFNamespace(prefix="cyc", namespaceURI=Constants.CYC_NAMESPACE)},
subject="texai:org.texai.grammar.domainEntity.WordSenseConstruction", type="cyc:LinguisticObjectType", subClassOf="texai:CxgComposedConstruction", context="texai:EnglishConstructionGrammarDomainContext")
@NotThreadSafe // but effectively immutable
public class WordSenseConstruction extends SimpleConstruction {
/** the lexicon word sense */
@RDFProperty(predicate="texai:cxgTexaiEnglishWordSense")
private TexaiEnglishWordSense texaiEnglishWordSense;
/** the cached part of speech */
@RDFProperty(predicate="texai:cxgWordSenseSpeechPart")
private URI speechPart;
/** the cached mapped term or null if not present */
@RDFProperty(predicate="texai:cxgWordSenseMappedTerm")
private URI texaiMappedTerm;
/** Creates a new instance of WordSenseConstruction. */
public WordSenseConstruction() {
super();
setLoggerUsingClass(this.getClass());
}
/** Creates a new instance of WordSenseConstruction.
*
* @param name the construction name that identifies this instance
* @param naturalLanguage the natural language to which this construction applies
* @param texaiEnglishWordSense the lexicon word sense
*/
public WordSenseConstruction(
final String name,
final URI naturalLanguage,
final TexaiEnglishWordSense texaiEnglishWordSense) {
super(name, naturalLanguage);
//Preconditions
assert texaiEnglishWordSense != null : "texaiEnglishWordSense must not be null";
setLoggerUsingClass(this.getClass());
speechPart = texaiEnglishWordSense.getSpeechPart();
texaiMappedTerm = texaiEnglishWordSense.getTexaiMappedTerm();
}
/** Gets the lexicon word sense.
*
* @return the lexicon word sense
*/
public TexaiEnglishWordSense getTexaiEnglishWordSense() {
return texaiEnglishWordSense;
}
/** Gets the cached part of speech.
*
* @return the cached part of speech
*/
public URI getSpeechPart() {
return speechPart;
}
/** Gets the cached mapped term or null if not present.
*
* @return the cached mapped term or null if not present
*/
public URI getTexaiMappedTerm() {
return texaiMappedTerm;
}
/** 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 WordSenseConstruction) {
final WordSenseConstruction that = (WordSenseConstruction) obj;
return this.getId().equals(that.getId());
} else {
return false;
}
}
/** 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_SMALL);
stringBuilder.append("[");
final String className = this.getClass().getName();
final int index = className.lastIndexOf('.');
if (index == -1) {
stringBuilder.append(className);
} else {
stringBuilder.append(className.substring(index + 1));
}
stringBuilder.append(": ");
if (getName() != null) {
stringBuilder.append(getName());
}
if (getSpeechPart() != null) {
stringBuilder.append(" (");
stringBuilder.append(getSpeechPart());
stringBuilder.append(')');
}
if (getTexaiMappedTerm() != null) {
stringBuilder.append(" --> ");
stringBuilder.append(getTexaiMappedTerm());
}
stringBuilder.append("]");
return stringBuilder.toString();
}
}
See more files for this project here