Skip to content

Commit ba02004

Browse files
author
dterefe
committed
Display annotation details in document viewer.
1 parent 98c17cb commit ba02004

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

DUUIRestService/src/main/java/org/texttechnologylab/duui/api/Main.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.List;
1515
import java.util.Set;
1616
import java.util.UUID;
17+
import java.util.stream.Collectors;
1718

1819
import javax.servlet.MultipartConfigElement;
1920
import javax.servlet.ServletException;
@@ -265,6 +266,18 @@ public static String preprocessCas(Request request, Response response) {
265266
.peek(annotation -> annotationNames.add(annotation.getType().getName()))
266267
.map(annotation -> new Document()
267268
.append("annotationType", annotation.getType().getName())
269+
.append("details", annotation.getType().getFeatures()
270+
.stream()
271+
.filter(feat -> !feat.getShortName().equals("sofa")
272+
&& !feat.getShortName().equals("begin")
273+
&& !feat.getShortName().equals("end")
274+
&& annotation.getFeatureValueAsString(feat) != null
275+
&& !annotation.getFeatureValueAsString(feat).isEmpty())
276+
.map(feat ->
277+
feat.getShortName() + ": " + annotation.getFeatureValueAsString(feat) + "\n"
278+
)
279+
.collect(Collectors.joining())
280+
)
268281
.append("begin", annotation.getBegin())
269282
.append("end", annotation.getEnd())
270283
).toList();

DUUIWeb/src/lib/svelte/components/Drawer/DocumentDrawer.svelte

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {
1414
faChevronDown,
1515
faClose,
16-
faDownload,
16+
faDownload, faInfo,
1717
faRefresh
1818
} from '@fortawesome/free-solid-svg-icons'
1919
import { getDrawerStore, getToastStore } from '@skeletonlabs/skeleton'
@@ -26,6 +26,8 @@
2626
import Number from '../Input/Number.svelte'
2727
import Search from '../Input/Search.svelte'
2828
import Dropdown from "$lib/svelte/components/Input/Dropdown.svelte";
29+
import Popup from '$lib/svelte/components/Popup.svelte'
30+
import Link from '$lib/svelte/components/Link.svelte'
2931
3032
const drawerStore = getDrawerStore()
3133
@@ -81,11 +83,13 @@
8183
begin: number
8284
end: number
8385
annotationType: string
86+
details: string
8487
}
8588
8689
type ProcessedAnnotation = {
8790
text: string
8891
annotationType?: string
92+
details: string
8993
}
9094
9195
let selectedAnnotation: string = ""
@@ -133,19 +137,20 @@
133137
134138
Object.values(annotations)
135139
.filter((annotation) => annotation.annotationType === selectedType)
136-
.forEach(({ begin, end, annotationType }) => {
140+
.forEach(({ begin, end, annotationType, details }) => {
137141
if (currentIndex < begin) {
138-
parts.push({ text: text.slice(currentIndex, begin) });
142+
parts.push({ text: text.slice(currentIndex, begin), details });
139143
}
140144
parts.push({
141145
text: text.slice(begin, end),
142-
annotationType
146+
annotationType,
147+
details
143148
});
144149
currentIndex = end;
145150
});
146151
147152
if (currentIndex < text.length) {
148-
parts.push({ text: text.slice(currentIndex) });
153+
parts.push({ text: text.slice(currentIndex), details: "" });
149154
}
150155
151156
processingText = false
@@ -413,12 +418,25 @@
413418
options={annotationNames}
414419
/>
415420
<hr class="border-t border-gray-300 my-4 rounded-md">
416-
<div class="p-8 py-4 border-b border-color flex justify-between items-center gap-8">
417-
<div class="flex flex-col items-start justify-center gap-2">
421+
<div class="p-8 py-4 border-b border-color flex gap-8">
422+
<div class="flex flex-col items-start gap-2">
418423
<div class="h-64 overflow-y-auto">
419424
{#each processedAnnotations as part}
420425
{#if part.annotationType}
421-
<span class=" variant-soft-primary px-1 rounded"> {part.text}</span>
426+
<span class=" variant-soft-primary px-1 rounded">
427+
<Popup autoPopupWidth={true} arrow={false} position="left">
428+
<svelte:fragment slot="trigger">
429+
{part.text}
430+
</svelte:fragment>
431+
<svelte:fragment slot="popup" >
432+
<div class="bg-primary-50-900-token bg-transparent absolute p-3 rounded-md w-48 overflow-y-auto h-36">
433+
<small class="max-w-prose text-primary-700 whitespace-pre-wrap">
434+
{part.details}
435+
</small>
436+
</div>
437+
</svelte:fragment>
438+
</Popup>
439+
</span>
422440
{:else}
423441
<span>{part.text}</span>
424442
{/if}

DUUIWeb/src/lib/svelte/components/Popup.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
const popupWidth = autoPopupWidth ? "w-auto min-w-max" : ""
1515
</script>
1616

17-
<div class="group relative {classes}">
17+
<div class="group relative {classes}" style="display: inline;">
1818
<slot name="trigger" />
1919
{#if position === 'bottom'}
2020
<div

0 commit comments

Comments
 (0)