Sgml extends Dom4JParser { @Override public Patent parse(Document document) throws PatentReaderException { DocumentId publicationId = new DocumentIdNode(document).read(); PatentType patentType = PatentType.UNDEFINED; if (publicationId != null) { MDC.put("DOCID", publicationId.toText()); patentType = UsKindCode2PatentType.getInstance().lookupPatentType(publicationId.getKindCode()); } else { LOGGER.warn("Publication Id is Null: {}", document.toString()); } DocumentId applicationId = new ApplicationIdNode(document).read(); List<DocumentId> priorityIds = new PriorityClaimsNode(document).read(); List<DocumentId> pctRegionalIds = new PctRegionalIdNode(document).read(); List<DocumentId> relatedIds = new RelatedIdNode(document).read(); Node titleN = TITLEXP.selectSingleNode(document); String title = titleN != null ? titleN.getText() : null; Set<PatentClassification> classifications = new ClassificationNode(document).read(); Set<PatentClassification> searchClassifications = new ClassificationSearchNode(document).read(); List<Inventor> inventors = new InventorNode(document).read(); List<Assignee> assignees = new AssigneeNode(document).read(); List<Agent> agents = new AgentNode(document).read(); List<Examiner> examiners = new ExaminerNode(document).read(); List<Citation> citations = new CitationNode(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); List<DocumentId> provisionals = relatedIds.stream().filter(d -> DocumentIdType.PROVISIONAL.equals(d.getType())) .collect(Collectors.toList()); if (!provisionals.isEmpty()) { patent.addPriorityId(provisionals); } patent.addOtherId(patent.getApplicationId()); patent.addOtherId(patent.getPriorityIds()); patent.addRelationIds(patent.getOtherIds()); patent.setTitle(title); if (classifications != null) { patent.setClassification(classifications); } if (searchClassifications != null) { patent.setSearchClassification(searchClassifications); } patent.setInventor(inventors); patent.setAssignee(assignees); patent.setAgent(agents); patent.setExaminer(examiners); patent.setAbstract(abstractText); patent.setDescription(description); patent.setClaim(claims); patent.setCitation(citations); LOGGER.trace(patent.toString()); return patent; }  @Override Patent parse(Document document); static void main(String[] args);  }
@Test public void readSamples() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Sgml sgml = new Sgml(); for (File file : samplePath.toFile().listFiles()) { Patent patent = sgml.parse(file); ValidatePatent.validateGrant(patent); } }
@Test public void multipleAssignee() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Sgml sgml = new Sgml(); Path filePath = samplePath.resolve("USD435854S1.xml"); Patent patent = sgml.parse(filePath.toFile()); assertEquals("Multiple Assignees", 3, patent.getAssignee().size()); }
@Test public void multipleInventor() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Sgml sgml = new Sgml(); Path filePath = samplePath.resolve("US06337117.xml"); Patent patent = sgml.parse(filePath.toFile()); assertEquals("Multiple Inventors", 5, patent.getInventors().size()); }
@Test public void shouldExtractContinuationRelations() throws PatentReaderException, IOException { Sgml sgml = new Sgml(); Path filePath = samplePath.resolve("US06336130.xml"); Patent patent = sgml.parse(filePath.toFile()); List<String> continuationDocNumbers = patent.getRelationIds().stream() .filter(r -> r.getType() == DocumentIdType.CONTINUATION) .map(DocumentId::getDocNumber) .collect(Collectors.toList()); assertEquals("Continuations not extracted", 2, continuationDocNumbers.size()); assertTrue( "Continuation child missing from " + continuationDocNumbers, continuationDocNumbers.contains("9413215")); assertTrue( "Continuation parent missing from " + continuationDocNumbers, continuationDocNumbers.contains("PCTNO9800107")); }