@Test public void testSortPositionsForMultiwordPhrase() { String query = "fox brown"; List positions = new ArrayList(); List<TermWithTermOffsets> termWithOffsetsList = new ArrayList<>(); TermWithTermOffsets one = new TermWithTermOffsets(); TermWithTermOffsets two = new TermWithTermOffsets(); one.setTerm("fox"); List <TermOffsetsWithPosition>oneOffsets = new ArrayList<>(); TermOffsetsWithPosition oneStartEndA = new TermOffsetsWithPosition(); oneStartEndA.setStart(0); oneStartEndA.setEnd(3); oneOffsets.add(oneStartEndA); TermOffsetsWithPosition oneStartEnd = new TermOffsetsWithPosition(); oneStartEnd.setStart(10); oneStartEnd.setEnd(13); oneOffsets.add(oneStartEnd); TermOffsetsWithPosition oneStartEnd2 = new TermOffsetsWithPosition(); oneStartEnd2.setStart(110); oneStartEnd2.setEnd(113); oneOffsets.add(oneStartEnd2); TermOffsetsWithPosition oneStartEnd3 = new TermOffsetsWithPosition(); oneStartEnd3.setStart(120); oneStartEnd3.setEnd(123); oneOffsets.add(oneStartEnd3); one.setOffsets(oneOffsets); two.setTerm("brown"); List <TermOffsetsWithPosition>twoOffsets = new ArrayList<>(); TermOffsetsWithPosition twoStartEnd = new TermOffsetsWithPosition(); twoStartEnd.setStart(14); twoStartEnd.setEnd(20); twoOffsets.add(twoStartEnd); TermOffsetsWithPosition twoStartEndA = new TermOffsetsWithPosition(); twoStartEndA.setStart(100); twoStartEndA.setEnd(105); twoOffsets.add(twoStartEndA); TermOffsetsWithPosition twoStartEnd2 = new TermOffsetsWithPosition(); twoStartEnd2.setStart(114); twoStartEnd2.setEnd(119); twoOffsets.add(twoStartEnd2); TermOffsetsWithPosition twoStartEnd3 = new TermOffsetsWithPosition(); twoStartEnd3.setStart(124); twoStartEnd3.setEnd(129); twoOffsets.add(twoStartEnd3); two.setOffsets(twoOffsets); termWithOffsetsList.add(one); termWithOffsetsList.add(two); textUtils.workThoughOffsets(termWithOffsetsList); Map<String, String> offsetMap = creatOffsetPositionMap(); List <Positions>positionsList = new ArrayList<>(); positions = textUtils.sortPositionsForMultiwordPhrase(termWithOffsetsList, offsetMap, positionsList); assertTrue(positions.size() == 3); LOG.info("positions " + positions); TermWithTermOffsets three = new TermWithTermOffsets(); three.setTerm("laughs"); List <TermOffsetsWithPosition>threeOffsets = new ArrayList<>(); TermOffsetsWithPosition threeStartEnd = new TermOffsetsWithPosition(); threeStartEnd.setStart(21); threeStartEnd.setEnd(27); threeOffsets.add(threeStartEnd); TermOffsetsWithPosition threeStartEnd3 = new TermOffsetsWithPosition(); threeStartEnd3.setStart(130); threeStartEnd3.setEnd(136); threeOffsets.add(threeStartEnd3); three.setOffsets(threeOffsets); termWithOffsetsList.add(three); TermWithTermOffsets four = new TermWithTermOffsets(); four.setTerm("quickly"); List <TermOffsetsWithPosition>fourOffsets = new ArrayList<>(); TermOffsetsWithPosition fourStartEnd = new TermOffsetsWithPosition(); fourStartEnd.setStart(28); fourStartEnd.setEnd(35); fourOffsets.add(fourStartEnd); TermOffsetsWithPosition fourStartEnd3 = new TermOffsetsWithPosition(); fourStartEnd3.setStart(137); fourStartEnd3.setEnd(142); fourOffsets.add(fourStartEnd3); four.setOffsets(fourOffsets); termWithOffsetsList.add(four); textUtils.workThoughOffsets(termWithOffsetsList); positionsList = new ArrayList<>(); positions= textUtils.sortPositionsForMultiwordPhrase(termWithOffsetsList, offsetMap, positionsList); assertTrue(positions.size() == 2); LOG.info("positions " + positions); }
public List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList, Map<String, String> offsetPositionMap, List<Positions> positionsList) { List<String> stringSets = workThoughOffsets(termWithOffsetsList); List<String> templist; List<Object> position = new ArrayList<>(); for (String item : stringSets) { templist = new ArrayList<>(); String[] stringArray = item.split("[|]"); for (String numberInArray : stringArray) { templist.add(numberInArray); } int start = Integer.parseInt(offsetPositionMap.get(templist.get(0))); int end = Integer.parseInt(offsetPositionMap.get(templist.get(templist.size() - 1))); positionsList.add(new Positions(start, end)); position.add(templist); } LOG.info("sortPositionsForMultiwordPhrase positionsList " + positionsList); LOG.info("sortPositionsForMultiwordPhrase position " + position); return position; }
TextUtils extends CommonUtils { public List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList, Map<String, String> offsetPositionMap, List<Positions> positionsList) { List<String> stringSets = workThoughOffsets(termWithOffsetsList); List<String> templist; List<Object> position = new ArrayList<>(); for (String item : stringSets) { templist = new ArrayList<>(); String[] stringArray = item.split("[|]"); for (String numberInArray : stringArray) { templist.add(numberInArray); } int start = Integer.parseInt(offsetPositionMap.get(templist.get(0))); int end = Integer.parseInt(offsetPositionMap.get(templist.get(templist.size() - 1))); positionsList.add(new Positions(start, end)); position.add(templist); } LOG.info("sortPositionsForMultiwordPhrase positionsList " + positionsList); LOG.info("sortPositionsForMultiwordPhrase position " + position); return position; } }
TextUtils extends CommonUtils { public List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList, Map<String, String> offsetPositionMap, List<Positions> positionsList) { List<String> stringSets = workThoughOffsets(termWithOffsetsList); List<String> templist; List<Object> position = new ArrayList<>(); for (String item : stringSets) { templist = new ArrayList<>(); String[] stringArray = item.split("[|]"); for (String numberInArray : stringArray) { templist.add(numberInArray); } int start = Integer.parseInt(offsetPositionMap.get(templist.get(0))); int end = Integer.parseInt(offsetPositionMap.get(templist.get(templist.size() - 1))); positionsList.add(new Positions(start, end)); position.add(templist); } LOG.info("sortPositionsForMultiwordPhrase positionsList " + positionsList); LOG.info("sortPositionsForMultiwordPhrase position " + position); return position; }  }
TextUtils extends CommonUtils { public List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList, Map<String, String> offsetPositionMap, List<Positions> positionsList) { List<String> stringSets = workThoughOffsets(termWithOffsetsList); List<String> templist; List<Object> position = new ArrayList<>(); for (String item : stringSets) { templist = new ArrayList<>(); String[] stringArray = item.split("[|]"); for (String numberInArray : stringArray) { templist.add(numberInArray); } int start = Integer.parseInt(offsetPositionMap.get(templist.get(0))); int end = Integer.parseInt(offsetPositionMap.get(templist.get(templist.size() - 1))); positionsList.add(new Positions(start, end)); position.add(templist); } LOG.info("sortPositionsForMultiwordPhrase positionsList " + positionsList); LOG.info("sortPositionsForMultiwordPhrase position " + position); return position; }  ImageHelperObject createOffsetPayload(Map<String, List<TermWithTermOffsets>> termWithOffsetsMap,
			String width, String height, Map<String, Map<String, String>> offsetPositionMap,
			Map<String, PageOverlapDetails> canvasOverlapDetailMap); Map<String, String> createCoordinateAnnotationFromImages(String query, Images images,
			ImageHelperObject imageHelper, Map<String, String> imageCanvasMap); int amendCrossCoordinates(Image crossImage, int next, int countTally, String[] queryArray,
			Map<String, String> crossCoordinates); Map<String, Object> createCoordinateAnnotation(String query, String coordinatePayload, boolean isW3c,
			ImageHelperObject imageHelper, Map<String, Map<String, TermOffsetStart>> termPositionMap,
			String queryString, PageParameters pageParams, boolean isMixedSearch, Map<String, String> imageCanvasMap,
			Map<String, String> crossXywhQueryMap); ImageHelperObject createImages(Map<String, List<TermWithTermOffsets>> termWithOffsetsMap, String width,
			String height, Map<String, Map<String, String>> offsetPositionMap,
			Map<String, PageOverlapDetails> canvasOverlapDetailMap); PositionListObjects sortMultiTermPosition(List<Object> positions, PageOverlapDetails overlapDetails,
			List<Positions> positionsList); List<String> workThoughOffsets(List<TermWithTermOffsets> termWithOffsetsList); List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList,
			Map<String, String> offsetPositionMap, List<Positions> positionsList); Map<String, Object> createResource(String imageId, String query, boolean isW3c, String xywh,
			String annoUrl); void amendStartsAndEndsPositions(String text, int startText, int endText); static void main(String[] args); }
