@Test public void testOneWord() { final String WORD = "gravida"; int woff = DOC.indexOf(WORD); assertTrue(WORD, woff >= 0); Passage p = new Passage(); p.setStartOffset(woff); p.setEndOffset(woff + WORD.length()); p.addMatch(woff, p.getEndOffset(), new BytesRef(WORD),1); assertEquals("getNumMatches()", 1, p.getNumMatches()); PassageConverter cvt = getConverter((short)0); SortedMap<Integer, LineHighlight> linemap = cvt.convert(new Passage[] {p}, splitter); assertEquals("linemap size()", 1, linemap.size()); int lineno = linemap.firstKey(); assertEquals("lineno", 2, lineno); LineHighlight lhi = linemap.get(lineno); assertNotNull("get LineHighlight", lhi); assertEquals("getLelide()", 0, lhi.getLelide()); assertEquals("getRelide()", 0, lhi.getRelide()); assertEquals("countMarkups()", 1, lhi.countMarkups()); PhraseHighlight phi = lhi.getMarkup(0); assertNotNull("get PhraseHighlight", phi); assertEquals("getLineStart()", 32, phi.getLineStart()); assertEquals("getLineEnd()", 32 + WORD.length(), phi.getLineEnd()); }
public SortedMap<Integer, LineHighlight> convert(Passage[] passages, SourceSplitter splitter) { SortedMap<Integer, LineHighlight> res = new TreeMap<>(); for (Passage passage : passages) { int start = passage.getStartOffset(); int end = passage.getEndOffset(); if (start >= end) { continue; } int m = splitter.findLineIndex(start); if (m < 0) { continue; } int n = splitter.findLineIndex(end - 1); if (n < 0) { continue; } m = Math.max(0, m - args.getContextSurround()); n = Math.min(splitter.count() - 1, n + args.getContextSurround()); for (int i = m; i <= n; ++i) { if (!res.containsKey(i)) { res.put(i, new LineHighlight(i)); } } for (int i = 0; i < passage.getNumMatches(); ++i) { int mstart = passage.getMatchStarts()[i]; int mm = splitter.findLineIndex(mstart); int mend = passage.getMatchEnds()[i]; int nn = splitter.findLineIndex(mend - 1); if (mstart < mend && mm >= m && mm <= n && nn >= m && nn <= n) { if (mm == nn) { int lbeg = splitter.getOffset(mm); int lstart = mstart - lbeg; int lend = mend - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.create(lstart, lend)); } else { int lbeg = splitter.getOffset(mm); int loff = mstart - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.createStarter(loff)); lbeg = splitter.getOffset(nn); loff = mend - lbeg; lhigh = res.get(nn); lhigh.addMarkup(PhraseHighlight.createEnder(loff)); for (int j = mm + 1; j <= nn - 1; ++j) { lhigh = res.get(j); lhigh.addMarkup(PhraseHighlight.createEntire()); } } } } } for (LineHighlight lhi : res.values()) { lhi.condenseMarkups(); String line = splitter.getLine(lhi.getLineno()); Matcher eolMatcher = StringUtils.STANDARD_EOL.matcher(line); if (eolMatcher.find()) { line = line.substring(0, eolMatcher.start()); } elideLine(lhi, line); } return res; }
PassageConverter { public SortedMap<Integer, LineHighlight> convert(Passage[] passages, SourceSplitter splitter) { SortedMap<Integer, LineHighlight> res = new TreeMap<>(); for (Passage passage : passages) { int start = passage.getStartOffset(); int end = passage.getEndOffset(); if (start >= end) { continue; } int m = splitter.findLineIndex(start); if (m < 0) { continue; } int n = splitter.findLineIndex(end - 1); if (n < 0) { continue; } m = Math.max(0, m - args.getContextSurround()); n = Math.min(splitter.count() - 1, n + args.getContextSurround()); for (int i = m; i <= n; ++i) { if (!res.containsKey(i)) { res.put(i, new LineHighlight(i)); } } for (int i = 0; i < passage.getNumMatches(); ++i) { int mstart = passage.getMatchStarts()[i]; int mm = splitter.findLineIndex(mstart); int mend = passage.getMatchEnds()[i]; int nn = splitter.findLineIndex(mend - 1); if (mstart < mend && mm >= m && mm <= n && nn >= m && nn <= n) { if (mm == nn) { int lbeg = splitter.getOffset(mm); int lstart = mstart - lbeg; int lend = mend - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.create(lstart, lend)); } else { int lbeg = splitter.getOffset(mm); int loff = mstart - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.createStarter(loff)); lbeg = splitter.getOffset(nn); loff = mend - lbeg; lhigh = res.get(nn); lhigh.addMarkup(PhraseHighlight.createEnder(loff)); for (int j = mm + 1; j <= nn - 1; ++j) { lhigh = res.get(j); lhigh.addMarkup(PhraseHighlight.createEntire()); } } } } } for (LineHighlight lhi : res.values()) { lhi.condenseMarkups(); String line = splitter.getLine(lhi.getLineno()); Matcher eolMatcher = StringUtils.STANDARD_EOL.matcher(line); if (eolMatcher.find()) { line = line.substring(0, eolMatcher.start()); } elideLine(lhi, line); } return res; } }
PassageConverter { public SortedMap<Integer, LineHighlight> convert(Passage[] passages, SourceSplitter splitter) { SortedMap<Integer, LineHighlight> res = new TreeMap<>(); for (Passage passage : passages) { int start = passage.getStartOffset(); int end = passage.getEndOffset(); if (start >= end) { continue; } int m = splitter.findLineIndex(start); if (m < 0) { continue; } int n = splitter.findLineIndex(end - 1); if (n < 0) { continue; } m = Math.max(0, m - args.getContextSurround()); n = Math.min(splitter.count() - 1, n + args.getContextSurround()); for (int i = m; i <= n; ++i) { if (!res.containsKey(i)) { res.put(i, new LineHighlight(i)); } } for (int i = 0; i < passage.getNumMatches(); ++i) { int mstart = passage.getMatchStarts()[i]; int mm = splitter.findLineIndex(mstart); int mend = passage.getMatchEnds()[i]; int nn = splitter.findLineIndex(mend - 1); if (mstart < mend && mm >= m && mm <= n && nn >= m && nn <= n) { if (mm == nn) { int lbeg = splitter.getOffset(mm); int lstart = mstart - lbeg; int lend = mend - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.create(lstart, lend)); } else { int lbeg = splitter.getOffset(mm); int loff = mstart - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.createStarter(loff)); lbeg = splitter.getOffset(nn); loff = mend - lbeg; lhigh = res.get(nn); lhigh.addMarkup(PhraseHighlight.createEnder(loff)); for (int j = mm + 1; j <= nn - 1; ++j) { lhigh = res.get(j); lhigh.addMarkup(PhraseHighlight.createEntire()); } } } } } for (LineHighlight lhi : res.values()) { lhi.condenseMarkups(); String line = splitter.getLine(lhi.getLineno()); Matcher eolMatcher = StringUtils.STANDARD_EOL.matcher(line); if (eolMatcher.find()) { line = line.substring(0, eolMatcher.start()); } elideLine(lhi, line); } return res; } PassageConverter(ContextArgs args); }
PassageConverter { public SortedMap<Integer, LineHighlight> convert(Passage[] passages, SourceSplitter splitter) { SortedMap<Integer, LineHighlight> res = new TreeMap<>(); for (Passage passage : passages) { int start = passage.getStartOffset(); int end = passage.getEndOffset(); if (start >= end) { continue; } int m = splitter.findLineIndex(start); if (m < 0) { continue; } int n = splitter.findLineIndex(end - 1); if (n < 0) { continue; } m = Math.max(0, m - args.getContextSurround()); n = Math.min(splitter.count() - 1, n + args.getContextSurround()); for (int i = m; i <= n; ++i) { if (!res.containsKey(i)) { res.put(i, new LineHighlight(i)); } } for (int i = 0; i < passage.getNumMatches(); ++i) { int mstart = passage.getMatchStarts()[i]; int mm = splitter.findLineIndex(mstart); int mend = passage.getMatchEnds()[i]; int nn = splitter.findLineIndex(mend - 1); if (mstart < mend && mm >= m && mm <= n && nn >= m && nn <= n) { if (mm == nn) { int lbeg = splitter.getOffset(mm); int lstart = mstart - lbeg; int lend = mend - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.create(lstart, lend)); } else { int lbeg = splitter.getOffset(mm); int loff = mstart - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.createStarter(loff)); lbeg = splitter.getOffset(nn); loff = mend - lbeg; lhigh = res.get(nn); lhigh.addMarkup(PhraseHighlight.createEnder(loff)); for (int j = mm + 1; j <= nn - 1; ++j) { lhigh = res.get(j); lhigh.addMarkup(PhraseHighlight.createEntire()); } } } } } for (LineHighlight lhi : res.values()) { lhi.condenseMarkups(); String line = splitter.getLine(lhi.getLineno()); Matcher eolMatcher = StringUtils.STANDARD_EOL.matcher(line); if (eolMatcher.find()) { line = line.substring(0, eolMatcher.start()); } elideLine(lhi, line); } return res; } PassageConverter(ContextArgs args); ContextArgs getArgs(); SortedMap<Integer, LineHighlight> convert(Passage[] passages,
        SourceSplitter splitter); }
