@Test public void testFind() throws Exception { String text = "ab"; List<String> data = Arrays.asList(text, "a c", "a d"); TreeWordList twl = new TreeWordList(data, false); JCas jcas = JCasFactory.createJCas(); jcas.setDocumentText(text); CAS cas = jcas.getCas(); RutaStream stream = createStream(text, cas); List<AnnotationFS> result1 = twl.find(stream, false, 0, null, 0, false); Assert.assertEquals(1, result1.size()); Assert.assertEquals(text, result1.get(0).getCoveredText()); List<AnnotationFS> result2 = twl.find(stream, false, 0, null, 0, true); Assert.assertEquals(1, result2.size()); Assert.assertEquals(text, result2.get(0).getCoveredText()); List<AnnotationFS> result3 = twl.find(stream, true, 0, null, 0, false); Assert.assertEquals(1, result3.size()); Assert.assertEquals(text, result3.get(0).getCoveredText()); }
@Override public List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>(); stream.moveToFirst(); RutaStream streamPointer = stream.copy(); while (stream.isValid()) { RutaBasic anchorBasic = (RutaBasic) stream.get(); streamPointer.moveTo(anchorBasic); List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>(); basicsToAdd.add(anchorBasic); String text = anchorBasic.getCoveredText(); StringBuilder candidate = new StringBuilder(text); Annotation interResult = null; while (streamPointer.isValid()) { if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { streamPointer.moveToNext(); if (streamPointer.isValid()) { RutaBasic next = (RutaBasic) streamPointer.get(); if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(basicsToAdd.size() - 1).getEnd()); } candidate.append(next.getCoveredText()); basicsToAdd.add(next); } else { tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); } } else { basicsToAdd.remove(basicsToAdd.size() - 1); tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); break; } } stream.moveToNext(); } return results; }
TreeWordList implements RutaWordList { @Override public List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>(); stream.moveToFirst(); RutaStream streamPointer = stream.copy(); while (stream.isValid()) { RutaBasic anchorBasic = (RutaBasic) stream.get(); streamPointer.moveTo(anchorBasic); List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>(); basicsToAdd.add(anchorBasic); String text = anchorBasic.getCoveredText(); StringBuilder candidate = new StringBuilder(text); Annotation interResult = null; while (streamPointer.isValid()) { if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { streamPointer.moveToNext(); if (streamPointer.isValid()) { RutaBasic next = (RutaBasic) streamPointer.get(); if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(basicsToAdd.size() - 1).getEnd()); } candidate.append(next.getCoveredText()); basicsToAdd.add(next); } else { tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); } } else { basicsToAdd.remove(basicsToAdd.size() - 1); tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); break; } } stream.moveToNext(); } return results; } }
TreeWordList implements RutaWordList { @Override public List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>(); stream.moveToFirst(); RutaStream streamPointer = stream.copy(); while (stream.isValid()) { RutaBasic anchorBasic = (RutaBasic) stream.get(); streamPointer.moveTo(anchorBasic); List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>(); basicsToAdd.add(anchorBasic); String text = anchorBasic.getCoveredText(); StringBuilder candidate = new StringBuilder(text); Annotation interResult = null; while (streamPointer.isValid()) { if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { streamPointer.moveToNext(); if (streamPointer.isValid()) { RutaBasic next = (RutaBasic) streamPointer.get(); if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(basicsToAdd.size() - 1).getEnd()); } candidate.append(next.getCoveredText()); basicsToAdd.add(next); } else { tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); } } else { basicsToAdd.remove(basicsToAdd.size() - 1); tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); break; } } stream.moveToNext(); } return results; } TreeWordList();  TreeWordList(Resource resource, boolean dictRemoveWS);  TreeWordList(String pathname, boolean dictRemoveWS);  TreeWordList(InputStream stream, String name, boolean dictRemoveWS);  TreeWordList(List<String> data, boolean dictRemoveWS); }
TreeWordList implements RutaWordList { @Override public List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>(); stream.moveToFirst(); RutaStream streamPointer = stream.copy(); while (stream.isValid()) { RutaBasic anchorBasic = (RutaBasic) stream.get(); streamPointer.moveTo(anchorBasic); List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>(); basicsToAdd.add(anchorBasic); String text = anchorBasic.getCoveredText(); StringBuilder candidate = new StringBuilder(text); Annotation interResult = null; while (streamPointer.isValid()) { if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { streamPointer.moveToNext(); if (streamPointer.isValid()) { RutaBasic next = (RutaBasic) streamPointer.get(); if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(basicsToAdd.size() - 1).getEnd()); } candidate.append(next.getCoveredText()); basicsToAdd.add(next); } else { tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); } } else { basicsToAdd.remove(basicsToAdd.size() - 1); tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); break; } } stream.moveToNext(); } return results; } TreeWordList();  TreeWordList(Resource resource, boolean dictRemoveWS);  TreeWordList(String pathname, boolean dictRemoveWS);  TreeWordList(InputStream stream, String name, boolean dictRemoveWS);  TreeWordList(List<String> data, boolean dictRemoveWS); void buildNewTree(List<String> data); void buildNewTree(InputStream stream); TextNode getRoot(); void addWord(String s); @Override boolean contains(String s, boolean ignoreCase, int size, char[] ignoreChars,
          int maxIgnoreChars, boolean ignoreWS); @Override boolean containsFragment(String s, boolean ignoreCase, int size, char[] ignoreChars,
          int maxIgnoreChars, boolean ignoreWS); @Override List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size,
          char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS); List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size,
          boolean ignoreWS); void readXML(InputStream stream, String encoding); void createTWLFile(String path, String encoding); void createTWLFile(String path, boolean compressed, String encoding); void createTWLFile(TextNode root, String path, boolean compressed, String encoding); void writeNode(Writer writer, TextNode node); @Override String toString(); @Override List<AnnotationFS> find(RutaStream stream, Map<String, Object> typeMap, boolean ignoreCase,
          int ignoreLength, boolean edit, double distance, String ignoreToken); @Override List<String> contains(String string, boolean ignoreCase, int ignoreLength, boolean edit,
          double distance, String ignoreToken); @Override List<String> containsFragment(String string, boolean ignoreCase, int ignoreLength,
          boolean edit, double distance, String ignoreToken); void startDocument(); void endDocument(); }
