Skip to content

Commit 724a104

Browse files
committed
remove layersummary in favor of annotation count map
1 parent 360160d commit 724a104

9 files changed

Lines changed: 28 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Layer(
3131
val annotations: Set<Annotation> by lazy { Annotation.order(terms.flatMap { it.annotations.keys }.asIterable()) }
3232

3333
@get:JsonIgnore
34-
val summary: LayerSummary by lazy { LayerSummary(terms.asIterable()) }
34+
val summary: LayerAnnotations by lazy { LayerAnnotations(terms.asIterable()) }
3535

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

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package org.ivdnt.galahad.annotations
22

3+
import com.fasterxml.jackson.annotation.JsonValue
4+
35
/**
46
* Stores the size of the [Layer] in terms of number of [WordForm], [Term], lemma and pos.
57
*/
6-
data class LayerSummary(
8+
data class LayerAnnotations(
9+
@JsonValue
710
val annotations: Map<Annotation, Int>,
811
) {
912
constructor(terms: Iterable<Term>) : this(
1013
annotations = terms.flatMap { it.annotations.keys }.groupingBy { it }
1114
.eachCount().toSortedMap { a, b -> Annotation.entries.indexOf(a).compareTo(Annotation.entries.indexOf(b)) })
1215

1316
companion object {
14-
val EMPTY: LayerSummary = LayerSummary(emptyMap())
17+
val EMPTY: LayerAnnotations = LayerAnnotations(emptyMap())
1518
}
1619
}
1720

18-
operator fun LayerSummary.plus(b: LayerSummary): LayerSummary {
19-
return LayerSummary(
21+
operator fun LayerAnnotations.plus(b: LayerAnnotations): LayerAnnotations {
22+
return LayerAnnotations(
2023
annotations = this.annotations.toMutableMap().also {
2124
b.annotations.forEach { (annotation, count) ->
2225
it.merge(annotation, count, Integer::sum)

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.ivdnt.galahad.documents
22

3+
import com.fasterxml.jackson.annotation.JsonIgnore
34
import org.ivdnt.galahad.annotations.Annotation
45
import org.ivdnt.galahad.annotations.LayerPreview
5-
import org.ivdnt.galahad.annotations.LayerSummary
6+
import org.ivdnt.galahad.annotations.LayerAnnotations
67
import org.ivdnt.galahad.formats.InternalFile
78

89
data class DocumentMetadata(
@@ -15,12 +16,14 @@ data class DocumentMetadata(
1516
/** A truncated preview of the annotated layer. */
1617
val preview: LayerPreview,
1718
/** Some statistics about the source annotations, if present */
18-
val summary: LayerSummary,
19+
val annotations: LayerAnnotations,
1920
/** Last modified timestamp in milliseconds. */
2021
val modified: Long,
21-
/** Annotation types in the source layer. */
22-
val annotations: Set<Annotation>,
2322
) {
23+
@get:JsonIgnore
24+
val annotationSet: List<Annotation>
25+
get() = annotations.annotations.map { it.key }
26+
2427
companion object {
2528
private const val PREVIEW_LENGTH: Int = 100
2629

@@ -31,9 +34,8 @@ data class DocumentMetadata(
3134
format = file.format,
3235
text = text.take(PREVIEW_LENGTH) + if (text.length > PREVIEW_LENGTH) "..." else "",
3336
preview = file.layer.preview,
34-
summary = file.layer.summary,
37+
annotations = file.layer.summary,
3538
modified = System.currentTimeMillis(),
36-
annotations = file.layer.annotations
3739
)
3840
}
3941
}

server/src/main/kotlin/org/ivdnt/galahad/formats/folia/FoliaWriter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class FoliaWriter(export: DocumentExport) : LayerWriter(export) {
8484
}
8585

8686
val containsDeprel: Boolean = if (export.tagger.id == SOURCE_LAYER_NAME) {
87-
Annotation.DEPREL in export.document.metadata.annotations
87+
Annotation.DEPREL in export.document.metadata.annotationSet
8888
} else {
8989
Annotation.DEPREL in export.tagger.annotationSet
9090
}

server/src/main/kotlin/org/ivdnt/galahad/jobs/JobMetadata.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.ivdnt.galahad.jobs
22

33
import org.ivdnt.galahad.annotations.LayerPreview
4-
import org.ivdnt.galahad.annotations.LayerSummary
4+
import org.ivdnt.galahad.annotations.LayerAnnotations
55
import org.ivdnt.galahad.annotations.SOURCE_LAYER_NAME
66
import org.ivdnt.galahad.annotations.plus
77
import org.ivdnt.galahad.taggers.Tagger
@@ -13,15 +13,15 @@ class JobMetadata(
1313
val tagger: Tagger,
1414
val progress: Progress,
1515
val preview: LayerPreview,
16-
val summary: LayerSummary,
16+
val annotations: LayerAnnotations,
1717
var modified: Long,
1818
) {
1919
companion object {
2020
fun create(job: Job): JobMetadata {
2121
val djs = job.results.readAll()
2222
// sum up the number of tokens/lemmas/etc of all documents
23-
val summary: LayerSummary =
24-
djs.mapNotNull { it.layer?.summary }.reduceOrNull { a, b -> a + b } ?: LayerSummary.EMPTY
23+
val summary: LayerAnnotations =
24+
djs.mapNotNull { it.layer?.summary }.reduceOrNull { a, b -> a + b } ?: LayerAnnotations.EMPTY
2525
// Preview of the resulting terms of this job.
2626
// Show the first preview of the first document that isn't LayerPreview.EMPTY.
2727
val preview = djs.firstNotNullOfOrNull { it.layer?.preview } ?: LayerPreview.EMPTY
@@ -38,7 +38,7 @@ class JobMetadata(
3838
tagger = tagger,
3939
progress = job.progress,
4040
preview = preview,
41-
summary = summary,
41+
annotations = summary,
4242
modified = System.currentTimeMillis()
4343
)
4444
}

server/src/main/kotlin/org/ivdnt/galahad/jobs/Jobs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.ivdnt.galahad.jobs
22

33
import org.ivdnt.galahad.annotations.LayerPreview
4-
import org.ivdnt.galahad.annotations.LayerSummary
4+
import org.ivdnt.galahad.annotations.LayerAnnotations
55
import org.ivdnt.galahad.annotations.SOURCE_LAYER_NAME
66
import org.ivdnt.galahad.corpora.Corpus
77
import org.ivdnt.galahad.exceptions.JobNotFoundException
@@ -51,7 +51,7 @@ class Jobs(
5151
// Create a map of all taggers with empty metadata
5252
val numDocs = corpus.immutableMetadata.numDocs
5353
val allJobs = Tagger.taggers.mapValues {
54-
JobMetadata(it.value, Progress(numDocs), LayerPreview.EMPTY, LayerSummary.EMPTY, 0)
54+
JobMetadata(it.value, Progress(numDocs), LayerPreview.EMPTY, LayerAnnotations.EMPTY, 0)
5555
}
5656
// replace the entries for which a job exists
5757
val jobs = readAll().map { it.metadata }.associateBy { it.tagger.id }

server/src/main/kotlin/org/ivdnt/galahad/taggers/Tagger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Tagger(
8989

9090
fun createSourceTagger(corpus: Corpus): Tagger {
9191
val metadata = corpus.immutableMetadata
92-
val produces = corpus.documents.readAll().flatMap { it.metadata.annotations }.toSet()
92+
val produces = corpus.documents.readAll().flatMap { it.metadata.annotationSet }.toSet()
9393
return Tagger(
9494
id = SOURCE_LAYER_NAME,
9595
description = "uploaded annotations",

server/src/test/kotlin/org/ivdnt/galahad/documents/DocumentMetadataTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.ivdnt.galahad.documents
22

33
import org.ivdnt.galahad.annotations.Annotation
44
import org.ivdnt.galahad.corpora.Corpus
5-
import org.ivdnt.galahad.documents.DocumentFormat
65
import org.ivdnt.galahad.util.TestUtil
76
import org.junit.jupiter.api.Test
87

@@ -27,7 +26,7 @@ class DocumentMetadataTest {
2726
assertEquals("input.txt", meta.name)
2827
assertEquals(DocumentFormat.Txt, meta.format)
2928
assertEquals(plaintext, meta.text) // This works because the preview is < MAX_PREVIEW_LENGTH
30-
val total = meta.summary.annotations[Annotation.TOKEN]
29+
val total = meta.annotations.annotations[Annotation.TOKEN]
3130
assertEquals(0, total)
3231
}
3332

@@ -40,7 +39,7 @@ class DocumentMetadataTest {
4039
assertEquals("input.tei.xml", meta.name)
4140
assertEquals(DocumentFormat.TeiP5, meta.format)
4241
assertEquals(plaintext, meta.text) // This works because the preview is < MAX_PREVIEW_LENGTH
43-
val total = meta.summary.annotations[Annotation.TOKEN]
42+
val total = meta.annotations.annotations[Annotation.TOKEN]
4443
assertEquals(21, total)
4544
}
4645
}

server/src/test/kotlin/org/ivdnt/galahad/jobs/JobTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class JobTest {
3030
// verify from state cache
3131
assertEquals(LayerPreview.EMPTY, job.metadata.preview)
3232
assertEquals(0, job.metadata.progress.total)
33-
assertEquals(0, job.metadata.summary.annotations[Annotation.TOKEN])
33+
assertEquals(0, job.metadata.annotations.annotations[Annotation.TOKEN])
3434
}
3535

3636
@Test

0 commit comments

Comments
 (0)