public IWord toWord(ISynset synset) { return new Word(synset, num, lemma, lexID, marker, verbFrames, relatedWords); }
/** * Returns a string form of the lexical id as they are written in data * files, which is a single digit hex number. * * @param lexID * the lexical id to convert * @throws IllegalArgumentException * if the specified integer is not a valid lexical id. * @return a string form of the lexical id as they are written in data * files, which is a single digit hex number. * @since JWI 2.1.0 */ public static String getLexicalIDForDataFile(int lexID) { checkLexicalID(lexID); return Integer.toHexString(lexID); }
/** * Constructs a word id from the specified arguments. This constructor * produces a word with an unknown lemma. * * @param id * the synset id; may not be <code>null</code> * @param num * the word number * @throws NullPointerException * if the synset id is <code>null</code> * @throws IllegalArgumentException * if the lemma is empty or all whitespace * @since JWI 1.0 */ public WordID(ISynsetID id, int num) { if (id == null) throw new NullPointerException(); Word.checkWordNumber(num); this.id = id; this.num = num; this.lemma = unknownLemma; }
/** * Checks the specified word number, and throws an * {@link IllegalArgumentException} if it is not legal. * * @param num * the number to check * @throws IllegalArgumentException * if the specified lexical id is not in the closed range [0,15] * @since JWI 2.1.0 */ public static void checkWordNumber(int num) { if(isIllegalWordNumber(num)) throw new IllegalArgumentException("'" + num + " is an illegal word number: word numbers are in the closed range [1,255]"); }
/** * Checks the specified lexical id, and throws an * {@link IllegalArgumentException} if it is not legal. * * @param id * the id to check * @throws IllegalArgumentException * if the specified lexical id is not in the closed range [0,15] * @since JWI 2.1.0 */ public static void checkLexicalID(int id) { if(isIllegalLexicalID(id)) throw new IllegalArgumentException("'" + id + " is an illegal lexical id: lexical ids are in the closed range [0,15]"); }
@Override public String toString() { StringBuilder sb = new StringBuilder(16 + lemma.length()); sb.append(wordIDPrefix); sb.append(Synset.zeroFillOffset(id.getOffset())); sb.append('-'); sb.append(Character.toUpperCase(id.getPOS().getTag())); sb.append('-'); sb.append((num < 0) ? unknownWordNumber : Word.zeroFillWordNumber(num)); sb.append('-'); sb.append(lemma); return sb.toString(); }
sb.append(LexFile.getLexicalFileNumberString(key.getLexicalFile().getNumber())); sb.append(':'); sb.append(Word.getLexicalIDForSenseKey(key.getLexicalID())); sb.append(':'); if(key.isAdjectiveSatellite()){ sb.append("??"); } else { sb.append(Word.getLexicalIDForSenseKey(key.getHeadID()));
/** * Returns a string form of the lexical id as they are written in sense * keys, which is as a two-digit decimal number. * * @param lexID * the lexical id to convert * @return a string form of the lexical id as they are written in sense * keys, which is as a two-digit decimal number. * @throws IllegalArgumentException * if the specified integer is not a valid lexical id. * @since JWI 2.1.0 */ public static String getLexicalIDForSenseKey(int lexID) { checkLexicalID(lexID); return (lexID < 10) ? lexIDNumStrs[lexID] : Integer.toString(lexID); }
/** * Constructs a fully specified word id * * @param id * the synset id; may not be <code>null</code> * @param num * the word number * @param lemma * the lemma; may not be <code>null</code>, empty, or all * whitespace * @throws NullPointerException * if the synset id is <code>null</code> * @throws IllegalArgumentException * if the lemma is empty or all whitespace, or the word number * is not legal * @since JWI 1.0 */ public WordID(ISynsetID id, int num, String lemma){ if(id == null) throw new NullPointerException(); if(lemma.trim().length() == 0) throw new IllegalArgumentException(); Word.checkWordNumber(num); this.id = id; this.num = num; this.lemma = lemma; }
IWord word = new Word(newSynset, old.getID(), old.getLexicalID(), old.getAdjectiveMarker(), old.getVerbFrames(), newPtrs); ISenseKey key = word.getSenseKey(); if(key.needsHeadSet()){
public void setHead(String headLemma, int headLexID) { if(!needsHeadSet()) throw new IllegalStateException(); Word.checkLexicalID(headLexID); if(headLemma.trim().length() == 0) throw new IllegalArgumentException(); this.headLemma = headLemma; this.headLexID = headLexID; this.isHeadSet = true; }
/** * 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. * * @param num * the number to be converted * @return a two hex digit zero-filled string representing the specified * number * @throws IllegalArgumentException * if the specified number is not a legal word number * @since JWI 2.1.0 */ public static String zeroFillWordNumber(int num){ checkWordNumber(num); StringBuilder sb = new StringBuilder(2); String str = Integer.toHexString(num); int numZeros = 2-str.length(); for(int i = 0; i < numZeros; i++) sb.append('0'); for(int i = 0; i < str.length(); i++) sb.append(Character.toUpperCase(str.charAt(i))); return sb.toString(); }
if(id == null) throw new NullPointerException(); checkLexicalID(lexID); if(synset.getPOS() != POS.ADJECTIVE && adjMarker != null) throw new IllegalArgumentException();