Skip to content

Commit 93bab3c

Browse files
committed
Added number of annotations in summary
1 parent 826f74e commit 93bab3c

14 files changed

Lines changed: 76 additions & 48 deletions

File tree

client/src/components/tables/DocumentsTable.vue

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
<template v-else> This corpus is empty. </template>
1919
</template>
2020

21-
<template #cell-layerSummary="data: TableData<DocumentMetadata>">
21+
<template #cell-summary="data: TableData<DocumentMetadata>">
2222
<RightFloatCell>
2323
<template #left>
24-
{{ data.value.tokens }}
24+
{{ data.value.annotations.token }}
2525
</template>
2626
<template #right>
27-
<InspectButton v-if="data.value.tokens > 0" @click="previewDocument = data.item" />
27+
<InspectButton v-if="data.value.annotations.token > 0" @click="previewDocument = data.item" />
2828
</template>
2929
</RightFloatCell>
3030
</template>
3131

3232
<template #cell-actions="data: TableData<DocumentMetadata>">
33-
<div class="actions">
33+
<GForm gap=".25rem">
3434
<DownloadButton @click="downloadRaw(data.item.name)" />
3535

3636
<GButton red title="Delete" @click="deleteDocumentData = data.item">
3737
<i class="fa fa-trash"></i>
3838
</GButton>
39-
</div>
39+
</GForm>
4040
</template>
4141
</GTable>
4242

@@ -79,21 +79,15 @@ const previewDocument = ref<DocumentMetadata>()
7979
const columns = computed<Column<DocumentMetadata>[]>(() => [
8080
{ key: "name" },
8181
{ key: "format" },
82-
{ key: "preview" },
82+
{ key: "text" },
8383
{
84-
key: "layerSummary",
84+
key: "summary",
8585
label: "tokens",
8686
align: "right",
87-
sortOn: (d: DocumentMetadata): number => d.layerSummary?.tokens,
87+
sortOn: (d: DocumentMetadata): number => d.summary?.annotations.token,
8888
},
8989
{ key: "modified", format: (d: DocumentMetadata): string => formatDate(d.modified) },
9090
{ key: "actions", noSort: true, hidden: !canWrite || type === DocsTableType.dataset },
9191
])
9292
</script>
9393

94-
<style scoped lang="scss">
95-
.actions {
96-
display: flex;
97-
gap: 0.25rem;
98-
}
99-
</style>

client/src/components/tables/LayerViewer.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<template>
22
<GTable :columns :items>
33
<template #title>Annotations preview</template>
4-
<template #help>Here you can see a preview of the annotations.</template>
4+
<template #header>
5+
<dl>
6+
<dl v-for="[key, value] in Object.entries(summary.annotations)" :key="key">
7+
<dt>{{ key }}:</dt>
8+
<dd>{{ value }}</dd>
9+
</dl>
10+
</dl>
11+
</template>
512
</GTable>
613
</template>
714

@@ -13,8 +20,23 @@ import type { Job } from "@/types/jobs"
1320
const { document, job } = defineProps<{ document?: DocumentMetadata; job?: Job }>()
1421
1522
// #computed
23+
const summary = computed(() => (document ? document.summary : job.summary))
1624
const annotations = computed(() => (document ? document.annotations : job.tagger.annotations))
1725
const columns = computed(() => annotations.value.map((i) => ({ key: i, label: i })))
18-
const terms = computed(() => (document ? document.layerPreview.terms : job.preview.terms))
26+
const terms = computed(() => (document ? document.preview.terms : job.preview.terms))
1927
const items = computed(() => terms.value.map((t) => t.annotations))
2028
</script>
29+
30+
<style scoped lang="scss">
31+
dl {
32+
display: flex;
33+
gap: 1rem;
34+
> dl {
35+
display: inline-flex;
36+
gap: 0.25rem;
37+
> dt {
38+
font-weight: bold;
39+
}
40+
}
41+
}
42+
</style>

