From: <lor...@us...> - 2011-09-15 09:24:52
|
Revision: 3269 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3269&view=rev Author: lorenz_b Date: 2011-09-15 09:24:46 +0000 (Thu, 15 Sep 2011) Log Message: ----------- Changed resource loading. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-09-15 08:15:48 UTC (rev 3268) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-09-15 09:24:46 UTC (rev 3269) @@ -17,7 +17,7 @@ public WordNet() { try { - JWNL.initialize(WordNet.class.getClassLoader().getResourceAsStream("tbsl/wordnet_properties.xml")); + JWNL.initialize(this.getClass().getClassLoader().getResourceAsStream("tbsl/wordnet_properties.xml")); dict = Dictionary.getInstance(); } catch (JWNLException e) { e.printStackTrace(); @@ -70,5 +70,9 @@ return result; } + + public static void main(String[] args) { + System.out.println(new WordNet().getBestSynonyms(POS.VERB, "learn")); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-09-18 08:40:20
|
Revision: 3278 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3278&view=rev Author: sebastianwtr Date: 2011-09-18 08:40:14 +0000 (Sun, 18 Sep 2011) Log Message: ----------- [tbsl] added a new function to get the Hypernyms and Hyponyms of a given word. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-09-16 20:20:52 UTC (rev 3277) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-09-18 08:40:14 UTC (rev 3278) @@ -1,14 +1,18 @@ package org.dllearner.algorithm.tbsl.nlp; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import net.didion.jwnl.JWNL; import net.didion.jwnl.JWNLException; import net.didion.jwnl.data.IndexWord; import net.didion.jwnl.data.POS; +import net.didion.jwnl.data.PointerUtils; import net.didion.jwnl.data.Synset; import net.didion.jwnl.data.Word; +import net.didion.jwnl.data.list.PointerTargetNode; +import net.didion.jwnl.data.list.PointerTargetNodeList; import net.didion.jwnl.dictionary.Dictionary; public class WordNet { @@ -74,5 +78,63 @@ public static void main(String[] args) { System.out.println(new WordNet().getBestSynonyms(POS.VERB, "learn")); } + + /** + * Funktion returns a List of Hypo and Hypernyms of a given string + * @param s Word for which you want to get Hypo and Hypersyms + * @return List of Hypo and Hypernyms + * @throws JWNLException + */ + public List<String> getRelatedNouns(String s) throws JWNLException { + List<String> result = new ArrayList<String>(); + IndexWord word = dict.getIndexWord(POS.NOUN,s); + + Synset sense = word.getSense(1); + + PointerTargetNodeList relatedListHypernyms = null; + PointerTargetNodeList relatedListHyponyms = null; + try { + relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Iterator i = relatedListHypernyms.iterator(); + while (i.hasNext()) { + PointerTargetNode related = (PointerTargetNode) i.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + + Iterator j = relatedListHyponyms.iterator(); + while (j.hasNext()) { + PointerTargetNode related = (PointerTargetNode) j.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + + return result; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-29 10:19:08
|
Revision: 3448 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3448&view=rev Author: sebastianwtr Date: 2011-11-29 10:19:02 +0000 (Tue, 29 Nov 2011) Log Message: ----------- [tbsl] fixed getRelatedNouns function Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-11-28 15:20:35 UTC (rev 3447) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-11-29 10:19:02 UTC (rev 3448) @@ -117,56 +117,67 @@ * @return List of Hypo and Hypernyms * @throws JWNLException */ - public List<String> getRelatedNouns(String s) throws JWNLException { + public List<String> getRelatedNouns(String s) { List<String> result = new ArrayList<String>(); - IndexWord word = dict.getIndexWord(POS.NOUN,s); - - Synset sense = word.getSense(1); - - PointerTargetNodeList relatedListHypernyms = null; - PointerTargetNodeList relatedListHyponyms = null; - try { - relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); - } catch (JWNLException e) { + IndexWord word = null; + Synset sense=null; + try{ + word=dict.getIndexWord(POS.NOUN,s); + if(word!=null){ + sense = word.getSense(1); + //Synset sense = word.getSense(1); + + PointerTargetNodeList relatedListHypernyms = null; + PointerTargetNodeList relatedListHyponyms = null; + try { + relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Iterator i = relatedListHypernyms.iterator(); + while (i.hasNext()) { + PointerTargetNode related = (PointerTargetNode) i.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + + Iterator j = relatedListHyponyms.iterator(); + while (j.hasNext()) { + PointerTargetNode related = (PointerTargetNode) j.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + } + }catch (JWNLException e) { // TODO Auto-generated catch block e.printStackTrace(); } - try { - relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); - } catch (JWNLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Iterator i = relatedListHypernyms.iterator(); - while (i.hasNext()) { - PointerTargetNode related = (PointerTargetNode) i.next(); - Synset s1 = related.getSynset(); - String tmp=(s1.toString()).replace(s1.getGloss(), ""); - tmp=tmp.replace(" -- ()]",""); - tmp=tmp.replaceAll("[0-9]",""); - tmp=tmp.replace("[Synset: [Offset: ",""); - tmp=tmp.replace("] [POS: noun] Words: ",""); - //its possible, that there is more than one word in a line from wordnet - String[] array_tmp=tmp.split(","); - for(String z : array_tmp) result.add(z.replace(" ", "")); - } - Iterator j = relatedListHyponyms.iterator(); - while (j.hasNext()) { - PointerTargetNode related = (PointerTargetNode) j.next(); - Synset s1 = related.getSynset(); - String tmp=(s1.toString()).replace(s1.getGloss(), ""); - tmp=tmp.replace(" -- ()]",""); - tmp=tmp.replaceAll("[0-9]",""); - tmp=tmp.replace("[Synset: [Offset: ",""); - tmp=tmp.replace("] [POS: noun] Words: ",""); - //its possible, that there is more than one word in a line from wordnet - String[] array_tmp=tmp.split(","); - for(String z : array_tmp) result.add(z.replace(" ", "")); - } return result; } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-12-07 16:15:44
|
Revision: 3485 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3485&view=rev Author: sebastianwtr Date: 2011-12-07 16:15:38 +0000 (Wed, 07 Dec 2011) Log Message: ----------- [tbsl] removed System.out Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-12-07 15:58:10 UTC (rev 3484) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-12-07 16:15:38 UTC (rev 3485) @@ -71,9 +71,9 @@ IndexWord iw = dict.getIndexWord(pos, s);//dict.getMorphologicalProcessor().lookupBaseForm(pos, s) // IndexWord iw = dict.getMorphologicalProcessor().lookupBaseForm(pos, s); if(iw != null){ - Synset[] synsets = iw.getSenses();System.out.println(synsets[0]); + Synset[] synsets = iw.getSenses(); + //System.out.println(synsets[0]); PointerTarget[] pointerArr = synsets[0].getTargets(); - System.out.println(pointerArr); } } catch (JWNLException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |