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); } }
public static Set<String> getHypernyms(final String synsetID) { return getGenericSet(synsetID, PointerType.HYPERNYM); }
final String sst = WordNet.mapSynsetToSST(synsetRef.getReference()); if (sstRef == null || !Objects.equal(sstRef.getReference(), sst)) { LOGGER.debug((sstRef == null ? "Added" : "Overridden") + " SST '" + sst final String bbn = WordNet.mapSynsetToBBN(synsetRef.getReference()); if (bbn != null) { bbnRef = document.newExternalRef(NAFUtils.RESOURCE_BBN, bbn); final String synsetID = WordNet.mapBBNToSynset(bbnRef.getReference()); if (synsetID != null) { synsetRef = document.newExternalRef(NAFUtils.RESOURCE_WN_SYNSET, synsetID); final String sst = WordNet.mapBBNToSST(bbnRef.getReference()); if (sst != null) { sstRef = document.newExternalRef(NAFUtils.RESOURCE_WN_SST, sst); synsetIDs = Sets.newHashSet(); for (final String oldSynsetID : oldSynsetIDs) { synsetIDs.addAll(WordNet.getHypernyms(oldSynsetID)); synsetIDs = WordNet.getHyponyms(synsetRef.getReference()); conceptURIs = Sumo.synsetsToConcepts(synsetIDs);
@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 }
@Nullable public static String mapSynsetToBBN(@Nullable final String synsetID) { final List<String> ids = Lists.newLinkedList(); ids.add(synsetID); while (!ids.isEmpty()) { final String id = ids.remove(0); final List<String> bbns = SYNSET_TO_BBN.get(id); if (bbns != null && !bbns.isEmpty()) { return bbns.get(0); // return only first BBN in case of ambiguity } try { final Synset source = getSynset(id); final List<String> hypernymIDs = Lists.newArrayList(); for (final PointerType type : new PointerType[] { PointerType.HYPERNYM, PointerType.INSTANCE_HYPERNYM }) { for (final Pointer pointer : source.getPointers(type)) { final Synset target = pointer.getTargetSynset(); hypernymIDs.add(getSynsetID(target.getOffset(), target.getPOS().getKey())); } } Collections.sort(hypernymIDs); // necessary in order to get deterministic results ids.addAll(hypernymIDs); } catch (final JWNLException ex) { throw new Error("Unexpected exception (!)", ex); } } return null; }
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 mapSynsetToSST(@Nullable final String synsetID) { if (synsetID != null) { final String sst = SYNSET_TO_SST.get(synsetID); if (sst != null) { return sst; } return "B-" + getSynset(synsetID).getLexFileName(); } return null; }
final String readableHeadSynsetID = WordNet.getReadableSynsetID(headSynsetID); final String headID = MoreObjects.firstNonNull(readableHeadSynsetID, // head.getLemma().toLowerCase());
public static void init() { getDictionary(); }
public static Set<URI> getDBpediaYagoURIs(@Nullable final Iterable<String> synsetIDs) { final Set<URI> uris = Sets.newHashSet(); final Set<String> hypernyms = Sets.newHashSet(); final List<String> queue = Lists.newLinkedList(); if (synsetIDs != null) { Iterables.addAll(queue, synsetIDs); } while (!queue.isEmpty()) { final String synsetID = queue.remove(0); final URI uri = getDBpediaYagoURI(synsetID); if (uri != null) { uris.add(uri); } else { for (final String hypernym : WordNet.getHypernyms(synsetID)) { if (hypernyms.add(hypernym)) { queue.add(hypernym); } } } } return uris; }
public static Set<String> getGenericSet(final String synsetID, final PointerType... pointerTypes) { final Set<String> ret = Sets.newHashSet(); final Synset synset = getSynset(synsetID); if (synset != null) { for (final PointerType pointerType : pointerTypes) { for (final Pointer pointer : synset.getPointers(pointerType)) { try { final Synset target = pointer.getTargetSynset(); ret.add(getSynsetID(target.getOffset(), target.getPOS().getKey())); } catch (final Throwable ex) { throw new RuntimeException(ex); } } } } return ret; }
final IndexWord word; synchronized (WordNet.class) { word = getDictionary().getIndexWord(pos, lemma); return getSynsetID(synset.getOffset(), pos.getKey()); } catch (final JWNLException ex) { throw new Error(ex);
public static Set<String> getLemmas(final String synsetID) { final Set<String> lemmas = Sets.newLinkedHashSet(); final Synset synset = getSynset(synsetID); if (synset != null) { for (final Word word : synset.getWords()) { lemmas.add(word.getLemma()); } } return lemmas; }
return; final String synsetID = WordNet.getReadableSynsetID(synsetRef.getReference()); final URI synsetURI = this.vf.createURI("http://wordnet-rdf.princeton.edu/wn30/", synsetRef.getReference()); modIDs.add(WordNet.getReadableSynsetID(modifierRef.getReference())); modURIs.add(this.vf.createURI("http://wordnet-rdf.princeton.edu/wn30/", synsetRef.getReference()));
public static Set<String> getHypernyms(final String synsetID, final boolean recursive) { return getGenericSet(synsetID, recursive, PointerType.HYPERNYM, PointerType.INSTANCE_HYPERNYM); }
public static Set<String> getHyponims(final String synsetID, final boolean recursive) { return getGenericSet(synsetID, recursive, PointerType.HYPONYM, PointerType.INSTANCES_HYPONYM); }
public static Set<String> getHyponyms(final String synsetID) { return getGenericSet(synsetID, PointerType.HYPONYM); }
public static Set<String> getGenericSet(final String synsetID, final boolean recursive, final PointerType... pointerTypes) { if (!recursive) { return getGenericSet(synsetID, pointerTypes); } final Set<String> result = Sets.newHashSet(); final List<String> queue = Lists.newArrayList(synsetID); while (!queue.isEmpty()) { final String id = queue.remove(0); if (result.add(id)) { queue.addAll(getGenericSet(id, pointerTypes)); } } return result; }