CpcClassification extends PatentClassification { @Override public void parseText(final String classificationStr) throws ParseException { Matcher matcher = REGEX.matcher(classificationStr); if (classificationStr.length() > 4 && matcher.matches()) { String section = matcher.group("section"); String mainClass = matcher.group("mainClass"); String subClass = matcher.group("subClass"); String mainGroup1 = matcher.group("mainGroup1"); String subGroup1 = matcher.group("subGroup1"); String[] mainGroup = null; String[] subGroup = null; String mainGroup2 = matcher.group("mainGroup2"); String subGroup2 = matcher.group("subGroup2"); String subGroup2SameMain = matcher.group("subGroup2SameMain"); if (mainGroup2 != null && !mainGroup2.equals(mainGroup1)) { mainGroup = new String[] { mainGroup1, mainGroup2 }; } else if (mainGroup2 == null && subGroup2 != null) { mainGroup = new String[] { mainGroup1, mainGroup1 }; } else { mainGroup = new String[] { mainGroup1 }; } if (subGroup2 != null) { subGroup = new String[] { subGroup1, subGroup2 }; } else if (subGroup2SameMain != null) { subGroup = new String[] { subGroup1, subGroup2SameMain }; } else { subGroup = new String[] { subGroup1 }; } setSection(section); setMainClass(mainClass); setSubClass(subClass); setMainGroup(mainGroup); setSubGroup(subGroup); return; } Matcher matchL3 = REGEX_LEN3.matcher(classificationStr); if (classificationStr.length() == 3 && matchL3.matches()) { String section = matchL3.group(1); String mainClass = matchL3.group(2); setSection(section); setMainClass(mainClass); return; } Matcher matchL4 = REGEX_LEN4.matcher(classificationStr); if (classificationStr.length() == 4 && matchL4.matches()) { String section = matchL4.group(1); String mainClass = matchL4.group(2); String subClass = matchL4.group(3); setSection(section); setMainClass(mainClass); setSubClass(subClass); return; } else { parseFailed = true; LOGGER.debug("CPC parse failed '{}'", classificationStr); throw new ParseException("Failed to regex parse CPC Classification: " + classificationStr, 0); } } CpcClassification(String originalText, boolean mainOrInventive); boolean isParseFailed(); @Override ClassificationType getType(); String getSection(); void setSection(String section); String getMainClass(); void setMainClass(String mainClass); String getSubClass(); void setSubClass(String subClass); String[] getMainGroup(); void setMainGroup(String[] mainGroup); String[] getSubGroup(); void setSubGroup(String[] subGroup); @Override String getTextNormalized(); @Override List<String> getSearchTokens(); String standardize(); @Override Tree getTree(); @Override int getDepth(); @Override boolean isContained(PatentClassification check); @Override boolean equals(Object obj); @Override void parseText(final String classificationStr); @Override boolean validate(); @Override String toString(); static Map<String, List<CpcClassification>> filterCpc(
			Collection<T> classes);  }
@Test(expected = ParseException.class) public void failBlank() throws ParseException { CpcClassification cpc = new CpcClassification("", false); cpc.parseText(""); }
@Test(expected = ParseException.class) public void failParseCheck() throws ParseException { CpcClassification cpc = new CpcClassification("A61F BAD", false); cpc.parseText("A61F BAD"); }