Skip to content

Commit

Permalink
fix annotation head for upos
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinsINT committed Nov 18, 2024
1 parent 604cb31 commit 6352c33
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/src/main/kotlin/org/ivdnt/galahad/data/layer/Term.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ data class Term(
return annotation.split('-')[1]
}
}
// for POS
else if (annotationType == AnnotationType.POS) {
// for POS & UPOS
else if (listOf(AnnotationType.POS, AnnotationType.UPOS).contains(annotationType)) {
return if (isMulti(annotationType)) {
// Split on + and transform each part
annotation.split("+").map { singlePosToHead(it) }.joinToString("+")
Expand Down
45 changes: 40 additions & 5 deletions server/src/test/kotlin/org/ivdnt/galahad/data/layer/TermTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,60 @@ class TermTest {
)
)

private val multiPos = Term("", "PD(type=art)+NOU-C(num=sg)", mutableListOf())
private val singlePos = Term("", "NOU-C(num=sg)", mutableListOf())
private val headOnlyPos = Term("", "NOU-C", mutableListOf())
// upos
private val singleUPos = Term(
mapOf(
AnnotationType.UPOS to "NOU-C(num=sg)"
), mutableListOf()
)

// ner
private val singleNer = Term(
mapOf(
AnnotationType.NER to "B-LOC"
), mutableListOf()
)

// pos
private val singlePos = Term(
mapOf(
AnnotationType.POS to "NOU-C(num=sg)"
), mutableListOf()
)

private val multiPos = Term(
mapOf(
AnnotationType.POS to "PD(type=art)+NOU-C(num=sg)"
), mutableListOf()
)

private val headOnlyPos = Term(
mapOf(
AnnotationType.POS to "NOU-C"
), mutableListOf()
)


@Test
fun `PoS head and features`() {
// single pos
assertEquals("NOU-C", singlePos.annotationHead(AnnotationType.POS))
assertEquals("num=sg", Term.features(singlePos.pos))
assertEquals("num=sg", Term.features(singlePos.annotations.pos))

// upos
assertEquals("NOU-C", singleUPos.annotationHead(AnnotationType.UPOS))
assertEquals("num=sg", Term.features(singleUPos.annotations.upos))

// ner
assertEquals("LOC", singleNer.annotationHead(AnnotationType.NER))

// multi pos
assertEquals("PD+NOU-C", multiPos.annotationHead(AnnotationType.POS))
// no features for now...

// head only pos
assertEquals("NOU-C", headOnlyPos.annotationHead(AnnotationType.POS))
assertEquals(null, Term.features(headOnlyPos.pos))
assertEquals(null, Term.features(headOnlyPos.annotations.pos))
}

@Test
Expand Down

0 comments on commit 6352c33

Please sign in to comment.