PassageConverter { public SortedMap<Integer, LineHighlight> convert(Passage[] passages, SourceSplitter splitter) { SortedMap<Integer, LineHighlight> res = new TreeMap<>(); for (Passage passage : passages) { int start = passage.getStartOffset(); int end = passage.getEndOffset(); if (start >= end) { continue; } int m = splitter.findLineIndex(start); if (m < 0) { continue; } int n = splitter.findLineIndex(end - 1); if (n < 0) { continue; } m = Math.max(0, m - args.getContextSurround()); n = Math.min(splitter.count() - 1, n + args.getContextSurround()); for (int i = m; i <= n; ++i) { if (!res.containsKey(i)) { res.put(i, new LineHighlight(i)); } } for (int i = 0; i < passage.getNumMatches(); ++i) { int mstart = passage.getMatchStarts()[i]; int mm = splitter.findLineIndex(mstart); int mend = passage.getMatchEnds()[i]; int nn = splitter.findLineIndex(mend - 1); if (mstart < mend && mm >= m && mm <= n && nn >= m && nn <= n) { if (mm == nn) { int lbeg = splitter.getOffset(mm); int lstart = mstart - lbeg; int lend = mend - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.create(lstart, lend)); } else { int lbeg = splitter.getOffset(mm); int loff = mstart - lbeg; LineHighlight lhigh = res.get(mm); lhigh.addMarkup(PhraseHighlight.createStarter(loff)); lbeg = splitter.getOffset(nn); loff = mend - lbeg; lhigh = res.get(nn); lhigh.addMarkup(PhraseHighlight.createEnder(loff)); for (int j = mm + 1; j <= nn - 1; ++j) { lhigh = res.get(j); lhigh.addMarkup(PhraseHighlight.createEntire()); } } } } } for (LineHighlight lhi : res.values()) { lhi.condenseMarkups(); String line = splitter.getLine(lhi.getLineno()); Matcher eolMatcher = StringUtils.STANDARD_EOL.matcher(line); if (eolMatcher.find()) { line = line.substring(0, eolMatcher.start()); } elideLine(lhi, line); } return res; } PassageConverter(ContextArgs args); ContextArgs getArgs(); SortedMap<Integer, LineHighlight> convert(Passage[] passages,
        SourceSplitter splitter);  }