GrantParser extends Dom4JParser { @Override public Patent parse(Document document) { DocumentId publicationId = new PublicationIdNode(document).read(); if (publicationId != null) { MDC.put("DOCID", publicationId.toText()); } else { LOGGER.warn("Publication ID not read!"); } String title = Dom4jUtil.getTextOrNull(document, TITLEXP); String dateProduced = Dom4jUtil.getTextOrNull(document, PRODDATEXP); String datePublished = Dom4jUtil.getTextOrNull(document, PUBDATEXP); DocumentDate dateProducedDate = null; if (dateProduced != null) { try { dateProducedDate = new DocumentDate(dateProduced); } catch (InvalidDataException e) { LOGGER.warn("{} : {}", e.getMessage(), "dateProduced"); } } DocumentDate datePublishedDate = null; if (datePublished != null) { try { datePublishedDate = new DocumentDate(datePublished); } catch (InvalidDataException e) { LOGGER.warn("{} : {}", e.getMessage(), "datePublished"); } } String patentTypeStr = Dom4jUtil.getTextOrNull(document, APPTYPEXP); PatentType patentType = PatentType.UNDEFINED; try { patentType = PatentType.fromString(patentTypeStr); } catch (InvalidDataException e1) { LOGGER.warn("{} : {}", e1.getMessage(), "patentTypeStr"); } DocumentId applicationId = new ApplicationIdNode(document).read(); List<DocumentId> priorityIds = new PriorityClaims(document).read(); List<DocumentId> pctRegionalIds = new PctRegionalIdNode(document).read(); DocumentId relatedId = new RelatedIdNode(document).read(); List<DocumentId> relationIds = new Relations(document).read(); List<Inventor> inventors = new InventorNode(document).read(); List<Applicant> applicants = new ApplicantNode(document).read(); List<Agent> agents = new AgentNode(document).read(); List<Examiner> examiners = new ExaminerNode(document).read(); List<Assignee> assignees = new AssigneeNode(document).read(); List<Citation> citations = new CitationNode(document).read(); Set<PatentClassification> classifications = new ClassificationNode(document).read(); Set<PatentClassification> searchClassifications = new ClassificationSearchNode(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(); PatentGranted patent = new PatentGranted(publicationId, patentType); patent.setSource(getSource()); patent.setDateProduced(dateProducedDate); patent.setDatePublished(datePublishedDate); patent.setDocumentId(publicationId); if (publicationId != null) { DocumentId docIdWithoutKind = new DocumentId(publicationId.getCountryCode(), publicationId.getDocNumber()); docIdWithoutKind.setType(DocumentIdType.PUBLISHED); docIdWithoutKind.setDate(publicationId.getDate()); patent.addOtherId(docIdWithoutKind); } patent.setApplicationId(applicationId); patent.addPriorityId(priorityIds); patent.addOtherId(pctRegionalIds); patent.addRelationIds(relationIds); patent.addOtherId(patent.getApplicationId()); patent.addOtherId(patent.getPriorityIds()); patent.addRelationIds(patent.getOtherIds()); patent.setTitle(title); patent.setAbstract(abstractText); patent.setDescription(description); patent.setExaminer(examiners); patent.setAssignee(assignees); patent.setInventor(inventors); patent.setApplicant(applicants); patent.setAgent(agents); if (citations != null) { patent.setCitation(citations); } else { LOGGER.warn("Patent Grant did not read any citations: {}", patent.getDocumentId().toText()); } patent.setClaim(claims); patent.setClassification(classifications); patent.setSearchClassification(searchClassifications); LOGGER.trace(patent.toString()); return patent; }  @Override Patent parse(Document document); static final String XML_ROOT; }
@Test public void readSamples2004() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { GrantParser xmlGrant = new GrantParser(); Path dirPath = Paths.get("resources/samples/xml2004"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "XML Grant 2004 sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = xmlGrant.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }
@Test public void readSamples2014() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { GrantParser xmlGrant = new GrantParser(); Path dirPath = Paths.get("resources/samples/xml2014"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "XML Grant 2014 sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = xmlGrant.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }