public static void main(String[] args) { try { f(args); } catch (Exception e) { ExceptionUtil.outputException(e, System.out); } }
@Test public void test() throws Exception { try { // Map token infos by ID tokensById = new LinkedHashMap<Integer, TestTokenInfo>(EXPECTED_TOKENS.length); for (TestTokenInfo info : EXPECTED_TOKENS) { tokensById.put(info.id, info); } // Run LAP LAPAccess lap = getLAP(); JCas mainJcas = lap.generateSingleTHPairCAS(TEXT, HYPOTHESIS); JCas jcas = mainJcas.getView(LAP_ImplBase.TEXTVIEW); // Verify sentences Iterator<TestSentenceInfo> iterSentence = Arrays.asList(EXPECTED_SENTENCES).iterator(); for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) { verifySentence(sentence, iterSentence.next()); } // Map generated Tokens to infos - by their order! expectedByGeneratedToken = new LinkedHashMap<Token, TestTokenInfo>(EXPECTED_TOKENS.length); Iterator<TestTokenInfo> iterToken = tokensById.values().iterator(); for (Token token : JCasUtil.select(jcas, Token.class)) { expectedByGeneratedToken.put(token, iterToken.next()); } // For each Token, find all its dependencies governors = new LinkedHashMap<Token, Set<TestDependencyInfo>>(expectedByGeneratedToken.size()); for (Token token : expectedByGeneratedToken.keySet()) { governors.put(token, new HashSet<TestDependencyInfo>()); } for (Dependency dep : JCasUtil.select(jcas, Dependency.class)) { int governorId = expectedByGeneratedToken.get(dep.getGovernor()).id; TestDependencyInfo depInfo = new TestDependencyInfo(dep.getDependencyType(), governorId); governors.get(dep.getDependent()).add(depInfo); } // Verify tokens for (Entry<Token, TestTokenInfo> entry : expectedByGeneratedToken.entrySet()) { verifyToken(entry.getKey(), entry.getValue()); } // Verify coref groups corefChainsByFirstMentionStart = new TreeMap<Integer, CoreferenceChain>(); for (CoreferenceChain chain : JCasUtil.select(jcas, CoreferenceChain.class)) { // use this map in order to order chain by a predefined order - the start offset of its // first CoreferenceLink corefChainsByFirstMentionStart.put(chain.getFirst().getBegin(), chain); } if (corefChainsByFirstMentionStart.size() != EXPECTED_COREF.length) { throw new LAPVerificationException( "Bad amount of coreference chains, expected " + EXPECTED_COREF.length + ", got " + corefChainsByFirstMentionStart.size()); } Iterator<TestCorefMentionInfo[]> iterCorefGroups = Arrays.asList(EXPECTED_COREF).iterator(); for (CoreferenceChain chain : corefChainsByFirstMentionStart.values()) { Iterator<TestCorefMentionInfo> iterCoref = Arrays.asList(iterCorefGroups.next()).iterator(); for (CoreferenceLink link = chain.getFirst(); link != null; link = link.getNext()) { verifyCorefLink(link, iterCoref.next()); } } } catch (Exception e) { ExceptionUtil.outputException(e, System.out); throw e; } }