private void demonstrateListOperation(IndexWord word) throws JWNLException { // Get all of the hypernyms (parents) of the first sense of <var>word</var> PointerTargetNodeList hypernyms = PointerUtils.getInstance().getDirectHypernyms(word.getSense(1)); System.out.println("Direct hypernyms of \"" + word.getLemma() + "\":"); hypernyms.print(); }
private void demonstrateTreeOperation(IndexWord word) throws JWNLException { // Get all the hyponyms (children) of the first sense of <var>word</var> PointerTargetTree hyponyms = PointerUtils.getInstance().getHyponymTree(word.getSense(1)); System.out.println("Hyponyms of \"" + word.getLemma() + "\":"); hyponyms.print(); }
/** Get the words that mean the opposite of <code>synset</code> and the immediate synonyms of those words */ public PointerTargetTree getExtendedAntonyms(Synset synset) throws JWNLException { return getExtendedAntonyms(synset, 1); }
public Set<Synset> getCoordinateTerms() throws WordNetException { try { return getSetOfSynsets(PointerUtils.getInstance().getCoordinateTerms(this.realSynset)); } catch (JWNLException e) { throw new WordNetException("See nested", e); } }
public Set<Synset> getHolonyms() throws WordNetException { try { return getSetOfSynsets(PointerUtils.getInstance().getHolonyms(this.realSynset)); } catch (JWNLException e) { throw new WordNetException("See nested", e); } }
public Set<Synset> getMeronyms() throws WordNetException { try { return getSetOfSynsets(PointerUtils.getInstance().getMeronyms(this.realSynset)); } catch (JWNLException e) { throw new WordNetException("See nested", e); } }
switch(relation){ case hype: nodeList = pUtils.getDirectHypernyms(sense); break; case hypo: nodeList = pUtils.getDirectHyponyms(sense); break; case derv: nodeList = pUtils.getDerived(sense); break; case vgrp: nodeList = pUtils.getVerbGroup(sense); break; case cause: nodeList = pUtils.getCauses(sense); break; case entl: nodeList = pUtils.getEntailments(sense); break; case entlby: nodeList = pUtils.getEntailedBy(sense); break; case antm: nodeList = pUtils.getAntonyms(sense); break; case syn2: nodeList = pUtils.getSynonyms(sense); break; case alsoc:
result.add(w.getLemma()); PointerTargetNodeList target = PointerUtils.getInstance().getDirectHypernyms(sense); while (target != null && !target.isEmpty()) { for (Object aTarget : target) { target = PointerUtils.getInstance().getDirectHyponyms(((PointerTargetNode) target.get(0)).getSynset()); System.out.println(target);
/** * Finds the asymmetric relationship(s) between two words. A relationship is * asymmetric if its type is asymmetric (i.e. it's not its own inverse). */ private RelationshipList findAsymmetricRelationships( Synset sourceSynset, Synset targetSynset, PointerType type, int depth) throws JWNLException { // We run the reversal function on the trees to get linear (non-branching) // paths from the source word to its deepest ancestor (i.e. if there are // multiple relations from a single word anywhere in the path, the reversal // function will break them down into multiple, linear paths). PointerTargetNodeList[] sourceRelations = new PointerTargetTree( sourceSynset, PointerUtils.getInstance().makePointerTargetTreeList(sourceSynset, type, depth)).reverse(); PointerTargetNodeList[] targetRelations = new PointerTargetTree( targetSynset, PointerUtils.getInstance().makePointerTargetTreeList(targetSynset, type, depth)).reverse(); RelationshipList relationships = new RelationshipList(); // Do an exhaustive search for relationships for (int i = 0; i < sourceRelations.length; i++) { for (int j = 0; j < targetRelations.length; j++) { Relationship relationship = findAsymmetricRelationship( sourceRelations[i], targetRelations[j], type, sourceSynset, targetSynset); if (relationship != null) { relationships.add(relationship); } } } return relationships; }
public void getHyponymsRecursive(List<String> lemmas, Synset sense, int depthToGo) { for (Word w : sense.getWords()) { lemmas.add(w.getLemma()); } if (depthToGo == 0) { return; } try { PointerTargetNodeList directHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); for (Object directHyponym : directHyponyms) { getHyponymsRecursive(lemmas, ((PointerTargetNode) directHyponym).getSynset(), depthToGo - 1); } } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
/** Get <code>synset</code>'s siblings (the hyponyms of its hypernyms) */ public PointerTargetNodeList getCoordinateTerms(Synset synset) throws JWNLException { PointerTargetNodeList list = new PointerTargetNodeList(); for (Iterator itr = getDirectHypernyms(synset).iterator(); itr.hasNext();) { list.addAll(getPointerTargets(((PointerTargetNode) itr.next()).getSynset(), PointerType.HYPONYM)); } return list; }
private WordNetAPI(InputStream propsFile) throws Exception { info("Initialize WordNet...: "); if (propsFile == null) throw new RuntimeException("Missing required property 'WN_PROP'"); try { JWNL.initialize(propsFile); wDict = Dictionary.getInstance(); pUtils = PointerUtils.getInstance(); morphProcessor = wDict.getMorphologicalProcessor(); } catch (Exception e) { throw new RuntimeException("Initialization failed", e); } info("Done initializing WordNet..."); }
/** Get all of the children of <code>synset</code> */ public PointerTargetTree getHyponymTree(Synset synset) throws JWNLException { return getHyponymTree(synset, INFINITY); }
/** Find all antonyms of <code>synset</code>, and all synonyms of those antonyms to depth <code>depth</code>. */ public PointerTargetTree getExtendedAntonyms(Synset synset, int depth) throws JWNLException { PointerTargetTreeNodeList list = new PointerTargetTreeNodeList(); if (synset.getPOS() == POS.ADJECTIVE) { PointerTargetNodeList antonyms = getAntonyms(synset); list = makePointerTargetTreeList(antonyms, PointerType.SIMILAR_TO, PointerType.ANTONYM, depth, false); } return new PointerTargetTree(new PointerTargetTreeNode(synset, list, null)); }
/** Get the immediate antonyms of all words that mean the same as <code>synset</code>. */ public PointerTargetTree getIndirectAntonyms(Synset synset) throws JWNLException { return getIndirectAntonyms(synset, 1); }
PointerTargetNodeList relatedListHyponyms = null; try { relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense);
/** A symmetric relationship is one whose type is symmetric (i.e. is it's own inverse). */ private RelationshipList findSymmetricRelationships( final Synset sourceSynset, final Synset targetSynset, PointerType type, int depth) throws JWNLException { PointerTargetTree tree = new PointerTargetTree( sourceSynset, PointerUtils.getInstance().makePointerTargetTreeList(sourceSynset, type, null, depth, false)); PointerTargetTreeNodeList.Operation opr = new PointerTargetTreeNodeList.Operation() { public Object execute(PointerTargetTreeNode testNode) { if (targetSynset.equals(testNode.getPointerTarget())) { return testNode; } return null; } }; List l = tree.getAllMatches(opr); RelationshipList list = new RelationshipList(); for (int i = 0; i < l.size(); i++) { PointerTargetNodeList nodes = findSymmetricRelationship((PointerTargetTreeNode)l.get(i), type); list.add(new SymmetricRelationship(type, nodes, sourceSynset, targetSynset)); } return list; }
public void getHyponymsScoredRecursive(List<LemmaScorePair> lemmas, Synset sense, int depthToGo, double score) { for (Word w : sense.getWords()) { lemmas.add(new LemmaScorePair(w.getLemma(), score)); } if (depthToGo == 0) { return; } try { PointerTargetNodeList directHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); for (Object directHyponym : directHyponyms) { getHyponymsScoredRecursive(lemmas, ((PointerTargetNode) directHyponym).getSynset(), depthToGo - 1, score * HYPONYM_FACTOR); } } catch (JWNLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
private void demonstrateListOperation(IndexWord word) throws JWNLException { // Get all of the hypernyms (parents) of the first sense of <var>word</var> PointerTargetNodeList hypernyms = PointerUtils.getInstance().getDirectHypernyms(word.getSense(1)); System.out.println("Direct hypernyms of \"" + word.getLemma() + "\":"); hypernyms.print(); }
private void demonstrateTreeOperation(IndexWord word) throws JWNLException { // Get all the hyponyms (children) of the first sense of <var>word</var> PointerTargetTree hyponyms = PointerUtils.getInstance().getHyponymTree(word.getSense(1)); System.out.println("Hyponyms of \"" + word.getLemma() + "\":"); hyponyms.print(); }