@Test public void testGetHighlightedTextNestedEntity() throws Exception { String text = "This is a test sentence"; List<OffsetItem> offsetItems = new ArrayList<OffsetItem>(); OffsetItem mockEntity1 = mock(VertexOffsetItem.class); when(mockEntity1.getStart()).thenReturn(0l); when(mockEntity1.getEnd()).thenReturn(4l); when(mockEntity1.getResolvedToVertexId()).thenReturn("0"); when(mockEntity1.getCssClasses()).thenReturn(asList(new String[]{"first"})); when(mockEntity1.shouldHighlight()).thenReturn(true); when(mockEntity1.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}")); offsetItems.add(mockEntity1); OffsetItem mockEntity2 = mock(VertexOffsetItem.class); when(mockEntity2.getStart()).thenReturn(0l); when(mockEntity2.getEnd()).thenReturn(4l); when(mockEntity2.getResolvedToVertexId()).thenReturn("1"); when(mockEntity2.getCssClasses()).thenReturn(asList(new String[]{"second"})); when(mockEntity2.shouldHighlight()).thenReturn(true); when(mockEntity2.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}")); offsetItems.add(mockEntity2); OffsetItem mockEntity3 = mock(VertexOffsetItem.class); when(mockEntity3.getStart()).thenReturn(0l); when(mockEntity3.getEnd()).thenReturn(7l); when(mockEntity3.getCssClasses()).thenReturn(asList(new String[]{"third"})); when(mockEntity3.shouldHighlight()).thenReturn(true); when(mockEntity3.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}")); offsetItems.add(mockEntity3); OffsetItem mockEntity4 = mock(VertexOffsetItem.class); when(mockEntity4.getStart()).thenReturn(5l); when(mockEntity4.getEnd()).thenReturn(9l); when(mockEntity4.getCssClasses()).thenReturn(asList(new String[]{"fourth"})); when(mockEntity4.shouldHighlight()).thenReturn(true); when(mockEntity4.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}")); offsetItems.add(mockEntity4); OffsetItem mockEntity5 = mock(VertexOffsetItem.class); when(mockEntity5.getStart()).thenReturn(15l); when(mockEntity5.getEnd()).thenReturn(23l); when(mockEntity5.getCssClasses()).thenReturn(asList(new String[]{"fifth"})); when(mockEntity5.shouldHighlight()).thenReturn(true); when(mockEntity5.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}")); offsetItems.add(mockEntity5); String highlightedText = EntityHighlighter.getHighlightedText(text, offsetItems); assertEquals("<span class=\"first\" data-info=\"{&quot;data&quot;:&quot;attribute&quot;}\">This</span> " + "<span class=\"fourth\" data-info=\"{&quot;data&quot;:&quot;attribute&quot;}\">is a</span> test <span " + "class=\"fifth\" data-info=\"{&quot;data&quot;:&quot;attribute&quot;}\">sentence</span>", highlightedText ); }
public String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations) { List<OffsetItem> offsetItems = convertTermMentionsToOffsetItems(termMentions, workspaceId, authorizations); return getHighlightedText(text, offsetItems); }
EntityHighlighter { public String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations) { List<OffsetItem> offsetItems = convertTermMentionsToOffsetItems(termMentions, workspaceId, authorizations); return getHighlightedText(text, offsetItems); } }
EntityHighlighter { public String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations) { List<OffsetItem> offsetItems = convertTermMentionsToOffsetItems(termMentions, workspaceId, authorizations); return getHighlightedText(text, offsetItems); }  }
EntityHighlighter { public String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations) { List<OffsetItem> offsetItems = convertTermMentionsToOffsetItems(termMentions, workspaceId, authorizations); return getHighlightedText(text, offsetItems); }  String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations); static String getHighlightedText(String text, List<OffsetItem> offsetItems); VideoTranscript getHighlightedVideoTranscript(VideoTranscript videoTranscript, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations); List<OffsetItem> convertTermMentionsToOffsetItems(Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations); }
EntityHighlighter { public String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations) { List<OffsetItem> offsetItems = convertTermMentionsToOffsetItems(termMentions, workspaceId, authorizations); return getHighlightedText(text, offsetItems); }  String getHighlightedText(String text, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations); static String getHighlightedText(String text, List<OffsetItem> offsetItems); VideoTranscript getHighlightedVideoTranscript(VideoTranscript videoTranscript, Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations); List<OffsetItem> convertTermMentionsToOffsetItems(Iterable<Vertex> termMentions, String workspaceId, Authorizations authorizations);  }