LexicalAligner implements AlignmentComponent { @Override public void annotate(JCas aJCas) throws AlignmentComponentException { try { logger.info("Started annotating a text and hypothesis pair using lexical aligner"); getTokenAnnotations(aJCas); for (LexicalResource<? extends RuleInfo> resource : lexicalResources) { LexicalResourceInformation resourceInfo = lexicalResourcesInformation.get(resource.getClass().getName()); String textPhrase = "", hypoPhrase = ""; for (int textStart = 0; textStart < textTokens.size(); ++textStart) { for (int textEnd = textStart; textEnd < Math.min(textTokens.size(), textStart + maxPhrase); ++textEnd) { textPhrase = getPhrase(textTokens, textStart, textEnd, resourceInfo.useLemma()); for (int hypoStart = 0; hypoStart < hypoTokens.size(); ++hypoStart) { for (int hypoEnd = hypoStart; hypoEnd < Math.min(hypoTokens.size(), hypoStart + maxPhrase); ++hypoEnd) { hypoPhrase = getPhrase(hypoTokens, hypoStart, hypoEnd, resourceInfo.useLemma()); List<LexicalRule<? extends RuleInfo>> ruleFromLeft = getRules(resource, textPhrase, hypoPhrase, resourceInfo.getLeftSidePOS(), resourceInfo.getRightSidePOS()); List<LexicalRule<? extends RuleInfo>> ruleFromRight = getRules(resource, hypoPhrase, textPhrase, resourceInfo.getLeftSidePOS(), resourceInfo.getRightSidePOS()); createAlignmentLinks( aJCas, textStart, textEnd, hypoStart, hypoEnd, ruleFromLeft, ruleFromRight, resourceInfo.getVersion()); } } } } } logger.info("Finished annotating a text and hypothesis pair using lexical aligner"); } catch (CASException | LexicalResourceException e) { throw new AlignmentComponentException( "LexicalAligner failed aligning the sentence pair.", e); } } LexicalAligner(CommonConfig config);  LexicalAligner(List<LexicalResource<? extends RuleInfo>> lexicalResources, 
			int maxPhrase, 
			HashMap<String, LexicalResourceInformation> lexicalResourcesInformation); @Override void annotate(JCas aJCas); @Override String getComponentName(); @Override String getInstanceName(); @Override void close(); void cleanUp();  }
@Test public void test1() { try { logger.info("Tokenize and lemmatize the sentence pair #1"); JCas pair1 = lap.generateSingleTHPairCAS(t1, h1); logger.info("Aligning pair #1"); aligner.annotate(pair1); logger.info("Finished aligning pair #1"); JCas hypoView = pair1.getView(LAP_ImplBase.HYPOTHESISVIEW); logger.info("Pair 1:"); logger.info("T: " + t1); logger.info("H: " + h1); boolean assassinKiller = false, deathPenaltyCapitalPunishment = false; for (Link link : JCasUtil.select(hypoView, Link.class)) { logger.info(String.format("Text phrase: %s, " + "hypothesis phrase: %s, " + "id: %s, confidence: %f, direction: %s", link.getTSideTarget().getCoveredText(), link.getHSideTarget().getCoveredText(), link.getID(), link.getStrength(), link.getDirection().toString())); assassinKiller = assassinKiller || ((link.getTSideTarget().getBegin() == 4) && (link.getTSideTarget().getEnd() == 12) && (link.getHSideTarget().getBegin() == 4) && (link.getHSideTarget().getEnd() == 10)); deathPenaltyCapitalPunishment = deathPenaltyCapitalPunishment || ((link.getTSideTarget().getBegin() == 44) && (link.getTSideTarget().getEnd() == 57) && (link.getHSideTarget().getBegin() == 52) && (link.getHSideTarget().getEnd() == 70)); } if (!assassinKiller) { fail("There is no alignment link between 'assassin' and 'killer'." + " This alignment link appears in: WordNet, BAP, Lin Dependency," + " Lin Proximity and Wikipedia. " + " Make sure that at least some of these resources were loaded correctly."); } if (!deathPenaltyCapitalPunishment) { fail("There is no alignment link between 'death penalty' and 'capital punishment'." + " This alignment link appears in: WordNet and Wikipedia. " + " Make sure that at least one of these resources was loaded correctly."); } } catch (Exception e) { logger.info("Could not process first pair. " + e.getMessage()); } }
@Test public void test2() { try { logger.info("Tokenize and lemmatize the sentence pair #2"); JCas pair2 = lap.generateSingleTHPairCAS(t2, h2); logger.info("Aligning pair #2"); aligner.annotate(pair2); logger.info("Finished aligning pair #2"); JCas hypoView = pair2.getView(LAP_ImplBase.HYPOTHESISVIEW); logger.info("Pair 2:"); logger.info("T: " + t2); logger.info("H: " + h2); boolean killedWounded = false, dallasTexas = false; for (Link link : JCasUtil.select(hypoView, Link.class)) { logger.info(String.format("Text phrase: %s, " + "hypothesis phrase: %s, " + "id: %s, confidence: %f, direction: %s", link.getTSideTarget().getCoveredText(), link.getHSideTarget().getCoveredText(), link.getID(), link.getStrength(), link.getDirection().toString())); killedWounded = killedWounded || ((link.getTSideTarget().getBegin() == 12) && (link.getTSideTarget().getEnd() == 18) && (link.getHSideTarget().getBegin() == 12) && (link.getHSideTarget().getEnd() == 19)); dallasTexas = dallasTexas || ((link.getTSideTarget().getBegin() == 22) && (link.getTSideTarget().getEnd() == 28) && (link.getHSideTarget().getBegin() == 32) && (link.getHSideTarget().getEnd() == 37)); } if (!killedWounded) { fail("There is no alignment link between 'killed' and 'wounded'." + " This alignment link appears in VerbOcean." + " Make sure that this resource was loaded correctly."); } if (!dallasTexas) { fail("There is no alignment link between 'Dallas' and 'Texas'." + " This alignment link appears in: WordNet and GEO. " + " Make sure that at least one of these resources was loaded correctly."); } } catch (Exception e) { logger.info("Could not process first pair. " + e.getMessage()); } }