ImsWSDAnnotator extends WSDAnnotatorBaseDocumentCollective { static Map<String, String> getMapping( String documentText, String senseDisambiguatedText) throws SenseInventoryException { Map<String, String> mapping = new HashMap<String, String>(); String[] words = documentText.replaceAll("\n", "").replaceAll("\\.", " ").replaceAll(" ", " ").split(" "); String[] senses = senseDisambiguatedText.replaceAll("\n", "").replaceAll("\\.", " ").replaceAll(" ", " ").split(" "); if(words.length != senses.length){ throw new SenseInventoryException("Mapping from IMS to WSDItems cannot be performed."); } for(int n=0;n<words.length;n++){ if(!words[n].equalsIgnoreCase(senses[n])){ mapping.put(words[n], senses[n]); } } return mapping; }  @Override void initialize(UimaContext context); final static String WSD_ALGORITHM_RESOURCE; }
@Test public void testMapping() throws SenseInventoryException { String input = "Lucy is in the sky with diamonds. She lives in a yellow submarine.\n\nShe has starnge hair."; String output = "1x05x00xx 2x42x03xx in the 1x17x00xx with 1x21x00xx .\nShe 2x42x08xx in a 5x00x00xchromaticx00 1x06x00xx .\nShe 2x40x00xx starnge 1x08x00xx ."; Map<String,String> mapping = ImsWSDAnnotator.getMapping(input, output); assertNotNull(mapping); assertEquals(9, mapping.size()); assertEquals("1x21x00xx", mapping.get("diamonds")); }