PatentAppPubParser extends Dom4JParser { @Override public Patent parse(Document document) { DocumentId publicationId = new PublicationIdNode(document).read(); DocumentId applicationId = new ApplicationIdNode(document).read(); if (CountryCode.UNDEFINED.equals(publicationId.getCountryCode())) { publicationId = new DocumentId(applicationId.getCountryCode(), publicationId.getDocNumber(), publicationId.getKindCode()); } if (publicationId != null) { MDC.put("DOCID", publicationId.toText()); } String title = Dom4jUtil.getTextOrNull(document, TITLE_XP); String dateProduced = Dom4jUtil.getTextOrNull(document, FILING_DATE_XP); String patentTypeStr = Dom4jUtil.getTextOrEmpty(document, PAT_TYPE_XP).replaceFirst("^new-", ""); PatentType patentType = null; try { patentType = PatentType.fromString(patentTypeStr); } catch (InvalidDataException e1) { patentType = UsKindCode2PatentType.getInstance().lookupPatentType(publicationId.getKindCode()); } List<DocumentId> priorityIds = new PriorityClaimNode(document).read(); List<DocumentId> relatedIds = new RelatedIdNode(document).read(); List<Inventor> inventors = new InventorNode(document).read(); List<Applicant> applicants = new ApplicantNode(document).read(); List<Agent> agents = new AgentNode(document).read(); Set<PatentClassification> classifications = new ClassificationNode(document).read(); FormattedText textProcessor = new FormattedText(); Abstract abstractText = new AbstractTextNode(document, textProcessor).read(); Description description = new DescriptionNode(document, textProcessor).read(); List<Claim> claims = new ClaimNode(document, textProcessor).read(); new ClaimTreeBuilder(claims).build(); patent = new PatentApplication(publicationId, patentType); patent.setSource(getSource()); patent.setApplicationId(applicationId); patent.addPriorityId(priorityIds); patent.addRelationIds(relatedIds); patent.addOtherId(patent.getApplicationId()); patent.addOtherId(patent.getPriorityIds()); patent.addRelationIds(patent.getOtherIds()); patent.setTitle(title); patent.setAbstract(abstractText); patent.setDescription(description); patent.setInventor(inventors); patent.setApplicant(applicants); patent.setAgent(agents); patent.setClaim(claims); patent.setClassification(classifications); if (dateProduced != null) { try { patent.setDateProduced(dateProduced); } catch (InvalidDataException e) { LOGGER.warn("{} : {}", e.getMessage(), "dateProduced"); } } if (publicationId != null) { patent.setDatePublished(publicationId.getDate()); } LOGGER.trace(patent.toString()); return patent; }  @Override Patent parse(Document document); static void main(String[] args); static final String XML_ROOT; }
@Test public void readSamples() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PatentValidationError { PatentAppPubParser pap = new PatentAppPubParser(); Path dirPath = Paths.get("resources/samples/pap"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "PAP sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = pap.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }
@Test public void validateSamples() throws PatentReaderException, IOException, PatentValidationError { PatentAppPubParser pap = new PatentAppPubParser(); Path dirPath = Paths.get("resources/samples/pap"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "PAP sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = pap.parse(file); try { PatentValidator.allRules().verify(patent); } catch (PatentValidationError e) { System.err.println(patent.getDocumentId().toText() + " : " + e.getMessage()); throw e; } } }