@Test public void testCoordinates() throws IOException{ String id1 = "https: String id2 = "https: String id3 = "https: Map<String,String> imageCanvasMap = new HashMap<>(); imageCanvasMap.put(id1, id1); imageCanvasMap.put(id2, id2); imageCanvasMap.put(id3, id3); String query = "test me out for a long"; Map <String, List<Positions>> positionMap = new HashMap<>(); List<Positions> positionList = new ArrayList<>(); Positions pos1 = new Positions(10, 10); Positions pos2 = new Positions(12, 12); Positions pos3 = new Positions(14, 14); Positions pos4 = new Positions(16, 16); Positions pos5 = new Positions(18, 18); Positions pos6 = new Positions(20, 20); positionList.add(pos1); positionList.add(pos2); positionList.add(pos3); positionList.add(pos4); positionList.add(pos5); positionList.add(pos6); positionMap.put(id1, positionList); List<Positions> positionList2 = new ArrayList<>(); Positions pos21 = new Positions(10, 10); Positions pos22 = new Positions(12, 12); positionList2.add(pos21); positionList2.add(pos22); positionMap.put(id2, positionList2); List<Positions> positionList3 = new ArrayList<>(); Positions pos31 = new Positions(10, 10); positionList3.add(pos31); positionMap.put(id3, positionList3); Map<String, Map<String, TermOffsetStart>> termPositionMap = new HashMap<>(); Map<String, TermOffsetStart> termOffsetMap1 = new HashMap<>(); Map<String, TermOffsetStart> termOffsetMap2 = new HashMap<>(); TermOffsetStart termOffsetStart5 = new TermOffsetStart(); termOffsetStart5.setTerm("the"); TermOffsetStart termOffsetStart6 = new TermOffsetStart(); termOffsetStart6.setTerm("big"); TermOffsetStart termOffsetStart7 = new TermOffsetStart(); termOffsetStart7.setTerm("bad"); TermOffsetStart termOffsetStart8 = new TermOffsetStart(); termOffsetStart8.setTerm("baby"); TermOffsetStart termOffsetStart9 = new TermOffsetStart(); termOffsetStart9.setTerm("red"); TermOffsetStart termOffsetStart10 = new TermOffsetStart(); termOffsetStart10.setTerm("fox"); TermOffsetStart termOffsetStart11 = new TermOffsetStart(); termOffsetStart11.setTerm("put"); TermOffsetStart termOffsetStart12 = new TermOffsetStart(); termOffsetStart12.setTerm("a"); TermOffsetStart termOffsetStart13 = new TermOffsetStart(); termOffsetStart13.setTerm("hen"); TermOffsetStart termOffsetStart14 = new TermOffsetStart(); termOffsetStart14.setTerm("into"); termPositionMap.put(id1, termOffsetMap1); termPositionMap.put(id2, termOffsetMap1); termPositionMap.put(id3, termOffsetMap1); termOffsetMap1.put("5", termOffsetStart5); termOffsetMap1.put("6", termOffsetStart6); termOffsetMap1.put("7", termOffsetStart7); termOffsetMap1.put("8", termOffsetStart8); termOffsetMap1.put("9", termOffsetStart9); termOffsetMap1.put("10", termOffsetStart10); termOffsetMap1.put("11", termOffsetStart11); termOffsetMap1.put("12", termOffsetStart12); termOffsetMap1.put("13", termOffsetStart13); termOffsetMap1.put("14", termOffsetStart14); String queryString = "http: String coordinates2 = getFileContents("test_coordinates_2.json"); ImageHelperObject imageHelper = new ImageHelperObject(); imageHelper.setPositionsMap(positionMap); Map<String,String> crossMap = null; Map<String,Object> map = textUtils.createCoordinateAnnotation(query, coordinates2, true, imageHelper, termPositionMap, queryString, new PageParameters(), true, imageCanvasMap, crossMap); LOG.info(map.toString()); }
public 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) { if (null == coordinatePayload) { return null; } Map<String, Object> javaRootBodyMapObject = new Gson().fromJson(coordinatePayload, Map.class); Map<String, List<Positions>> positionMap = imageHelper.getPositionsMap(); Map<String, String> crossPageImageMap = imageHelper.getCrossPageImageMap(); LOG.info("crossPageImageMap: " + crossPageImageMap); if (null == javaRootBodyMapObject) { return null; } String[] queryArray = query.split(" "); int queryArrayLength = queryArray.length; LOG.info("queryArrayLength: " + queryArrayLength); Map<String, Object> root; root = this.buildAnnotationPageHead(queryString, isW3c, pageParams, true); List<Map> resources = this.getResources(root, isW3c); this.setHits(root); List images = (List) javaRootBodyMapObject.get(IMAGESLIST); List<Positions> crossPositionList = null; for (Object object : (List) images) { Map<String, Object> image = (Map<String, Object>) object; String imageId = (String) image.get("image_uri"); String id = imageCanvasMap.get(imageId); Map<String, String> annoURLMap = new HashMap<>(); List<Positions> positionList = positionMap.get(id); LOG.debug("positionList: " + positionList); Map<String, TermOffsetStart> sourcePositionMap = termPositionMap.get(id); Object phraseObject = image.get(PHRASES); List<Map<String, Object>> hitList = this.getHits(root); if (phraseObject instanceof ArrayList) { List phraseObjectList = (ArrayList) image.get(PHRASES); int count = 0; for (Object innerPhraseArray : phraseObjectList) { if (innerPhraseArray instanceof ArrayList) { List innerObjectList = (ArrayList) innerPhraseArray; Map<String, String> xywhMap = new HashMap<>(); String xywh = null; String termCount; int queryCount = 0; String[] beforeAfter = null; for (Object phraseArray : innerObjectList) { LinkedTreeMap map = (LinkedTreeMap) phraseArray; xywh = (String) map.get("xywh"); termCount = removeDotZero((Double) map.get("count")) + ""; int start = positionList.get(count).getStartPosition(); int end = positionList.get(count).getEndPosition(); if (null != sourcePositionMap) { beforeAfter = this.getHighlights(start, end, BEFORE_AFTER_WORDS, sourcePositionMap); } StringBuilder queryForResource = new StringBuilder(); int countInt = Integer.parseInt(termCount); if (queryArrayLength > countInt) { if (queryCount == 0) { for (int r = 0; r < countInt; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } else { Collection<String> stringList = xywhMap.values(); int countOfElements = 0; for (String value : stringList) { String[] valueArray = value.split(" "); countOfElements += valueArray.length; } for (int r = countOfElements; r < countInt + countOfElements; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } if (null != crossXywhQueryMap && crossXywhQueryMap.containsKey(xywh)) { xywhMap.put(xywh, crossXywhQueryMap.get(xywh)); } queryCount++; } else { xywhMap.put(xywh, query); } String annoUrl = createMadeUpResource(queryString, xywh); annoURLMap.put(xywh, annoUrl); } LOG.debug("xywhMap " + xywhMap); Map<String, Object> hitMap = new LinkedHashMap<>(); List<String> list = new ArrayList<>(xywhMap.keySet()); Collections.sort(list, Collections.reverseOrder()); Set<String> resultSet = new LinkedHashSet<>(list); List<String> annotationsList = new ArrayList<>(); for (String xywhKey : resultSet) { String partQuery = xywhMap.get(xywhKey); annotationsList.add(annoURLMap.get(xywhKey)); resources.add(createResource(id, partQuery, isW3c, xywhKey, annoURLMap.get(xywhKey))); } if (null != beforeAfter) { setHits(isW3c, hitMap, annotationsList, query, beforeAfter); } LOG.debug("Hit:" + hitMap.toString()); if (!hitMap.isEmpty()) { hitList.add(hitMap); } } count++; } } } if (TextSearchServiceImpl.DEFAULT_TEXT_PAGING_NUMBER > resources.size() && !isMixedSearch) { if (isW3c) { root.remove(W3C_WITHIN_IS_PART_OF); root.remove(W3C_STARTINDEX); } else { root.remove(OA_WITHIN); root.remove(OA_STARTINDEX); } root.remove(NEXT); root.remove(PREV); } return root; }
TextUtils extends CommonUtils { public 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) { if (null == coordinatePayload) { return null; } Map<String, Object> javaRootBodyMapObject = new Gson().fromJson(coordinatePayload, Map.class); Map<String, List<Positions>> positionMap = imageHelper.getPositionsMap(); Map<String, String> crossPageImageMap = imageHelper.getCrossPageImageMap(); LOG.info("crossPageImageMap: " + crossPageImageMap); if (null == javaRootBodyMapObject) { return null; } String[] queryArray = query.split(" "); int queryArrayLength = queryArray.length; LOG.info("queryArrayLength: " + queryArrayLength); Map<String, Object> root; root = this.buildAnnotationPageHead(queryString, isW3c, pageParams, true); List<Map> resources = this.getResources(root, isW3c); this.setHits(root); List images = (List) javaRootBodyMapObject.get(IMAGESLIST); List<Positions> crossPositionList = null; for (Object object : (List) images) { Map<String, Object> image = (Map<String, Object>) object; String imageId = (String) image.get("image_uri"); String id = imageCanvasMap.get(imageId); Map<String, String> annoURLMap = new HashMap<>(); List<Positions> positionList = positionMap.get(id); LOG.debug("positionList: " + positionList); Map<String, TermOffsetStart> sourcePositionMap = termPositionMap.get(id); Object phraseObject = image.get(PHRASES); List<Map<String, Object>> hitList = this.getHits(root); if (phraseObject instanceof ArrayList) { List phraseObjectList = (ArrayList) image.get(PHRASES); int count = 0; for (Object innerPhraseArray : phraseObjectList) { if (innerPhraseArray instanceof ArrayList) { List innerObjectList = (ArrayList) innerPhraseArray; Map<String, String> xywhMap = new HashMap<>(); String xywh = null; String termCount; int queryCount = 0; String[] beforeAfter = null; for (Object phraseArray : innerObjectList) { LinkedTreeMap map = (LinkedTreeMap) phraseArray; xywh = (String) map.get("xywh"); termCount = removeDotZero((Double) map.get("count")) + ""; int start = positionList.get(count).getStartPosition(); int end = positionList.get(count).getEndPosition(); if (null != sourcePositionMap) { beforeAfter = this.getHighlights(start, end, BEFORE_AFTER_WORDS, sourcePositionMap); } StringBuilder queryForResource = new StringBuilder(); int countInt = Integer.parseInt(termCount); if (queryArrayLength > countInt) { if (queryCount == 0) { for (int r = 0; r < countInt; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } else { Collection<String> stringList = xywhMap.values(); int countOfElements = 0; for (String value : stringList) { String[] valueArray = value.split(" "); countOfElements += valueArray.length; } for (int r = countOfElements; r < countInt + countOfElements; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } if (null != crossXywhQueryMap && crossXywhQueryMap.containsKey(xywh)) { xywhMap.put(xywh, crossXywhQueryMap.get(xywh)); } queryCount++; } else { xywhMap.put(xywh, query); } String annoUrl = createMadeUpResource(queryString, xywh); annoURLMap.put(xywh, annoUrl); } LOG.debug("xywhMap " + xywhMap); Map<String, Object> hitMap = new LinkedHashMap<>(); List<String> list = new ArrayList<>(xywhMap.keySet()); Collections.sort(list, Collections.reverseOrder()); Set<String> resultSet = new LinkedHashSet<>(list); List<String> annotationsList = new ArrayList<>(); for (String xywhKey : resultSet) { String partQuery = xywhMap.get(xywhKey); annotationsList.add(annoURLMap.get(xywhKey)); resources.add(createResource(id, partQuery, isW3c, xywhKey, annoURLMap.get(xywhKey))); } if (null != beforeAfter) { setHits(isW3c, hitMap, annotationsList, query, beforeAfter); } LOG.debug("Hit:" + hitMap.toString()); if (!hitMap.isEmpty()) { hitList.add(hitMap); } } count++; } } } if (TextSearchServiceImpl.DEFAULT_TEXT_PAGING_NUMBER > resources.size() && !isMixedSearch) { if (isW3c) { root.remove(W3C_WITHIN_IS_PART_OF); root.remove(W3C_STARTINDEX); } else { root.remove(OA_WITHIN); root.remove(OA_STARTINDEX); } root.remove(NEXT); root.remove(PREV); } return root; } }
TextUtils extends CommonUtils { public 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) { if (null == coordinatePayload) { return null; } Map<String, Object> javaRootBodyMapObject = new Gson().fromJson(coordinatePayload, Map.class); Map<String, List<Positions>> positionMap = imageHelper.getPositionsMap(); Map<String, String> crossPageImageMap = imageHelper.getCrossPageImageMap(); LOG.info("crossPageImageMap: " + crossPageImageMap); if (null == javaRootBodyMapObject) { return null; } String[] queryArray = query.split(" "); int queryArrayLength = queryArray.length; LOG.info("queryArrayLength: " + queryArrayLength); Map<String, Object> root; root = this.buildAnnotationPageHead(queryString, isW3c, pageParams, true); List<Map> resources = this.getResources(root, isW3c); this.setHits(root); List images = (List) javaRootBodyMapObject.get(IMAGESLIST); List<Positions> crossPositionList = null; for (Object object : (List) images) { Map<String, Object> image = (Map<String, Object>) object; String imageId = (String) image.get("image_uri"); String id = imageCanvasMap.get(imageId); Map<String, String> annoURLMap = new HashMap<>(); List<Positions> positionList = positionMap.get(id); LOG.debug("positionList: " + positionList); Map<String, TermOffsetStart> sourcePositionMap = termPositionMap.get(id); Object phraseObject = image.get(PHRASES); List<Map<String, Object>> hitList = this.getHits(root); if (phraseObject instanceof ArrayList) { List phraseObjectList = (ArrayList) image.get(PHRASES); int count = 0; for (Object innerPhraseArray : phraseObjectList) { if (innerPhraseArray instanceof ArrayList) { List innerObjectList = (ArrayList) innerPhraseArray; Map<String, String> xywhMap = new HashMap<>(); String xywh = null; String termCount; int queryCount = 0; String[] beforeAfter = null; for (Object phraseArray : innerObjectList) { LinkedTreeMap map = (LinkedTreeMap) phraseArray; xywh = (String) map.get("xywh"); termCount = removeDotZero((Double) map.get("count")) + ""; int start = positionList.get(count).getStartPosition(); int end = positionList.get(count).getEndPosition(); if (null != sourcePositionMap) { beforeAfter = this.getHighlights(start, end, BEFORE_AFTER_WORDS, sourcePositionMap); } StringBuilder queryForResource = new StringBuilder(); int countInt = Integer.parseInt(termCount); if (queryArrayLength > countInt) { if (queryCount == 0) { for (int r = 0; r < countInt; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } else { Collection<String> stringList = xywhMap.values(); int countOfElements = 0; for (String value : stringList) { String[] valueArray = value.split(" "); countOfElements += valueArray.length; } for (int r = countOfElements; r < countInt + countOfElements; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } if (null != crossXywhQueryMap && crossXywhQueryMap.containsKey(xywh)) { xywhMap.put(xywh, crossXywhQueryMap.get(xywh)); } queryCount++; } else { xywhMap.put(xywh, query); } String annoUrl = createMadeUpResource(queryString, xywh); annoURLMap.put(xywh, annoUrl); } LOG.debug("xywhMap " + xywhMap); Map<String, Object> hitMap = new LinkedHashMap<>(); List<String> list = new ArrayList<>(xywhMap.keySet()); Collections.sort(list, Collections.reverseOrder()); Set<String> resultSet = new LinkedHashSet<>(list); List<String> annotationsList = new ArrayList<>(); for (String xywhKey : resultSet) { String partQuery = xywhMap.get(xywhKey); annotationsList.add(annoURLMap.get(xywhKey)); resources.add(createResource(id, partQuery, isW3c, xywhKey, annoURLMap.get(xywhKey))); } if (null != beforeAfter) { setHits(isW3c, hitMap, annotationsList, query, beforeAfter); } LOG.debug("Hit:" + hitMap.toString()); if (!hitMap.isEmpty()) { hitList.add(hitMap); } } count++; } } } if (TextSearchServiceImpl.DEFAULT_TEXT_PAGING_NUMBER > resources.size() && !isMixedSearch) { if (isW3c) { root.remove(W3C_WITHIN_IS_PART_OF); root.remove(W3C_STARTINDEX); } else { root.remove(OA_WITHIN); root.remove(OA_STARTINDEX); } root.remove(NEXT); root.remove(PREV); } return root; }  }
TextUtils extends CommonUtils { public 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) { if (null == coordinatePayload) { return null; } Map<String, Object> javaRootBodyMapObject = new Gson().fromJson(coordinatePayload, Map.class); Map<String, List<Positions>> positionMap = imageHelper.getPositionsMap(); Map<String, String> crossPageImageMap = imageHelper.getCrossPageImageMap(); LOG.info("crossPageImageMap: " + crossPageImageMap); if (null == javaRootBodyMapObject) { return null; } String[] queryArray = query.split(" "); int queryArrayLength = queryArray.length; LOG.info("queryArrayLength: " + queryArrayLength); Map<String, Object> root; root = this.buildAnnotationPageHead(queryString, isW3c, pageParams, true); List<Map> resources = this.getResources(root, isW3c); this.setHits(root); List images = (List) javaRootBodyMapObject.get(IMAGESLIST); List<Positions> crossPositionList = null; for (Object object : (List) images) { Map<String, Object> image = (Map<String, Object>) object; String imageId = (String) image.get("image_uri"); String id = imageCanvasMap.get(imageId); Map<String, String> annoURLMap = new HashMap<>(); List<Positions> positionList = positionMap.get(id); LOG.debug("positionList: " + positionList); Map<String, TermOffsetStart> sourcePositionMap = termPositionMap.get(id); Object phraseObject = image.get(PHRASES); List<Map<String, Object>> hitList = this.getHits(root); if (phraseObject instanceof ArrayList) { List phraseObjectList = (ArrayList) image.get(PHRASES); int count = 0; for (Object innerPhraseArray : phraseObjectList) { if (innerPhraseArray instanceof ArrayList) { List innerObjectList = (ArrayList) innerPhraseArray; Map<String, String> xywhMap = new HashMap<>(); String xywh = null; String termCount; int queryCount = 0; String[] beforeAfter = null; for (Object phraseArray : innerObjectList) { LinkedTreeMap map = (LinkedTreeMap) phraseArray; xywh = (String) map.get("xywh"); termCount = removeDotZero((Double) map.get("count")) + ""; int start = positionList.get(count).getStartPosition(); int end = positionList.get(count).getEndPosition(); if (null != sourcePositionMap) { beforeAfter = this.getHighlights(start, end, BEFORE_AFTER_WORDS, sourcePositionMap); } StringBuilder queryForResource = new StringBuilder(); int countInt = Integer.parseInt(termCount); if (queryArrayLength > countInt) { if (queryCount == 0) { for (int r = 0; r < countInt; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } else { Collection<String> stringList = xywhMap.values(); int countOfElements = 0; for (String value : stringList) { String[] valueArray = value.split(" "); countOfElements += valueArray.length; } for (int r = countOfElements; r < countInt + countOfElements; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } if (null != crossXywhQueryMap && crossXywhQueryMap.containsKey(xywh)) { xywhMap.put(xywh, crossXywhQueryMap.get(xywh)); } queryCount++; } else { xywhMap.put(xywh, query); } String annoUrl = createMadeUpResource(queryString, xywh); annoURLMap.put(xywh, annoUrl); } LOG.debug("xywhMap " + xywhMap); Map<String, Object> hitMap = new LinkedHashMap<>(); List<String> list = new ArrayList<>(xywhMap.keySet()); Collections.sort(list, Collections.reverseOrder()); Set<String> resultSet = new LinkedHashSet<>(list); List<String> annotationsList = new ArrayList<>(); for (String xywhKey : resultSet) { String partQuery = xywhMap.get(xywhKey); annotationsList.add(annoURLMap.get(xywhKey)); resources.add(createResource(id, partQuery, isW3c, xywhKey, annoURLMap.get(xywhKey))); } if (null != beforeAfter) { setHits(isW3c, hitMap, annotationsList, query, beforeAfter); } LOG.debug("Hit:" + hitMap.toString()); if (!hitMap.isEmpty()) { hitList.add(hitMap); } } count++; } } } if (TextSearchServiceImpl.DEFAULT_TEXT_PAGING_NUMBER > resources.size() && !isMixedSearch) { if (isW3c) { root.remove(W3C_WITHIN_IS_PART_OF); root.remove(W3C_STARTINDEX); } else { root.remove(OA_WITHIN); root.remove(OA_STARTINDEX); } root.remove(NEXT); root.remove(PREV); } return root; }  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 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) { if (null == coordinatePayload) { return null; } Map<String, Object> javaRootBodyMapObject = new Gson().fromJson(coordinatePayload, Map.class); Map<String, List<Positions>> positionMap = imageHelper.getPositionsMap(); Map<String, String> crossPageImageMap = imageHelper.getCrossPageImageMap(); LOG.info("crossPageImageMap: " + crossPageImageMap); if (null == javaRootBodyMapObject) { return null; } String[] queryArray = query.split(" "); int queryArrayLength = queryArray.length; LOG.info("queryArrayLength: " + queryArrayLength); Map<String, Object> root; root = this.buildAnnotationPageHead(queryString, isW3c, pageParams, true); List<Map> resources = this.getResources(root, isW3c); this.setHits(root); List images = (List) javaRootBodyMapObject.get(IMAGESLIST); List<Positions> crossPositionList = null; for (Object object : (List) images) { Map<String, Object> image = (Map<String, Object>) object; String imageId = (String) image.get("image_uri"); String id = imageCanvasMap.get(imageId); Map<String, String> annoURLMap = new HashMap<>(); List<Positions> positionList = positionMap.get(id); LOG.debug("positionList: " + positionList); Map<String, TermOffsetStart> sourcePositionMap = termPositionMap.get(id); Object phraseObject = image.get(PHRASES); List<Map<String, Object>> hitList = this.getHits(root); if (phraseObject instanceof ArrayList) { List phraseObjectList = (ArrayList) image.get(PHRASES); int count = 0; for (Object innerPhraseArray : phraseObjectList) { if (innerPhraseArray instanceof ArrayList) { List innerObjectList = (ArrayList) innerPhraseArray; Map<String, String> xywhMap = new HashMap<>(); String xywh = null; String termCount; int queryCount = 0; String[] beforeAfter = null; for (Object phraseArray : innerObjectList) { LinkedTreeMap map = (LinkedTreeMap) phraseArray; xywh = (String) map.get("xywh"); termCount = removeDotZero((Double) map.get("count")) + ""; int start = positionList.get(count).getStartPosition(); int end = positionList.get(count).getEndPosition(); if (null != sourcePositionMap) { beforeAfter = this.getHighlights(start, end, BEFORE_AFTER_WORDS, sourcePositionMap); } StringBuilder queryForResource = new StringBuilder(); int countInt = Integer.parseInt(termCount); if (queryArrayLength > countInt) { if (queryCount == 0) { for (int r = 0; r < countInt; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } else { Collection<String> stringList = xywhMap.values(); int countOfElements = 0; for (String value : stringList) { String[] valueArray = value.split(" "); countOfElements += valueArray.length; } for (int r = countOfElements; r < countInt + countOfElements; r++) { queryForResource.append(queryArray[r] + " "); } xywhMap.put(xywh, queryForResource.substring(0, queryForResource.length() - 1)); } if (null != crossXywhQueryMap && crossXywhQueryMap.containsKey(xywh)) { xywhMap.put(xywh, crossXywhQueryMap.get(xywh)); } queryCount++; } else { xywhMap.put(xywh, query); } String annoUrl = createMadeUpResource(queryString, xywh); annoURLMap.put(xywh, annoUrl); } LOG.debug("xywhMap " + xywhMap); Map<String, Object> hitMap = new LinkedHashMap<>(); List<String> list = new ArrayList<>(xywhMap.keySet()); Collections.sort(list, Collections.reverseOrder()); Set<String> resultSet = new LinkedHashSet<>(list); List<String> annotationsList = new ArrayList<>(); for (String xywhKey : resultSet) { String partQuery = xywhMap.get(xywhKey); annotationsList.add(annoURLMap.get(xywhKey)); resources.add(createResource(id, partQuery, isW3c, xywhKey, annoURLMap.get(xywhKey))); } if (null != beforeAfter) { setHits(isW3c, hitMap, annotationsList, query, beforeAfter); } LOG.debug("Hit:" + hitMap.toString()); if (!hitMap.isEmpty()) { hitList.add(hitMap); } } count++; } } } if (TextSearchServiceImpl.DEFAULT_TEXT_PAGING_NUMBER > resources.size() && !isMixedSearch) { if (isW3c) { root.remove(W3C_WITHIN_IS_PART_OF); root.remove(W3C_STARTINDEX); } else { root.remove(OA_WITHIN); root.remove(OA_STARTINDEX); } root.remove(NEXT); root.remove(PREV); } return root; }  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; }