private void assertSrxDocumentEquals(SrxDocument leftDocument, SrxDocument rightDocument) { assertEquals(leftDocument.getCascade(), rightDocument.getCascade()); List<LanguageMap> leftLanguageMapList = leftDocument.getLanguageMapList(); List<LanguageMap> rightLanguageMapList = rightDocument.getLanguageMapList(); assertEquals(leftLanguageMapList.size(), rightLanguageMapList.size()); for (int i = 0; i < leftLanguageMapList.size(); ++i) { LanguageMap leftLanguageMap = leftLanguageMapList.get(i); LanguageMap rightLanguageMap = rightLanguageMapList.get(i); assertEquals( leftLanguageMap.getLanguagePattern().pattern(), rightLanguageMap.getLanguagePattern().pattern()); LanguageRule leftLanguageRule = leftLanguageMap.getLanguageRule(); LanguageRule rightLanguageRule = rightLanguageMap.getLanguageRule(); assertEquals(leftLanguageRule.getName(), rightLanguageRule.getName()); List<Rule> leftRuleList = leftLanguageRule.getRuleList(); List<Rule> rightRuleList = rightLanguageRule.getRuleList(); assertEquals(leftRuleList.size(), rightRuleList.size()); for (int k = 0; k < leftRuleList.size(); ++k) { Rule leftRule = leftRuleList.get(k); Rule rightRule = rightRuleList.get(k); assertEquals(leftRule.isBreak(), rightRule.isBreak()); assertEquals(leftRule.getBeforePattern(), rightRule.getBeforePattern()); assertEquals(leftRule.getAfterPattern(), rightRule.getAfterPattern()); } } }
private void testSrx2Ticket1(SrxParser parser) { Reader reader = getReader(getResourceStream(TICKET_1_DOCUMENT_NAME)); SrxDocument document = parser.parse(reader); assertTrue(document.getCascade()); List<LanguageRule> languageRuleList = document.getLanguageRuleList("en"); LanguageRule languageRule = languageRuleList.get(0); assertEquals("Default", languageRule.getName()); List<Rule> ruleList = languageRule.getRuleList(); assertEquals(1, ruleList.size()); Rule rule = ruleList.get(0); assertEquals("[\\.!?…]['»\"”\\)\\]\\}]?\\u0002?\\s", rule.getBeforePattern()); assertEquals("", rule.getAfterPattern()); }
private void testSrx1(SrxParser parser) { Reader reader = getReader(getResourceStream(SRX_1_DOCUMENT_NAME)); SrxDocument document = parser.parse(reader); assertFalse(document.getCascade()); List<LanguageRule> languageRuleList = document.getLanguageRuleList("en"); assertEquals(1, languageRuleList.size()); LanguageRule languageRule = languageRuleList.get(0); assertEquals("Default", languageRule.getName()); List<Rule> ruleList = languageRule.getRuleList(); assertEquals(5, ruleList.size()); Rule rule = ruleList.get(1); assertEquals("[Ee][Tt][Cc]\\.", rule.getBeforePattern()); assertEquals("\\s[a-z]", rule.getAfterPattern()); }
private void testSrx2(SrxParser parser) { Reader reader = getReader(getResourceStream(SRX_2_DOCUMENT_NAME)); SrxDocument document = parser.parse(reader); assertTrue(document.getCascade()); List<LanguageRule> languageRuleList = document.getLanguageRuleList("fr_FR"); assertEquals(2, languageRuleList.size()); LanguageRule languageRule = languageRuleList.get(0); assertEquals("French", languageRule.getName()); List<Rule> ruleList = languageRule.getRuleList(); assertEquals(4, ruleList.size()); Rule rule0 = ruleList.get(0); assertEquals(" [Mm]lle\\.", rule0.getBeforePattern()); assertEquals("\\s", rule0.getAfterPattern()); Rule rule1 = ruleList.get(1); assertEquals("\\s[Mm]lles\\.", rule1.getBeforePattern()); assertEquals("\\s", rule1.getAfterPattern()); }