public static void main(String[] args) { WordLemmaTag wLT = new WordLemmaTag(); wLT.setFromString("hunter/NN"); System.out.println(wLT.word()); System.out.println(wLT.lemma()); System.out.println(wLT.tag()); WordLemmaTag wLT2 = new WordLemmaTag(); wLT2.setFromString("bought/buy/V"); System.out.println(wLT2.word()); System.out.println(wLT2.lemma()); System.out.println(wLT2.tag()); WordLemmaTag wLT3 = new WordLemmaTag(); wLT2.setFromString("life"); System.out.println(wLT3.word()); System.out.println(wLT3.lemma()); System.out.println(wLT3.tag()); }
public void setFromString(String labelStr, String divider) { int first = labelStr.indexOf(divider); int second = labelStr.lastIndexOf(divider); if (first == second) { setWord(labelStr.substring(0, first)); setTag(labelStr.substring(first + 1)); setLemma(Morphology.lemmaStatic(labelStr.substring(0, first), labelStr.substring(first + 1))); } else if (first >= 0) { setWord(labelStr.substring(0, first)); setLemma(labelStr.substring(first + 1, second)); setTag(labelStr.substring(second + 1)); } else { setWord(labelStr); setLemma(null); setTag(null); } }
@Override public void setWord(String word) { setValue(word); }
/** * Equality is satisfied only if the compared object is a WordLemmaTag * and has String-equal word, lemma and tag fields. */ @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof WordLemmaTag)) return false; final WordLemmaTag other = (WordLemmaTag) o; return word().equals(other.word()) && lemma().equals(other.lemma()) && tag().equals(other.tag()); }
/** * Make a new label with this {@code String} as the value (word). * Any other fields of the label would normally be null. * * @param labelStr The String that will be used for value * @return The new WordLemmaTag (lemma and tag will be {@code null}) */ @Override public Label newLabel(String labelStr) { return new WordLemmaTag(labelStr); }
public WordLemmaTag(String word) { this.word = word; this.lemma = null; setTag(null); }
/** * Return a String representation of the Label. For a multipart Label, * this will return all parts. * * @return a text representation of the full label contents: word/lemma/tag */ @Override public String toString() { return toString(DIVIDER); }
public String toString(String divider) { return word() + divider + lemma + divider + tag; }
/** * The String is divided according to the divider character (usually, "/"). * We assume that we can always just divide on the rightmost divider character, * rather than trying to parse up escape sequences. If the divider character isn't found * in the word, then the whole string becomes the word, and lemma and tag * are {@code null}. * We assume that if only one divider character is found, word and tag are present in * the String, and lemma will be computed. * * @param labelStr The word that will go into the {@code WordLemmaTag} */ @Override public void setFromString(String labelStr) { setFromString(labelStr, DIVIDER); }
/** * Orders first by word, then by lemma, then by tag. * * @param wordLemmaTag object to compare to * @return result (positive if {@code this} is greater than * {@code obj}, 0 if equal, negative otherwise) */ @Override public int compareTo(WordLemmaTag wordLemmaTag) { int first = word().compareTo(wordLemmaTag.word()); if (first != 0) return first; int second = lemma().compareTo(wordLemmaTag.lemma()); if (second != 0) return second; else return tag().compareTo(wordLemmaTag.tag()); }
/** * Create a new {@code WordLemmaTag Label}, where the label is * formed from the {@code Label} object passed in. Depending on what fields * each label has, other things will be {@code null}. * * @param oldLabel The Label that the new label is being created from * @return a new label of a particular type */ @Override public Label newLabel(Label oldLabel) { return new WordLemmaTag(oldLabel); }
/** * Create a new {@code WordLemmaTag}. * * @param word This word is passed to the supertype constructor * @param lemma The lemma is set as the lemma of this Label * @param tag The {@code value()} of this Label is set as the * tag of this Label */ public WordLemmaTag(String word, String lemma, String tag) { this(word); this.lemma = lemma; setTag(tag); }
return ((LabeledWord) o).toString(separator); } else if (separator != null && o instanceof WordLemmaTag) { return ((WordLemmaTag) o).toString(separator); } else if (separator != null && o instanceof WordTag) { return ((WordTag) o).toString(separator);
public String toString(String divider) { return word() + divider + lemma + divider + tag; }
/** * The String is divided according to the divider character (usually, "/"). * We assume that we can always just divide on the rightmost divider character, * rather than trying to parse up escape sequences. If the divider character isn't found * in the word, then the whole string becomes the word, and lemma and tag * are <code>null</code>. * We assume that if only one divider character is found, word and tag are present in * the String, and lemma will be computed. * * @param labelStr The word that will go into the <code>WordLemmaTag</code> */ public void setFromString(String labelStr) { setFromString(labelStr, DIVIDER); }
public static void main(String[] args) { WordLemmaTag wLT = new WordLemmaTag(); wLT.setFromString("hunter/NN"); System.out.println(wLT.word()); System.out.println(wLT.lemma()); System.out.println(wLT.tag()); WordLemmaTag wLT2 = new WordLemmaTag(); wLT2.setFromString("bought/buy/V"); System.out.println(wLT2.word()); System.out.println(wLT2.lemma()); System.out.println(wLT2.tag()); WordLemmaTag wLT3 = new WordLemmaTag(); wLT2.setFromString("life"); System.out.println(wLT3.word()); System.out.println(wLT3.lemma()); System.out.println(wLT3.tag()); }
/** * Equality is satisfied only if the compared object is a WordLemmaTag * and has String-equal word, lemma and tag fields. */ @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof WordLemmaTag)) return false; final WordLemmaTag other = (WordLemmaTag) o; return word().equals(other.word()) && lemma().equals(other.lemma()) && tag().equals(other.tag()); }
/** * Make a new label with this {@code String} as a value component. * Any other fields of the label would normally be null. * * @param labelStr The String that will be used for value * @param options what to make (use labelStr as word, lemma or tag) * @return The new WordLemmaTag (word or lemma or tag will be {@code null}) */ @Override public Label newLabel(String labelStr, int options) { if (options == TAG_LABEL) { return new WordLemmaTag(null, null, labelStr); } else if (options == LEMMA_LABEL) { return new WordLemmaTag(null, labelStr, null); } else { return new WordLemmaTag(labelStr); } }
public void setFromString(String labelStr, String divider) { int first = labelStr.indexOf(divider); int second = labelStr.lastIndexOf(divider); if (first == second) { setWord(labelStr.substring(0, first)); setTag(labelStr.substring(first + 1)); setLemma(Morphology.lemmaStatic(labelStr.substring(0, first), labelStr.substring(first + 1))); } else if (first >= 0) { setWord(labelStr.substring(0, first)); setLemma(labelStr.substring(first + 1, second)); setTag(labelStr.substring(second + 1)); } else { setWord(labelStr); setLemma(null); setTag(null); } }
/** * Create a new {@code WordLemmaTag}. * * @param word This word is set as the word of this Label * @param tag The {@code value()} of this Label is set as the * tag of this Label */ public WordLemmaTag(String word, String tag) { WordTag wT = new WordTag(word, tag); this.word = word; this.lemma = Morphology.stemStatic(wT).word(); setTag(tag); }