ReferenceExtractor implements Closeable { public String extractAllReferencesXMLFile(String pathXML, boolean filterDuplicate, int consolidate, boolean includeRawCitations, List<PatentItem> patents, List<BibDataSet> articles) { try { if (patents == null) { System.out.println("Warning patents List is null!"); } TextSaxParser sax = new TextSaxParser(); sax.setFilter("description"); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setFeature("http: spf.setFeature("http: XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { return new InputSource( new ByteArrayInputStream("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes())); } }); reader.setContentHandler(sax); InputSource input = null; if (pathXML.endsWith(".gz")) { InputStream dataInputStream = new FileInputStream(pathXML); GZIPInputStream gzip = new GZIPInputStream(dataInputStream); DataInputStream tmp = new DataInputStream(gzip); dataInputStream = tmp; input = new InputSource(dataInputStream); } else { input = new InputSource(pathXML); } input.setEncoding("UTF-8"); reader.parse(input); description = sax.getText(); currentPatentNumber = sax.currentPatentNumber; consolidate = 0; filterDuplicate = true; if (description != null) { return extractAllReferencesString(description, filterDuplicate, consolidate, includeRawCitations, patents, articles); } else return null; } catch (Exception e) { e.printStackTrace(); } return null; } ReferenceExtractor();  ReferenceExtractor(EngineParsers parsers); void setDocumentPath(String dirName); String extractAllReferencesOPS(boolean filterDuplicate,
                                       int consolidate,
                                       boolean includeRawCitations,
                                       List<PatentItem> patents,
                                       List<BibDataSet> articles); String extractPatentReferencesXMLFile(String pathXML,
                                              boolean filterDuplicate,
                                              int consolidate,
                                              boolean includeRawCitations,
                                              List<PatentItem> patents); String extractAllReferencesXMLFile(String pathXML,
                                           boolean filterDuplicate,
                                           int consolidate,
                                           boolean includeRawCitations,
                                           List<PatentItem> patents,
                                           List<BibDataSet> articles); String extractAllReferencesPDFFile(String inputFile,
                                           boolean filterDuplicate,
                                           int consolidate,
                                           boolean includeRawCitations,
                                           List<PatentItem> patents,
                                           List<BibDataSet> articles); String annotateAllReferencesPDFFile(String inputFile,
                                           boolean filterDuplicate,
                                           int consolidate,
                                           boolean includeRawCitations,
                                           List<PatentItem> patents,
                                           List<BibDataSet> articles); String extractAllReferencesString(String text,
                                          boolean filterDuplicate,
                                          int consolidate,
                                          boolean includeRawCitations,
                                          List<PatentItem> patents,
                                          List<BibDataSet> articles); String annotateAllReferences(Document doc,
										List<LayoutToken> tokenizations,
                                        boolean filterDuplicate,
                                        int consolidate,
                                        boolean includeRawCitations,
                                        List<PatentItem> patents,
                                        List<BibDataSet> articles); String references2TEI2(); String reference2TEI(int i); String references2BibTeX(); String references2TEI(); String reference2BibTeX(int i); void generateTrainingData(String documentPath, String newTrainingPath); boolean getDocOPS(String number); void generateXMLReport(File file,
                                  ArrayList<PatentItem> patents,
                                  ArrayList<BibDataSet> articles); @Override void close(); public boolean debug; public Lexicon lexicon; public String currentPatentNumber; public OPSService ops; public ArrayList<org.grobid.core.data.BibDataSet> resBib; }
@Test public void extractAllReferencesXmlST36() { ReferenceExtractor extractor = new ReferenceExtractor(); List<PatentItem> patents = new ArrayList<PatentItem>(); List<BibDataSet> articles = new ArrayList<BibDataSet>(); extractor .extractAllReferencesXMLFile( new File( "src/test/resources/org/grobid/core/engines/patent/ReferenceExtractor/st36-sample-1.xml") .getAbsolutePath(), false, 0, false, patents, articles); LOGGER.info("PatentItem: " + patents.toString()); assertEquals(2, patents.size()); assertEquals(0, articles.size()); assertEquals("9937368", patents.get(0).getNumberEpoDoc()); assertEquals("6083121", patents.get(1).getNumberEpoDoc()); }
@Test public void extractAllReferencesXml() { ReferenceExtractor extractor = new ReferenceExtractor(); List<PatentItem> patents = new ArrayList<PatentItem>(); List<BibDataSet> articles = new ArrayList<BibDataSet>(); extractor .extractAllReferencesXMLFile( new File( "src/test/resources/patents/006271747.xml") .getAbsolutePath(), false, 0, false, patents, articles); assertEquals("20050675311", patents.get(0).getNumberEpoDoc()); assertEquals("9202190", patents.get(1).getNumberEpoDoc()); }