DescriptionFigures extends ItemReader<List<Figure>> { public static void findFigures(String pargraphText, List<Figure> figureList) { Figure figure = null; int figEnd = 0; String figText = ""; Matcher matchFig = PATENT_FIG.matcher(pargraphText); if (matchFig.lookingAt()) { String id = matchFig.group(1); if (!id.equals(pargraphText)) { figEnd = matchFig.end(); figText = pargraphText.substring(figEnd + 1); figure = new Figure(figText, id); } } else { Matcher matchFigs = PATENT_FIGS.matcher(pargraphText); if (matchFigs.lookingAt()) { String id = matchFigs.group(1); if (!id.equals(pargraphText)) { figEnd = matchFigs.end(); figText = pargraphText.substring(figEnd + 1); Figure fig = new Figure(figText, id); figureList.add(fig); } } else { if (pargraphText.matches("^FIG")) { LOGGER.warn("Unable to Parse Patent Figure ID: '" + pargraphText); } else { LOGGER.trace("2. Unable to Parse Patent Figure ID: '" + pargraphText); } } } if (figure != null) { figureList.add(figure); } } DescriptionFigures(Node itemNode); @Override List<Figure> read(); static void findFigures(String pargraphText, List<Figure> figureList);  }
@Test public void extractFigDesc1() { String pargraphText = "FIG. 1 is a partial perspective view of a person wearing a suitcoat."; List<Figure> figures = new ArrayList<Figure>(); DescriptionFigures.findFigures(pargraphText, figures); Figure fig1 = figures.get(0); Set<String> ids = fig1.getIds(); String fig1Text = fig1.getRawText(); assertEquals("FIG. 1", ids.iterator().next()); assertEquals("is a partial perspective view of a person wearing a suitcoat.", fig1Text); }
@Test public void extractFigDesc2() { String pargraphText = "Image 1 is a partial perspective view of a person wearing a suitcoat."; List<Figure> figures = new ArrayList<Figure>(); DescriptionFigures.findFigures(pargraphText, figures); assertTrue(figures.isEmpty()); }
@Test public void extractFigDesc3() { String pargraphText = ""; List<Figure> figures = new ArrayList<Figure>(); DescriptionFigures.findFigures(pargraphText, figures); assertTrue(figures.isEmpty()); }
@Test public void extractFigDesc4() { String pargraphText = "FIG. 1"; List<Figure> figures = new ArrayList<Figure>(); DescriptionFigures.findFigures(pargraphText, figures); assertTrue(figures.isEmpty()); }
@Test public void mentionalAnother() { String pargraphText = "FIG. 3 is a cross-sectional view similar to that shown in FIG. 2 wherein the"; List<Figure> figures = new ArrayList<Figure>(); DescriptionFigures.findFigures(pargraphText, figures); Figure fig1 = figures.get(0); Set<String> ids = fig1.getIds(); String fig1Text = fig1.getRawText(); assertEquals("FIG. 3", ids.iterator().next()); assertEquals("is a cross-sectional view similar to that shown in FIG. 2 wherein the", fig1Text); }