TwsiWsdDisambiguator implements WSDAlgorithmDocumentTextBasic { @Override public String getDisambiguation(String documentText) throws SenseInventoryException { Viterbitagger tagger = new Viterbitagger(Configuration.taggerModelPrefix); String sentence = Util.tokenize(documentText); String taggedSentence = "%^%/BOS" + tagger.addPOStags(sentence) + " %$%/EOS"; sentence = "%^% " + sentence + " %$%"; String[] words = sentence.replace(" ", " ").toLowerCase().split(" "); String[] wordTag = taggedSentence.replace(" ", " ").split(" "); String[] postags = new String[words.length]; for (int i = 0; i < wordTag.length; i++) { String parts[] = wordTag[i].split("/"); postags[i] = parts[1]; } List<String> wordList = Arrays.asList(words); List<String> resultList = new ArrayList<String>(); for (int i = 0; i < wordList.size(); i++) { Substitution subst = sensub.getSubstitution(i, words, postags); if (subst != null) { resultList.add(subst.getSense().replaceAll("@@", "")); } else { resultList.add(wordList.get(i)); } } resultList.remove(0); resultList.remove(resultList.size() - 1); return StringUtils.join(resultList, " "); } TwsiWsdDisambiguator(TwsiSenseInventory inventory); @Override String getDisambiguation(String documentText); @Override String getDisambiguationMethod(); @Override SenseInventory getSenseInventory(); @Override void setSenseInventory(SenseInventory senseInventory);  }
@Ignore @Test public void run() throws Exception { TwsiSenseInventory si = new TwsiSenseInventoryBase("/home/miller/src/TWSISubstituter/conf/TWSI2_config.conf"); TwsiWsdDisambiguator disamb = new TwsiWsdDisambiguator(si); Map<String, Double> expResult = new HashMap<String, Double>(); expResult.put("capital@@3", 0.5); String result = disamb.getDisambiguation("The company manages over 10 million dollars in capital assets."); assertEquals(result, expResult); expResult = new HashMap<String, Double>(); expResult.put("capital@@5", 0.5); result = disamb.getDisambiguation("When imposing capital punishment, the state becomes a murder of sorts."); assertEquals(result, expResult); expResult = new HashMap<String, Double>(); expResult.put("capital@@1", 0.5); result = disamb.getDisambiguation("Capital cities are sometimes deliberately planned by government to house the seat of government of the nation or subdivision."); assertEquals(result, expResult); for (String sense : si.getSenses("capital")) { System.out.println(sense + ": " + si.getSenseDescription(sense)); } }