/** * Make a nested list of pointer targets to the default depth, starting at <code>synset</code>. Each * level of the list is related to the previous level by one of the pointer types specified by * <var>searchTypes</var>. */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset set, PointerType[] searchTypes) throws JWNLException { return makePointerTargetTreeList(set, searchTypes, INFINITY); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at <code>synset</code>. Each * level of the list is related to the previous level by one of the pointer types specified by * <var>searchTypes</var>. * @param labelType the type used to label each pointer target in the tree * @param allowRedundancies if true, duplicate items will be included in the tree */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset synset, PointerType[] searchTypes, PointerType labelType, int depth, boolean allowRedundancies) throws JWNLException { return makePointerTargetTreeList(synset, searchTypes, labelType, depth, allowRedundancies, null); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at <code>synset</code>. Each * level of the list is related to the previous level by one of the pointer types specified by * <var>searchTypes</var>. */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset set, PointerType[] searchTypes, int depth) throws JWNLException { return makePointerTargetTreeList(set, searchTypes, null, depth, true); }
/** * Make a nested list of pointer targets to the default depth, starting at <code>synset</code>. Each * level of the list is related to the previous level by a pointer of type <var>searchType</var>. */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset set, PointerType searchType) throws JWNLException { return makePointerTargetTreeList(set, searchType, INFINITY); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at <code>synset</code>. Each * level of the list is related to the previous level by a pointer of type <var>searchType</var>. */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset set, PointerType searchType, int depth) throws JWNLException { return makePointerTargetTreeList(set, searchType, null, depth, true); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at <code>synset</code>. Each * level of the list is related to the previous level by a pointer of type <var>searchType</var>. * @param labelType the type used to label each pointer target in the tree * @param allowRedundancies if true, duplicate items will be included in the tree */ public PointerTargetTreeNodeList makePointerTargetTreeList(Synset set, PointerType searchType, PointerType labelType, int depth, boolean allowRedundancies) throws JWNLException { PointerType[] searchTypes = new PointerType[1]; searchTypes[0] = searchType; return makePointerTargetTreeList(set, searchTypes, labelType, depth, allowRedundancies); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at each <code>synset</code> in * <var>list</var>. Each level of the list is related to the previous level by a pointer of type * <var>searchType</var>. * @param labelType the type used to label each pointer target in the tree * @param allowRedundancies if true, duplicate items will be included in the tree */ public PointerTargetTreeNodeList makePointerTargetTreeList(PointerTargetNodeList list, PointerType searchType, PointerType labelType, int depth, boolean allowRedundancies) throws JWNLException { PointerType[] searchTypes = new PointerType[1]; searchTypes[0] = searchType; return makePointerTargetTreeList(list, searchTypes, labelType, depth, allowRedundancies); }
/** Find all entailed bys of <code>synset</code> to depth <code>depth</code>. */ public PointerTargetTree getEntailedByTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.ENTAILED_BY, depth)); }
/** Get all the synonyms of <code>synset</code> to depth <code>depth</code>. */ public PointerTargetTree getSynonymTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.SIMILAR_TO, null, depth, false)); }
/** Get all of the ancestors of <code>synset</code> to depth <code>depth</code> */ public PointerTargetTree getHypernymTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.HYPERNYM, depth)); }
/** Find all cause links for <code>synset</code> to depth <code>depth</code>.*/ public PointerTargetTree getCauseTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.CAUSE, depth)); }
/** Get all of the children of <code>synset</code> to depth <code>depth</code> */ public PointerTargetTree getHyponymTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.HYPONYM, depth)); }
/** Find all See Also relations to depth <code>depth</code>.*/ public PointerTargetTree getAlsoSeeTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.SEE_ALSO, depth)); }
/** Find all entailments for <code>synset</code> to depth <code>depth</code> */ public PointerTargetTree getEntailmentTree(Synset synset, int depth) throws JWNLException { return new PointerTargetTree(synset, makePointerTargetTreeList(synset, PointerType.ENTAILMENT, depth)); }
/** * Make a nested list of pointer targets to depth <var>depth</var>, starting at each <code>synset</code> in * <var>list</var>. Each level of the list is related to the previous level by one of the pointer types specified * by <var>searchTypes</var>. * @param labelType the type used to label each pointer target in the tree * @param allowRedundancies if true, duplicate items will be included in the tree */ public PointerTargetTreeNodeList makePointerTargetTreeList(PointerTargetNodeList list, PointerType[] searchTypes, PointerType labelType, int depth, boolean allowRedundancies) throws JWNLException { PointerTargetTreeNodeList treeList = new PointerTargetTreeNodeList(); for (Iterator itr = list.iterator(); itr.hasNext();) { PointerTargetNode node = (PointerTargetNode) itr.next(); treeList.add(node.getPointerTarget(), makePointerTargetTreeList(node.getSynset(), searchTypes, labelType, depth, allowRedundancies), labelType); } return treeList; }
/** 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; }
/** 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 antonyms of all words that mean the same as <code>synset</code> to depth <code>depth</code>.*/ public PointerTargetTree getIndirectAntonyms(Synset synset, int depth) throws JWNLException { PointerTargetTreeNodeList list = new PointerTargetTreeNodeList(); if (synset.getPOS() == POS.ADJECTIVE) { PointerTargetNodeList synonyms = getSynonyms(synset); list = makePointerTargetTreeList(synonyms, PointerType.ANTONYM, PointerType.ANTONYM, depth, false); } return new PointerTargetTree(new PointerTargetTreeNode(synset, list, null)); }
public Set<Synset> getRelatedSynsets(WordNetRelation relation, int chainingLength) throws WordNetException { if (chainingLength < 1) throw new WordNetException("chaining length must be positive. I got " + chainingLength); if (WordNetRelation.STRICT_2ND_DEGREE_COUSIN.equals(relation)) throw new WordNetMethodNotSupportedException("Extracting cousin relations is currently not supported by JwnlDictionary. Use JwiDictionary instead"); PointerType pointerType = JwnlUtils.wordNetRelationToPointerType(relation); if (pointerType == null) // some relations (inc. SYNONYM) have no neighbors, cos they have no matching JWNL relation // other relations just don't exist in ext JWNL return new HashSet<Synset>(); else { if (!relation.isTransitive()) chainingLength = 1; // most relations make no sense when chained try { return getSetOfSynsets(PointerUtils.getInstance().makePointerTargetTreeList(realSynset, pointerType, chainingLength)); } catch (JWNLException e) { throw new WordNetException("see nested" , e); } } }
/** * Turn an existing tree into an inheritance tree. * @param tree the tree to convert * @param searchTypes the pointer types to include in the pointer lists * @param labelType the <code>PointerType</code> with which to label each pointer * @param pointerDepth the depth to which to search for each pointer list * @param ancestorDepth the depth to which to go to in <code>tree</code> * @param allowRedundancies if true, duplicate items are allowed in the list */ public PointerTargetTree makeInheritedTree(PointerTargetTree tree, PointerType[] searchTypes, PointerType labelType, int pointerDepth, int ancestorDepth, boolean allowRedundancies) throws JWNLException { PointerTargetTreeNode root = tree.getRootNode(); root.setPointerTreeList(makePointerTargetTreeList(root.getSynset(), searchTypes, labelType, pointerDepth, allowRedundancies)); root.setChildTreeList(makeInheritedTreeList(root.getChildTreeList(), searchTypes, labelType, pointerDepth, ancestorDepth, allowRedundancies)); return new PointerTargetTree(root); }