Greenbook extends KvParser { @Override public Patent parse(Document document) throws PatentReaderException { DocumentId publicationId = new DocumentIdNode(document).read(); PatentType patentType = PatentType.UNDEFINED; if (publicationId != null) { patentType = new PatentTypeNode(document).read(); publicationId.setPatentType(patentType); if (CountryCode.US.equals(publicationId.getCountryCode())) { switch (patentType) { case UTILITY: publicationId.setKindCode("A"); break; case PLANT: publicationId.setKindCode("P"); break; case DESIGN: publicationId.setKindCode("S"); break; case REISSUE: publicationId.setKindCode("E"); break; case SIR: publicationId.setKindCode("H"); break; case DEF: publicationId.setKindCode("I4"); break; case UNDEFINED: LOGGER.warn("!!! Patent Type UNDEFINED : {}", publicationId.toText()); break; default: break; } } MDC.put("DOCID", publicationId.toText()); } DocumentId applicationId = new ApplicationIdNode(document).read(); Node titleN = TITLEXP.selectSingleNode(document); String title = titleN != null ? titleN.getText().trim() : null; List<Examiner> examiners = new ExaminerNode(document).read(); List<Inventor> inventors = new InventorNode(document).read(); List<Assignee> assignees = new AssigneeNode(document).read(); List<Agent> agents = new AgentNode(document).read(); Set<PatentClassification> classifications = new ClassificationNode(document).read(); Set<PatentClassification> searchClassifications = new ClassificationSearchNode(document).read(); List<DocumentId> priorityIds = new PriorityClaimNode(document).read(); List<DocumentId> relatedIds = new RelatedIdNode(document).read(); List<Citation> citations = new CitationNode(document).read(); List<DocumentId> pctRegionalIds = new PctRegionalIdNode(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 patent = new PatentGranted(publicationId, patentType); patent.setSource(getSource()); if (publicationId != null && publicationId.getDate() != null) { patent.setDatePublished(publicationId.getDate()); } if (applicationId != null && applicationId.getDate() != null) { patent.setDateProduced(applicationId.getDate()); } patent.setApplicationId(applicationId); patent.addPriorityId(priorityIds); patent.addOtherId(pctRegionalIds); patent.addRelationIds(relatedIds); patent.addOtherId(patent.getApplicationId()); patent.addOtherId(patent.getPriorityIds()); patent.addRelationIds(patent.getOtherIds()); patent.setTitle(title); patent.setInventor(inventors); patent.setAssignee(assignees); patent.setExaminer(examiners); patent.setAgent(agents); patent.setCitation(citations); patent.setClassification(classifications); patent.setSearchClassification(searchClassifications); patent.setAbstract(abstractText); patent.setDescription(description); patent.setClaim(claims); LOGGER.trace(patent.toString()); return patent; } Greenbook(); @Override Patent parse(Document document); static void main(String[] args); @Override Patent parse(Reader reader, Iterable<String> skipPaths);  }
@Test public void readSamples() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Greenbook greenbook = new Greenbook(); Path dirPath = Paths.get("resources/samples/greenbook"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "greenbook sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = greenbook.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }
@Test public void checkSamples() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Greenbook greenbook = new Greenbook(); Path dirPath = Paths.get("resources/samples/greenbook"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "greenbook sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = greenbook.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }