From: <lor...@us...> - 2011-11-22 21:19:57
|
Revision: 3428 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3428&view=rev Author: lorenz_b Date: 2011-11-22 21:19:51 +0000 (Tue, 22 Nov 2011) Log Message: ----------- Continued WordNet similarity measure. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/WordnetSimilarity.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/WordnetSimilarity.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/WordnetSimilarity.java 2011-11-22 14:39:43 UTC (rev 3427) +++ trunk/components-core/src/main/java/org/dllearner/utilities/WordnetSimilarity.java 2011-11-22 21:19:51 UTC (rev 3428) @@ -32,33 +32,96 @@ try { IndexWord iw = dict.getIndexWord(pos, s1);//dict.getMorphologicalProcessor().lookupBaseForm(pos, s) // IndexWord iw = dict.getMorphologicalProcessor().lookupBaseForm(pos, s); + getUpwardHierachy(s1, pos); + getUpwardHierachy(s2, pos); + + + } catch (JWNLException e) { + e.printStackTrace(); + } + + + return -1; + } + + private List<PointerTarget> getUpwardHierachy(PointerTarget target){ + List<PointerTarget> hierarchy = new ArrayList<PointerTarget>(); + try { + PointerTarget[] targets = target.getTargets(PointerType.HYPERNYM); + for (PointerTarget t : targets) { + hierarchy.add(t); + hierarchy.addAll(getUpwardHierachy(t)); + } + } catch (JWNLException e) { + e.printStackTrace(); + } + return hierarchy; + + } + +// private List<List<PointerTarget>> getUpwardHierachies(List<List<PointerTarget>> targets){ +// List<List<PointerTarget>> hierarchies = new ArrayList<List<PointerTarget>>(); +// try { +// PointerTarget[] targets = target.getTargets(PointerType.HYPERNYM); +// for (PointerTarget t : targets) { +// hierarchy.add(t); +// hierarchy.addAll(getUpwardHierachy(t)); +// } +// } catch (JWNLException e) { +// e.printStackTrace(); +// } +// return hierarchy; +// +// } + + private List<PointerTarget> getUpwardHierachy2(PointerTarget target){ + List<PointerTarget> hierarchy = new ArrayList<PointerTarget>(); + try { + PointerTarget[] targets = target.getTargets(PointerType.HYPERNYM); + for (PointerTarget t : targets) { + hierarchy.add(t); + hierarchy.addAll(getUpwardHierachy(t)); + } + } catch (JWNLException e) { + e.printStackTrace(); + } + return hierarchy; + + } + + private void getUpwardHierachy(String word, POS pos){ + try { + IndexWord iw = dict.getIndexWord(pos, word); + for(Synset synset : iw.getSenses()){ + for(PointerTarget t : getUpwardHierachy(synset)){ + System.out.print(((Synset)t).getWord(0).getLemma() + "-->"); + } + System.out.println(); + } + } catch (JWNLException e) { + e.printStackTrace(); + } + + } + + private void getHypernyms(IndexWord iw){ + try { if(iw != null){ Synset[] synsets = iw.getSenses(); for(Synset s : synsets){ System.out.println(s); PointerTarget[] targets = s.getTargets(PointerType.HYPERNYM); - for (PointerTarget target : targets) - { - Word[] words = ((Synset) target).getWords(); - for (Word word : words) - { - System.out.println(word); - } - } + for (PointerTarget target : targets) { + Word[] words = ((Synset) target).getWords(); + for (Word word : words) { + System.out.println(word); + } + } } -// Word[] words = synsets[0].getWords(); -// for(Word w : words){ -// String c = w.getLemma(); -// System.out.println(c); -// } } - } catch (JWNLException e) { e.printStackTrace(); } - - - return -1; } public static void main(String[] args) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |