@Test public void testExtractFromDocumentWithAllFieldsSet() throws Exception { String title = "some title"; String abstractText = "some abstract"; String classIpcText = "some class IPC text"; String applnEpodocId = "1234"; String applnDate = "20200501"; String publnDate = "20000530"; List<String> epodocApplicantNames = Lists.newArrayList("John Smith [PL]"); String xmlContents = buildXMLContents(title, abstractText, classIpcText, applnEpodocId, applnDate, publnDate, epodocApplicantNames); Patent.Builder patentBuilder = parser.parse(xmlContents, getPatentBuilderInitializedWithRequiredFields()); Patent patent = patentBuilder.build(); assertNotNull(patent); assertEquals(title, patent.getApplnTitle()); assertNotNull(patent.getApplnAbstract()); assertEquals(abstractText, patent.getApplnAbstract()); assertNotNull(patent.getIpcClassSymbol()); assertEquals(1, patent.getIpcClassSymbol().size()); assertEquals(classIpcText, patent.getIpcClassSymbol().get(0)); assertEquals(applnEpodocId, patent.getApplnNrEpodoc()); assertEquals("2020-05-01", patent.getApplnFilingDate()); assertEquals("2000-05-30", patent.getEarliestPublnDate()); assertNotNull(patent.getApplicantNames()); assertEquals(1, patent.getApplicantNames().size()); assertEquals("John Smith", patent.getApplicantNames().get(0)); assertNotNull(patent.getApplicantCountryCodes()); assertEquals(1, patent.getApplicantCountryCodes().size()); assertEquals("PL", patent.getApplicantCountryCodes().get(0)); }
@Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); @Override Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder); }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); @Override Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder);  }