edu.mit.jwi.item
Class Word

java.lang.Object
  extended by edu.mit.jwi.item.Word
All Implemented Interfaces:
IHasPOS, IItem<IWordID>, IWord, java.io.Serializable

public class Word
extends java.lang.Object
implements IWord

Default implementation of the IWord interface.

Since:
JWI 1.0
Version:
2.4.0
Author:
Mark A. Finlayson
See Also:
Serialized Form

Constructor Summary
Word(ISynset synset, int number, java.lang.String lemma, int lexID, AdjMarker adjMarker, java.util.List<IVerbFrame> frames, java.util.Map<IPointer,? extends java.util.List<IWordID>> pointers)
          Constructs a new word object.
Word(ISynset synset, IWordID id, int lexID, AdjMarker adjMarker, java.util.List<IVerbFrame> frames, java.util.Map<IPointer,? extends java.util.List<IWordID>> pointers)
          Constructs a new word object.
 
Method Summary
static void checkLexicalID(int id)
          Checks the specified lexical id, and throws an IllegalArgumentException if it is not legal.
static void checkWordNumber(int num)
          Checks the specified word number, and throws an IllegalArgumentException if it is not legal.
 boolean equals(java.lang.Object obj)
           
 AdjMarker getAdjectiveMarker()
          Returns the adjective marker of this word.
 IWordID getID()
          Returns the ID object for this item.
 java.lang.String getLemma()
          Returns the root form of this word, never null or empty.
 int getLexicalID()
          A integer in the closed range [0,15] that, when appended onto lemma, uniquely identifies a sense within a lexicographer file.
static java.lang.String getLexicalIDForDataFile(int lexID)
          Returns a string form of the lexical id as they are written in data files, which is a single digit hex number.
static java.lang.String getLexicalIDForSenseKey(int lexID)
          Returns a string form of the lexical id as they are written in sense keys, which is as a two-digit decimal number.
 POS getPOS()
          Returns the associated part of speech for this object.
 java.util.Map<IPointer,java.util.List<IWordID>> getRelatedMap()
          Returns an immutable map of from pointers to immutable maps.
 java.util.List<IWordID> getRelatedWords()
          Returns an immutable list of all word ids related to this word by pointers in the database.
 java.util.List<IWordID> getRelatedWords(IPointer type)
          Returns an immutable list of all word ids related to this word by the specified pointer type.
 ISenseKey getSenseKey()
          Returns the sense key for this word.
 ISynset getSynset()
          Returns the synset uniquely identified by this word.
 java.util.List<IVerbFrame> getVerbFrames()
          Returns an immutable list of all verb frames associated with this word.
 int hashCode()
           
static boolean isIllegalLexicalID(int id)
          Lexical id's are always an integer in the closed range [0,15].
static boolean isIllegalWordNumber(int num)
          Word numbers are always an integer in the closed range [1,255].
 java.lang.String toString()
           
static java.lang.String zeroFillWordNumber(int num)
          Returns a string representation of the specified integer as a two hex digit zero-filled string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Word

public Word(ISynset synset,
            int number,
            java.lang.String lemma,
            int lexID,
            AdjMarker adjMarker,
            java.util.List<IVerbFrame> frames,
            java.util.Map<IPointer,? extends java.util.List<IWordID>> pointers)
Constructs a new word object.

Parameters:
synset - the synset for the word; may not be null
number - the word number
lemma - the word lemma; may not be empty or all whitespace
lexID - the lexical id
adjMarker - non-null only if this is an adjective
frames - verb frames if this is a verb
pointers - lexical pointers
Throws:
java.lang.NullPointerException - if the synset is null
java.lang.IllegalArgumentException - if the adjective marker is non-null and this is not an adjective
Since:
JWI 1.0

Word

public Word(ISynset synset,
            IWordID id,
            int lexID,
            AdjMarker adjMarker,
            java.util.List<IVerbFrame> frames,
            java.util.Map<IPointer,? extends java.util.List<IWordID>> pointers)
Constructs a new word object.

Parameters:
synset - the synset for the word; may not be null the word lemma; may not be empty or all whitespace
id - the word id; may not be null
lexID - the lexical id
adjMarker - non-null only if this is an adjective
frames - verb frames if this is a verb
pointers - lexical pointers
Throws:
java.lang.NullPointerException - if the synset or word ID is null
java.lang.IllegalArgumentException - if the adjective marker is non-null and this is not an adjective
Since:
JWI 1.0
Method Detail

getID

public IWordID getID()
Description copied from interface: IItem
Returns the ID object for this item. Will not return null.

Specified by:
getID in interface IItem<IWordID>
Returns:
the non-null ID for this item

getLemma

public java.lang.String getLemma()
Description copied from interface: IWord
Returns the root form of this word, never null or empty.

Specified by:
getLemma in interface IWord
Returns:
the non-null, non-empty root form of this word

getPOS

public POS getPOS()
Description copied from interface: IHasPOS
Returns the associated part of speech for this object. If this object is not associated with any particular part of speech, this method may return null.

Specified by:
getPOS in interface IHasPOS
Returns:
The associated part of speech, or null if none.

getSynset

public ISynset getSynset()
Description copied from interface: IWord
Returns the synset uniquely identified by this word. The returned synset will never be null.

Specified by:
getSynset in interface IWord
Returns:
the non-null synset identified by this word.

getLexicalID

public int getLexicalID()
Description copied from interface: IWord
A integer in the closed range [0,15] that, when appended onto lemma, uniquely identifies a sense within a lexicographer file. Lexical id numbers usually start with 0, and are incremented as additional senses of the word are added to the same file, although there is no requirement that the numbers be consecutive or begin with 0. Note that a value of 0 is the default, and therefore is not present in lexicographer files. In the wordnet data files the lexical id is represented as a one digit hexadecimal integer.

Specified by:
getLexicalID in interface IWord
Returns:
the lexical id of the word, an integer between 0 and 15, inclusive

getAdjectiveMarker

public AdjMarker getAdjectiveMarker()
Description copied from interface: IWord
Returns the adjective marker of this word. If this word has no adjective marker, returns null

Specified by:
getAdjectiveMarker in interface IWord
Returns:
the adjective marker for this word, or null if none.

getSenseKey

public ISenseKey getSenseKey()
Description copied from interface: IWord
Returns the sense key for this word. Will never return null; however, the sense key that is returned may not yet have it's head lemma and head lexical id set yet, and so may throw an exception on some calls.

Specified by:
getSenseKey in interface IWord
Returns:
the sense key for this word, never null
See Also:
ISenseKey.needsHeadSet(), ISenseKey.setHead(String, int)

getRelatedMap

public java.util.Map<IPointer,java.util.List<IWordID>> getRelatedMap()
Description copied from interface: IWord
Returns an immutable map of from pointers to immutable maps. Note that this only returns IWords related by lexical pointers (i.e., not semantic pointers). To retrieve items related by semantic pointers, call ISynset.getRelatedMap() on the appropriate object.

Specified by:
getRelatedMap in interface IWord
Returns:
an immutable map from lexical pointers to words

getRelatedWords

public java.util.List<IWordID> getRelatedWords(IPointer type)
Description copied from interface: IWord
Returns an immutable list of all word ids related to this word by the specified pointer type. Note that this only returns words related by lexical pointers (i.e., not semantic pointers). To retrieve items related by semantic pointers, call ISynset.getRelatedSynsets(). If this word has no targets for the for the specified pointer, this method returns an empty list. This method never returns null.

Specified by:
getRelatedWords in interface IWord
Parameters:
type - the pointer for which related words are requested
Returns:
the list of words related by the specified pointer, or an empty list if none.

getRelatedWords

public java.util.List<IWordID> getRelatedWords()
Description copied from interface: IWord
Returns an immutable list of all word ids related to this word by pointers in the database. Note this only returns words related to this word by lexical pointers, i.e., not semantic pointers. To retrieve synsets related to the synset for this word by semantic pointers, call ISynset.getRelatedSynsets() on the ISynset for this word.

Specified by:
getRelatedWords in interface IWord
Returns:
an immutable list of all lexically-related words

getVerbFrames

public java.util.List<IVerbFrame> getVerbFrames()
Description copied from interface: IWord
Returns an immutable list of all verb frames associated with this word. If there are no such frames, returns the empty list.

Specified by:
getVerbFrames in interface IWord
Returns:
an immutable list of all the verb frames associated with this word, or the empty list if none.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

checkWordNumber

public static void checkWordNumber(int num)
Checks the specified word number, and throws an IllegalArgumentException if it is not legal.

Parameters:
num - the number to check
Throws:
java.lang.IllegalArgumentException - if the specified lexical id is not in the closed range [0,15]
Since:
JWI 2.1.0

checkLexicalID

public static void checkLexicalID(int id)
Checks the specified lexical id, and throws an IllegalArgumentException if it is not legal.

Parameters:
id - the id to check
Throws:
java.lang.IllegalArgumentException - if the specified lexical id is not in the closed range [0,15]
Since:
JWI 2.1.0

isIllegalLexicalID

public static boolean isIllegalLexicalID(int id)
Lexical id's are always an integer in the closed range [0,15]. In the wordnet data files, lexical ids are represented as a one digit hexidecimal integer.

Parameters:
id - the lexical id to check
Returns:
true if the specified integer is an invalid lexical id; false otherwise.
Since:
JWI 2.1.0

isIllegalWordNumber

public static boolean isIllegalWordNumber(int num)
Word numbers are always an integer in the closed range [1,255]. In the wordnet data files, the word number is determined by the order of the word listing.

Parameters:
num - the number to check
Returns:
true if the specified integer is an invalid lexical id; false otherwise.
Since:
JWI 2.1.0

getLexicalIDForDataFile

public static java.lang.String getLexicalIDForDataFile(int lexID)
Returns a string form of the lexical id as they are written in data files, which is a single digit hex number.

Parameters:
lexID - the lexical id to convert
Returns:
a string form of the lexical id as they are written in data files, which is a single digit hex number.
Throws:
java.lang.IllegalArgumentException - if the specified integer is not a valid lexical id.
Since:
JWI 2.1.0

getLexicalIDForSenseKey

public static java.lang.String getLexicalIDForSenseKey(int lexID)
Returns a string form of the lexical id as they are written in sense keys, which is as a two-digit decimal number.

Parameters:
lexID - the lexical id to convert
Returns:
a string form of the lexical id as they are written in sense keys, which is as a two-digit decimal number.
Throws:
java.lang.IllegalArgumentException - if the specified integer is not a valid lexical id.
Since:
JWI 2.1.0

zeroFillWordNumber

public static java.lang.String zeroFillWordNumber(int num)
Returns a string representation of the specified integer as a two hex digit zero-filled string. E.g., "1" becomes "01", "10" becomes "0A", and so on. This is used for the generation of Word ID numbers.

Parameters:
num - the number to be converted
Returns:
a two hex digit zero-filled string representing the specified number
Throws:
java.lang.IllegalArgumentException - if the specified number is not a legal word number
Since:
JWI 2.1.0


Copyright © 2007-2013 Massachusetts Institute of Technology. All Rights Reserved.