/*
 * Word.java
 *
 * Created on October 13, 2002, 12:02 PM
 */

/**
 *
 * @author  becker
 * @version 1.0
 */

public class Word {

    public static final int UNKNOWN = -1;
    
    public static final int FIRST = 1;
    
    public static final int NOUN = 1;
    public static final int VERB = 2;
    public static final int ARTICLE = 3;
    public static final int PRONOUN = 4;
    public static final int PROPERNOUN = 5;
    public static final int ADJECTIVE = 6;
    public static final int ADVERB = 7;
    public static final int PREPOSITION = 8;
    public static final int CONJUNCTION = 9;
    
    public static final int LAST = 9;
    
    int wordType = UNKNOWN;
    String name = "";
    Word translation;
    
    /** Creates new Word - search for word in dictionary - give it a type s*/
    public Word(String w) 
        throws NotAWordException 
    {

    }
    /** Creates new Word - search for word in dictionary of given type */
    public Word(String w, int type) 
        throws NotAWordException
    {
        if ((type < FIRST) || (type > LAST))
            throw new NotAWordException("Bad Type: " + type);
        else {
            wordType = type;
            name = w;
        }
    }

    /** Creates new Word */
    public Word(String w, int type, String t) 
        throws NotAWordException
    {
        if ((type < FIRST) || (type > LAST))
            throw new NotAWordException("Bad Type: " + type + "\n");
        else {
            wordType = type;
            name = w;
            translation = new Word(t, type);
        }
    }

    
    public boolean isNoun() { return (wordType == NOUN)? true : false; }
    public boolean isVerb() { return (wordType == VERB)? true : false; }
    public boolean isArticle() { return (wordType == ARTICLE)? true : false; }
    public boolean isProNoun() { return (wordType == PRONOUN)? true : false; }
    public boolean isProperNoun() { return (wordType == PROPERNOUN)? true : false; }
    public boolean isAdjective() { return (wordType == ADJECTIVE)? true : false; }
    public boolean isAdverb() { return (wordType == ADVERB)? true : false; }
    public boolean isPreposition() { return (wordType == PREPOSITION)? true : false; }
    public boolean isConjunction() { return (wordType == CONJUNCTION)? true : false; }
    
    public String toString() { return name; }
    public Word Translation() { return translation; }
    public int Type() { return wordType; }
    
    /** find out what type we have */
    public static int checkType( String S ) {
        S = S.toLowerCase();
        if (S.equals("noun")) 
            return NOUN;
        else if (S.equals("pronoun") || S.equals("pro")) 
            return PRONOUN;
        else if (S.equals("propernoun") || S.equals("prop.")) 
            return PROPERNOUN;
        else if (S.equals("verb")) 
            return VERB;
        else if (S.equals("article") || S.equals("art.")) 
            return ARTICLE;
        else if (S.equals("adjective") || S.equals("adj.")) 
            return ADJECTIVE;
        else if (S.equals("adverb") || S.equals("adv."))
            return ADVERB;
        else if (S.equals("preposition") || S.equals("prep."))
            return PREPOSITION;
        else if (S.equals("conjunction") || S.equals("conj.")) 
            return CONJUNCTION;
        else
            return UNKNOWN;
    } // end checkType
    
    public void display() {
        System.out.print("Word: " + name + " -> " + wordType
                            + " -> " + translation + "\n");
    }

}
