public static void init() { getDictionary(); }
private static Synset getSynset(final String id) { final POS pos = POS.getPOSForKey(getPOS(id)); final long offset = getOffset(id); try { synchronized (WordNet.class) { return getDictionary().getSynsetAt(pos, offset); } } catch (final JWNLException ex) { throw new Error(ex); } }
final IndexWord word; synchronized (WordNet.class) { word = getDictionary().getIndexWord(pos, lemma);
public static List<String> getSynsetsForLemma(String lemma, String pos) { try { synchronized (WordNet.class) { IndexWord indexWord = getDictionary().lookupIndexWord(POS.getPOSForKey(pos), lemma); if (indexWord == null) { return new ArrayList<>(); } Synset[] synsets = indexWord.getSenses(); ArrayList<String> ret = new ArrayList<>(); for (int i = 0; i < synsets.length; i++) { Synset synset = synsets[i]; ret.add(getSynsetID(synset.getOffset(), synset.getPOS().getKey())); } return ret; } } catch (final JWNLException ex) { throw new Error(ex); } }
@Nullable public static String getReadableSynsetID(@Nullable final String synsetID) { if (synsetID == null) { return null; } final Synset synset = getSynset(synsetID); if (synset == null) { throw new IllegalArgumentException("Illegal synset ID " + synsetID); } final String lemma = synset.getWords()[0].getLemma(); final POS pos = POS.getPOSForKey(getPOS(synsetID)); try { final IndexWord word; synchronized (WordNet.class) { word = getDictionary().lookupIndexWord(pos, lemma); } final Synset[] senses = word.getSenses(); for (int i = 0; i < senses.length; ++i) { if (senses[i].equals(synset)) { return lemma + "-" + (i + 1) + pos.getKey(); } } throw new Error("Could not determine sense index for lemma " + lemma + " and synset " + synsetID); } catch (final JWNLException ex) { throw new Error(ex); } // return synset.getSenseKey(lemma); // TODO }