@Test @Ignore public void testDegreeCentrality() throws MalformedURLException, JWNLException, IOException, SenseInventoryException, InterruptedException { WordNetSynsetSenseInventory inventory = new WordNetSynsetSenseInventory( new FileInputStream( "/home/miller/share/WordNet/WordNet-3.0/extjwnl_properties.xml")); DegreeCentralityWSD wsdAlgorithm = new DegreeCentralityWSD(inventory); JungGraphVisualizer g = new JungGraphVisualizer(); inventory.setSenseDescriptionFormat("<html><b>%w</b><br />%d</html>"); g.setAnimationDimensions(1000, 500); g.setAnimationDelay(0); g.setInteractive(true); wsdAlgorithm.setGraphVisualizer(g); List<Pair<String, POS>> sentence = new ArrayList<Pair<String, POS>>(); sentence.add(new Pair<String, POS>("drink", POS.VERB)); sentence.add(new Pair<String, POS>("milk", POS.NOUN)); sentence.add(new Pair<String, POS>("straw", POS.NOUN)); wsdAlgorithm.setSearchDepth(4); Map<Pair<String,POS>, Map<String, Double>> dabMap = wsdAlgorithm .getDisambiguation(sentence); Thread.sleep(5000); assertNotNull(dabMap); assertEquals(2, dabMap.size()); Map<String, Double> wordMap; wordMap = dabMap.get(new Pair<String, POS>("drink", POS.VERB)); assertNotNull(wordMap); assertEquals(1, wordMap.size()); assertEquals(1.0, wordMap.get("01170052v"), 0.001); wordMap = dabMap.get(new Pair<String, POS>("milk", POS.NOUN)); assertNotNull(wordMap); assertEquals(1, wordMap.size()); assertEquals(1.0, wordMap.get("07844042n"), 0.001); }
@Override protected Map<Pair<String, POS>, Map<String, Double>> getDisambiguation( Collection<Pair<String, POS>> sods, Graph<String, UnorderedPair<String>> dGraph) throws SenseInventoryException { final Map<Pair<String, POS>, Map<String, Double>> solutions = new HashMap<Pair<String, POS>, Map<String, Double>>(); int disambiguatedCount = 0; for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); String highestDegree = null; for (String sense : senses) { if (dGraph.degree(sense) < minDegree) { continue; } if (highestDegree == null || dGraph.degree(sense) > dGraph.degree(highestDegree)) { highestDegree = sense; } } if (highestDegree == null) { logger.debug("Failed to disambiguate " + wsdItem); continue; } disambiguatedCount++; Map<String, Double> senseScores = new HashMap<String, Double>(); senseScores.put(highestDegree, 1.0); solutions.put(wsdItem, senseScores); logger.debug("\"" + wsdItem.getFirst() + "\" = " + highestDegree + ": " + inventory.getSenseDescription(highestDegree)); if (graphVisualizer != null) { graphVisualizer.highlight(highestDegree); } } logger.debug("Disambiguated " + (disambiguatedCount) + " of " + sods.size() + " items"); return solutions; }
DegreeCentralityWSD extends GraphConnectivityWSD { @Override protected Map<Pair<String, POS>, Map<String, Double>> getDisambiguation( Collection<Pair<String, POS>> sods, Graph<String, UnorderedPair<String>> dGraph) throws SenseInventoryException { final Map<Pair<String, POS>, Map<String, Double>> solutions = new HashMap<Pair<String, POS>, Map<String, Double>>(); int disambiguatedCount = 0; for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); String highestDegree = null; for (String sense : senses) { if (dGraph.degree(sense) < minDegree) { continue; } if (highestDegree == null || dGraph.degree(sense) > dGraph.degree(highestDegree)) { highestDegree = sense; } } if (highestDegree == null) { logger.debug("Failed to disambiguate " + wsdItem); continue; } disambiguatedCount++; Map<String, Double> senseScores = new HashMap<String, Double>(); senseScores.put(highestDegree, 1.0); solutions.put(wsdItem, senseScores); logger.debug("\"" + wsdItem.getFirst() + "\" = " + highestDegree + ": " + inventory.getSenseDescription(highestDegree)); if (graphVisualizer != null) { graphVisualizer.highlight(highestDegree); } } logger.debug("Disambiguated " + (disambiguatedCount) + " of " + sods.size() + " items"); return solutions; } }
DegreeCentralityWSD extends GraphConnectivityWSD { @Override protected Map<Pair<String, POS>, Map<String, Double>> getDisambiguation( Collection<Pair<String, POS>> sods, Graph<String, UnorderedPair<String>> dGraph) throws SenseInventoryException { final Map<Pair<String, POS>, Map<String, Double>> solutions = new HashMap<Pair<String, POS>, Map<String, Double>>(); int disambiguatedCount = 0; for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); String highestDegree = null; for (String sense : senses) { if (dGraph.degree(sense) < minDegree) { continue; } if (highestDegree == null || dGraph.degree(sense) > dGraph.degree(highestDegree)) { highestDegree = sense; } } if (highestDegree == null) { logger.debug("Failed to disambiguate " + wsdItem); continue; } disambiguatedCount++; Map<String, Double> senseScores = new HashMap<String, Double>(); senseScores.put(highestDegree, 1.0); solutions.put(wsdItem, senseScores); logger.debug("\"" + wsdItem.getFirst() + "\" = " + highestDegree + ": " + inventory.getSenseDescription(highestDegree)); if (graphVisualizer != null) { graphVisualizer.highlight(highestDegree); } } logger.debug("Disambiguated " + (disambiguatedCount) + " of " + sods.size() + " items"); return solutions; } DegreeCentralityWSD(SenseTaxonomy inventory); }
DegreeCentralityWSD extends GraphConnectivityWSD { @Override protected Map<Pair<String, POS>, Map<String, Double>> getDisambiguation( Collection<Pair<String, POS>> sods, Graph<String, UnorderedPair<String>> dGraph) throws SenseInventoryException { final Map<Pair<String, POS>, Map<String, Double>> solutions = new HashMap<Pair<String, POS>, Map<String, Double>>(); int disambiguatedCount = 0; for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); String highestDegree = null; for (String sense : senses) { if (dGraph.degree(sense) < minDegree) { continue; } if (highestDegree == null || dGraph.degree(sense) > dGraph.degree(highestDegree)) { highestDegree = sense; } } if (highestDegree == null) { logger.debug("Failed to disambiguate " + wsdItem); continue; } disambiguatedCount++; Map<String, Double> senseScores = new HashMap<String, Double>(); senseScores.put(highestDegree, 1.0); solutions.put(wsdItem, senseScores); logger.debug("\"" + wsdItem.getFirst() + "\" = " + highestDegree + ": " + inventory.getSenseDescription(highestDegree)); if (graphVisualizer != null) { graphVisualizer.highlight(highestDegree); } } logger.debug("Disambiguated " + (disambiguatedCount) + " of " + sods.size() + " items"); return solutions; } DegreeCentralityWSD(SenseTaxonomy inventory); void setMinDegree(int minDegree); int getMinDegree(); }
DegreeCentralityWSD extends GraphConnectivityWSD { @Override protected Map<Pair<String, POS>, Map<String, Double>> getDisambiguation( Collection<Pair<String, POS>> sods, Graph<String, UnorderedPair<String>> dGraph) throws SenseInventoryException { final Map<Pair<String, POS>, Map<String, Double>> solutions = new HashMap<Pair<String, POS>, Map<String, Double>>(); int disambiguatedCount = 0; for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); String highestDegree = null; for (String sense : senses) { if (dGraph.degree(sense) < minDegree) { continue; } if (highestDegree == null || dGraph.degree(sense) > dGraph.degree(highestDegree)) { highestDegree = sense; } } if (highestDegree == null) { logger.debug("Failed to disambiguate " + wsdItem); continue; } disambiguatedCount++; Map<String, Double> senseScores = new HashMap<String, Double>(); senseScores.put(highestDegree, 1.0); solutions.put(wsdItem, senseScores); logger.debug("\"" + wsdItem.getFirst() + "\" = " + highestDegree + ": " + inventory.getSenseDescription(highestDegree)); if (graphVisualizer != null) { graphVisualizer.highlight(highestDegree); } } logger.debug("Disambiguated " + (disambiguatedCount) + " of " + sods.size() + " items"); return solutions; } DegreeCentralityWSD(SenseTaxonomy inventory); void setMinDegree(int minDegree); int getMinDegree();  }