client/src/stores/documents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const documents = defineStore("documents", () => {
3131
[],
3232
)
3333

34-
const numSourceAnnotations = computed(() => documents.value.filter((i) => i.layerSummary?.tokens > 0).length)
34+
const numSourceAnnotations = computed(() => documents.value.filter((i) => i.summary?.tokens > 0).length)
3535
const uploading: Record<string, FileStatus> = reactive({})
3636
const uploadBusyCount = computed(() => Object.values(uploading).filter((i) => i.status === "busy").length)
3737
const uploadErrorCount = computed(() => Object.values(uploading).filter((i) => i.status === "error").length)

client/src/types/documents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export type Format = (typeof Format)[keyof typeof Format]
1515
export type DocumentMetadata = {
1616
name: string
1717
format: Format
18-
preview: string
19-
layerPreview: LayerPreview
20-
layerSummary: LayerSummary
18+
text: string
19+
preview: LayerPreview
20+
summary: LayerSummary
2121
modified: number
2222
annotations: string[]
2323
}

client/src/types/jobs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ export type Progress = {
2525

2626
export type LayerPreview = { terms: Term[] }
2727

28-
export type LayerSummary = { tokens: number }
28+
export type LayerSummary = { annotations: Record<string, number> }

client/src/views/annotate/subviews/JobsView.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,22 @@ const columns = computed<Column<Job>[]>((): Column<Job>[] => [
106106
{ key: "id", label: "tagger", sortOn: (j: Job): string => j.tagger.id, align: "left" },
107107
{ key: "tagset", sortOn: (j: Job): string => j.tagger.tagset, format: (j: Job): string => j.tagger.tagset },
108108
{ key: "language", sortOn: (j: Job): string => j.tagger.language, format: (j: Job): string => j.tagger.language },
109+
{
110+
key: "period",
111+
sortOn: (j: Job): string => `${j.tagger.eraFrom} ${j.tagger.eraTo}`,
112+
format: (j: Job): string => `${j.tagger.eraFrom} – ${j.tagger.eraTo}`,
113+
},
109114
{
110115
key: "annotations",
111116
format: (j: Job): string => j.tagger.annotations.join(", "),
112117
sortOn: (j: Job): string => j.tagger.annotations.join(),
113118
},
114119
{
115-
key: "tokens",
120+
key: "summary",
121+
label: "tokens",
116122
align: "right",
117-
sortOn: (j: Job): number => j.summary.tokens,
118-
format: (j: Job): number => j.summary.tokens,
119-
},
120-
{
121-
key: "period",
122-
sortOn: (j: Job): string => `${j.tagger.eraFrom} ${j.tagger.eraTo}`,
123-
format: (j: Job): string => `${j.tagger.eraFrom} – ${j.tagger.eraTo}`,
123+
sortOn: (j: Job): number => j.summary.annotations.token,
124+
format: (j: Job): number => j.summary.annotations.token ?? 0,
124125
},
125126
{ key: "modified", align: "center", format: (j: Job): string => formatDate(j.modified) },
126127
{ key: "progress", align: "right", sortOn: (j: Job): number => j.progress.finished / j.progress.total },

server/src/main/kotlin/org/ivdnt/galahad/annotations/Layer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Layer(
2727
}
2828

2929
@get:JsonIgnore
30-
val summary: LayerSummary by lazy { LayerSummary(tokens = terms.count()) }
30+
val summary: LayerSummary by lazy { LayerSummary(terms.asIterable()) }
3131

3232
@get:JsonIgnore
3333
val preview: LayerPreview by lazy { LayerPreview(terms.take(LAYER_PREVIEW_LENGTH).toList()) }

server/src/main/kotlin/org/ivdnt/galahad/annotations/LayerPreview.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.ivdnt.galahad.annotations
22

33
/**
44
* The minimum length in chars of a [LayerPreview].
5-
* If the limit ends halfway a word, we incorporate the entire word.
65
*/
76
const val LAYER_PREVIEW_LENGTH: Int = 15
87

server/src/main/kotlin/org/ivdnt/galahad/annotations/LayerSummary.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ package org.ivdnt.galahad.annotations
44
* Stores the size of the [Layer] in terms of number of [WordForm], [Term], lemma and pos.
55
*/
66
data class LayerSummary(
7-
val tokens: Int,
8-
)
7+
val annotations: Map<Annotation, Int>,
8+
) {
9+
constructor(terms: Iterable<Term>) : this(
10+
annotations = terms.flatMap { it.annotations.keys }.groupingBy { it }.eachCount()
11+
)
12+
13+
companion object {
14+
val EMPTY: LayerSummary = LayerSummary(emptyMap())
15+
}
16+
}
917

1018
operator fun LayerSummary.plus(b: LayerSummary): LayerSummary {
1119
return LayerSummary(
12-
tokens = this.tokens + b.tokens,
20+
annotations = this.annotations.toMutableMap().also {
21+
b.annotations.forEach { (annotation, count) ->
22+
it.merge(annotation, count, Integer::sum)
23+
}
24+
}
1325
)
1426
}

server/src/main/kotlin/org/ivdnt/galahad/documents/DocumentMetadata.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ data class DocumentMetadata(
1515
/** Number of alphabetic chars in the parsed plaintext. */
1616
val numAlphabeticChars: Int,
1717
/** A truncated preview of the parsed plaintext. */
18-
val preview: String,
18+
val text: String,
1919
/** A truncated preview of the annotated layer. */
20-
val layerPreview: LayerPreview,
20+
val preview: LayerPreview,
2121
/** Some statistics about the source annotations, if present */
22-
val layerSummary: LayerSummary,
22+
val summary: LayerSummary,
2323
/** Last modified timestamp in milliseconds. */
2424
val modified: Long,
2525
/** Annotation types in the source layer. */
@@ -35,9 +35,9 @@ data class DocumentMetadata(
3535
format = file.format,
3636
numChars = text.length,
3737
numAlphabeticChars = text.filter { it.isLetter() }.length,
38-
preview = text.take(PREVIEW_LENGTH) + if (text.length > PREVIEW_LENGTH) "..." else "",
39-
layerPreview = file.layer.preview,
40-
layerSummary = file.layer.summary,
38+
text = text.take(PREVIEW_LENGTH) + if (text.length > PREVIEW_LENGTH) "..." else "",
39+
preview = file.layer.preview,
40+
summary = file.layer.summary,
4141
modified = System.currentTimeMillis(),
4242
annotations = Annotation.order(file.layer.terms.flatMap { it.annotations.keys }.toList())
4343
)

0 commit comments

Comments
 (0)