LexicalAlignerFromLexicalResource implements AlignmentComponent { @Override public void annotate(JCas aJCas) throws AlignmentComponentException { String tLemmaSeq = null; Lemma[] tSideLemmas = null; List<Lemma[]> allHSideCandidates = null; try { tLemmaSeq = getLemmasAsStringSequence(aJCas.getView(LAP_ImplBase.TEXTVIEW)); Collection<Lemma> lemmas = JCasUtil.select(aJCas.getView(LAP_ImplBase.TEXTVIEW), Lemma.class); tSideLemmas = lemmas.toArray(new Lemma[lemmas.size()]); allHSideCandidates = getAllPossibleCandidates(aJCas.getView(LAP_ImplBase.HYPOTHESISVIEW)); } catch (CASException ce) { throw new AlignmentComponentException("unable to access views (text or hypothesis) of the given CAS"); } try { for (Lemma[] oneCand : allHSideCandidates) { String candVal = lemmaArrAsString(oneCand); for (LexicalRule<? extends RuleInfo> rule : underlyingResource.getRulesForRight(candVal, null)) { if (tLemmaSeq.contains(rule.getLLemma())) { addAlignmentLinkT2H(aJCas, rule, tSideLemmas, oneCand); } } } } catch (LexicalResourceException le) { throw new AlignmentComponentException("Underlying Lexical Resource raised an exception: " + le.getMessage(), le); } } LexicalAlignerFromLexicalResource(LexicalResource<? extends RuleInfo> res, Set<GroupLabelInferenceLevel> defaultGroupLabel, int maxPhraseLen);  LexicalAlignerFromLexicalResource(LexicalResource<? extends RuleInfo> res, int maxPhraseLen);  LexicalAlignerFromLexicalResource(LexicalResource<? extends RuleInfo> res);  LexicalAlignerFromLexicalResource(LexicalResource<? extends RuleInfo> res, Set<GroupLabelInferenceLevel> defaultGroupLabel);  LexicalAlignerFromLexicalResource(LexicalResource<? extends RuleInfo> res, Boolean supportPhrase, int maxPhraseLen, Map<String,Set<GroupLabelInferenceLevel>> groupLabelMapI, Map<String,Set<GroupLabelDomainLevel>> groupLabelMapD, Set<GroupLabelInferenceLevel> defaultGroupLabel); @Override void annotate(JCas aJCas); void close(); @Override String getComponentName(); @Override String getInstanceName();  }
@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"); alignerWordNetEN.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()); e.printStackTrace(); } }
@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"); alignerWordNetEN.annotate(pair2); alignerVerbOceanEN.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()); } }