TextUtils extends CommonUtils { public List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList, Map<String, String> offsetPositionMap, List<Positions> positionsList) { List<String> stringSets = workThoughOffsets(termWithOffsetsList); List<String> templist; List<Object> position = new ArrayList<>(); for (String item : stringSets) { templist = new ArrayList<>(); String[] stringArray = item.split("[|]"); for (String numberInArray : stringArray) { templist.add(numberInArray); } int start = Integer.parseInt(offsetPositionMap.get(templist.get(0))); int end = Integer.parseInt(offsetPositionMap.get(templist.get(templist.size() - 1))); positionsList.add(new Positions(start, end)); position.add(templist); } LOG.info("sortPositionsForMultiwordPhrase positionsList " + positionsList); LOG.info("sortPositionsForMultiwordPhrase position " + position); return position; }  ImageHelperObject createOffsetPayload(Map<String, List<TermWithTermOffsets>> termWithOffsetsMap,
			String width, String height, Map<String, Map<String, String>> offsetPositionMap,
			Map<String, PageOverlapDetails> canvasOverlapDetailMap); Map<String, String> createCoordinateAnnotationFromImages(String query, Images images,
			ImageHelperObject imageHelper, Map<String, String> imageCanvasMap); int amendCrossCoordinates(Image crossImage, int next, int countTally, String[] queryArray,
			Map<String, String> crossCoordinates); Map<String, Object> createCoordinateAnnotation(String query, String coordinatePayload, boolean isW3c,
			ImageHelperObject imageHelper, Map<String, Map<String, TermOffsetStart>> termPositionMap,
			String queryString, PageParameters pageParams, boolean isMixedSearch, Map<String, String> imageCanvasMap,
			Map<String, String> crossXywhQueryMap); ImageHelperObject createImages(Map<String, List<TermWithTermOffsets>> termWithOffsetsMap, String width,
			String height, Map<String, Map<String, String>> offsetPositionMap,
			Map<String, PageOverlapDetails> canvasOverlapDetailMap); PositionListObjects sortMultiTermPosition(List<Object> positions, PageOverlapDetails overlapDetails,
			List<Positions> positionsList); List<String> workThoughOffsets(List<TermWithTermOffsets> termWithOffsetsList); List<Object> sortPositionsForMultiwordPhrase(List<TermWithTermOffsets> termWithOffsetsList,
			Map<String, String> offsetPositionMap, List<Positions> positionsList); Map<String, Object> createResource(String imageId, String query, boolean isW3c, String xywh,
			String annoUrl); void amendStartsAndEndsPositions(String text, int startText, int endText); static void main(String[] args); static final String SERVICE_NAME; }