UspcClassification extends PatentClassification { @Override public void parseText(final String classificationStr) throws ParseException { String input = classificationStr.toUpperCase().replace(' ', '0').replaceAll("(DIG|FOR)0", "$1"); Matcher rangeMatcher = SUBGROUP_RANGE.matcher(input); String subClassRangLmt = null; if (rangeMatcher.find()) { input = input.substring(0, rangeMatcher.start()); subClassRangLmt = rangeMatcher.group(1); subClassRangLmt = subClassRangLmt.replaceFirst("^0+", ""); String subClassIndent = rangeMatcher.group(2); if (subClassIndent != null) { if ("FOR".equals(subClass) || "DIG".equals(subClass)) { subClassRangLmt += " " + subClassIndent.replaceFirst("^0+", "").replaceFirst("0([A-Z]{1,2})$", "$1"); } else if (subClassIndent.matches("^0[A-Z]{1,2}$")) { subClassRangLmt += subClassIndent.replaceFirst("^0", ""); } else if (subClassIndent.startsWith(".")) { subClassRangLmt += subClassIndent.replaceFirst("000", ""); } else if (subClassIndent.matches("^\\d+(0[A-Z]{1,2})?$")) { subClassRangLmt += "." + subClassIndent.replaceFirst("0([A-Z]{1,2})$", "$1"); } else { subClassRangLmt += subClassIndent; } } } Matcher matcher = REGEX.matcher(input); if (matcher.matches()) { String mainClass = matcher.group("mainClass"); mainClass = mainClass.replaceFirst("^0+", ""); mainClass = mainClass.replaceFirst("^D0", "D"); setMainClass(mainClass); String subClass = matcher.group("subClass"); String subClassIndent = matcher.group("subClassIndent"); subClass = subClass.replaceFirst("^0+", ""); if ("000".equals(subClassIndent)) { subClassIndent = ""; } LOGGER.trace( input + " --> main(" + mainClass + ") sub(" + subClass + ") indent(" + subClassIndent + ")"); if (subClassIndent != null) { if ("FOR".equals(subClass) || "DIG".equals(subClass)) { subClass += " " + subClassIndent.replaceFirst("^0+", "").replaceFirst("0([A-Z]{1,2})$", "$1"); } else if (subClassIndent.matches("^0[A-Z]{1,2}$")) { subClass += subClassIndent.replaceFirst("^0", ""); } else if (subClassIndent.startsWith(".")) { subClass += subClassIndent.replaceFirst("000", ""); } else if (subClassIndent.matches("^\\d+(0[A-Z]{1,2})?$")) { subClass += "." + subClassIndent.replaceFirst("0([A-Z]{1,2})$", "$1"); } else { subClass += subClassIndent; } } String[] subClassRange; if (subClassRangLmt != null) { subClassRange = new String[] { subClass, subClassRangLmt }; } else { subClassRange = new String[] { subClass }; } setSubClass(subClassRange); return; } parseFailed = true; LOGGER.debug("USPC parse failed '{}' as '{}'", classificationStr, input); throw new ParseException( "Failed to regex parse USPC Classification: '" + classificationStr + "' evaluated as: '" + input + "'", 0); } UspcClassification(String originalText, boolean mainOrInventive); boolean isParseFailed(); @Override ClassificationType getType(); void setMainClass(String mainClass); String getMainClass(); String[] getSubClass(); void setSubClass(String subClass); void setSubClass(String[] subClass); @Override String getTextNormalized(); List<String> getSearchTokens(); int getDepth(); Tree getTree(); @Override void parseText(final String classificationStr); @Override boolean validate(); @Override boolean isContained(PatentClassification check); @Override String toString();  }
@Test(expected = ParseException.class) public void failBlank() throws ParseException { UspcClassification uspc = new UspcClassification("", false); uspc.parseText(""); }