/** * Find all relationships of type <var>type</var> between <var>sourceSynset</var> and <var>targetSynset</var>. * This method creates a symmetric or asymmetric relationship based on whether <var>type</var> is symmetric. */ public RelationshipList findRelationships( Synset sourceSynset, Synset targetSynset, PointerType type) throws JWNLException { return (type.isSymmetric()) ? findSymmetricRelationships(sourceSynset, targetSynset, type) : findAsymmetricRelationships(sourceSynset, targetSynset, type); }
private void demonstrateSymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // find all synonyms that <var>start</var> and <var>end</var> have in common RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.SIMILAR_TO); System.out.println("Synonym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); } }
/** * Build a relationsip from <var>node</var> back to it's root ancestor and * then reverse the list. */ private PointerTargetNodeList findSymmetricRelationship(PointerTargetTreeNode node, PointerType type) { PointerTargetNodeList list = new PointerTargetNodeList(); buildSymmetricRelationshipList(list, node); list = list.reverse(); // set the root's pointer type ((PointerTargetNode)list.get(0)).setType(type); return list; }
/** * 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) throws JWNLException { return findAsymmetricRelationships(sourceSynset, targetSynset, type, DEFAULT_ASYMMETRIC_SEARCH_DEPTH); }
/** * A symmetric relationship is one whose type is symmetric (i.e. is it's own * inverse. An example of a symmetric relationship is synonomy. */ private RelationshipList findSymmetricRelationships( Synset sourceSynset, Synset targetSynset, PointerType type) throws JWNLException { return findSymmetricRelationships(sourceSynset, targetSynset, type, DEFAULT_SYMMETRIC_SEARCH_DEPTH); }
/** 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; }
/** * 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; }
private void demonstrateSymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // find all synonyms that <var>start</var> and <var>end</var> have in common RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.SIMILAR_TO); System.out.println("Synonym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); } }
/** Build the relationship. */ private void buildSymmetricRelationshipList(PointerTargetNodeList list, PointerTargetTreeNode node) { list.add(node.getPointerTarget(), node.getType()); if (node.getParent() != null) { buildSymmetricRelationshipList(list, node.getParent()); } }
private void demonstrateSymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // find all synonyms that <var>start</var> and <var>end</var> have in common RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.SIMILAR_TO); System.out.println("Synonym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); } }
/** * Find all relationships of type <var>type</var> between <var>sourceSynset</var> and <var>targetSynset</var> * to depth <var>depth</var>. This method creates a symmetric or asymmetric relationship based on * whether <var>type</var> is symmetric. */ public RelationshipList findRelationships( Synset sourceSynset, Synset targetSynset, PointerType type, int depth) throws JWNLException { return (type.isSymmetric()) ? findSymmetricRelationships(sourceSynset, targetSynset, type, depth) : findAsymmetricRelationships(sourceSynset, targetSynset, type, depth); }
private void demonstrateSymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // find all synonyms that <var>start</var> and <var>end</var> have in common RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.SIMILAR_TO); System.out.println("Synonym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); } }
private void demonstrateAsymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // Try to find a relationship between the first sense of <var>start</var> and the first sense of <var>end</var> RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.HYPERNYM); System.out.println("Hypernym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Common Parent Index: " + ((AsymmetricRelationship) list.get(0)).getCommonParentIndex()); System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); }
private void demonstrateAsymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // Try to find a relationship between the first sense of <var>start</var> and the first sense of <var>end</var> RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.HYPERNYM); System.out.println("Hypernym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Common Parent Index: " + ((AsymmetricRelationship) list.get(0)).getCommonParentIndex()); System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); }
private void demonstrateAsymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // Try to find a relationship between the first sense of <var>start</var> and the first sense of <var>end</var> RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.HYPERNYM); System.out.println("Hypernym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Common Parent Index: " + ((AsymmetricRelationship) list.get(0)).getCommonParentIndex()); System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); }
private void demonstrateAsymmetricRelationshipOperation(IndexWord start, IndexWord end) throws JWNLException { // Try to find a relationship between the first sense of <var>start</var> and the first sense of <var>end</var> RelationshipList list = RelationshipFinder.getInstance().findRelationships(start.getSense(1), end.getSense(1), PointerType.HYPERNYM); System.out.println("Hypernym relationship between \"" + start.getLemma() + "\" and \"" + end.getLemma() + "\":"); for (Iterator itr = list.iterator(); itr.hasNext();) { ((Relationship) itr.next()).getNodeList().print(); } System.out.println("Common Parent Index: " + ((AsymmetricRelationship) list.get(0)).getCommonParentIndex()); System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth()); }