TreeWordList implements RutaWordList { @Override public List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) { ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>(); stream.moveToFirst(); RutaStream streamPointer = stream.copy(); while (stream.isValid()) { RutaBasic anchorBasic = (RutaBasic) stream.get(); streamPointer.moveTo(anchorBasic); List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>(); basicsToAdd.add(anchorBasic); String text = anchorBasic.getCoveredText(); StringBuilder candidate = new StringBuilder(text); Annotation interResult = null; while (streamPointer.isValid()) { if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { streamPointer.moveToNext(); if (streamPointer.isValid()) { RutaBasic next = (RutaBasic) streamPointer.get(); if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) { interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(basicsToAdd.size() - 1).getEnd()); } candidate.append(next.getCoveredText()); basicsToAdd.add(next); } else { tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); } } else { basicsToAdd.remove(basicsToAdd.size() - 1); tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd, candidate.toString(), interResult, ignoreChars, maxIgnoredChars, ignoreWS); break; } } stream.moveToNext(); } return results; } TreeWordList();  TreeWordList(Resource resource, boolean dictRemoveWS);  TreeWordList(String pathname, boolean dictRemoveWS);  TreeWordList(InputStream stream, String name, boolean dictRemoveWS);  TreeWordList(List<String> data, boolean dictRemoveWS); void buildNewTree(List<String> data); void buildNewTree(InputStream stream); TextNode getRoot(); void addWord(String s); @Override boolean contains(String s, boolean ignoreCase, int size, char[] ignoreChars,
          int maxIgnoreChars, boolean ignoreWS); @Override boolean containsFragment(String s, boolean ignoreCase, int size, char[] ignoreChars,
          int maxIgnoreChars, boolean ignoreWS); @Override List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size,
          char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS); List<AnnotationFS> find(RutaStream stream, boolean ignoreCase, int size,
          boolean ignoreWS); void readXML(InputStream stream, String encoding); void createTWLFile(String path, String encoding); void createTWLFile(String path, boolean compressed, String encoding); void createTWLFile(TextNode root, String path, boolean compressed, String encoding); void writeNode(Writer writer, TextNode node); @Override String toString(); @Override List<AnnotationFS> find(RutaStream stream, Map<String, Object> typeMap, boolean ignoreCase,
          int ignoreLength, boolean edit, double distance, String ignoreToken); @Override List<String> contains(String string, boolean ignoreCase, int ignoreLength, boolean edit,
          double distance, String ignoreToken); @Override List<String> containsFragment(String string, boolean ignoreCase, int ignoreLength,
          boolean edit, double distance, String ignoreToken); void startDocument(); void endDocument();  }