Skip to content

Commit d548e78

Browse files
committed
proof of concept of NER select legend
1 parent a89bfba commit d548e78

4 files changed

Lines changed: 57 additions & 8 deletions

File tree

client/src/components/tables/DocumentEntitiesTable.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ const items = computed(() =>
5151
jobEntities.map(entity => ({ ...entity, job: jobName }))
5252
)
5353
)
54-
const columns = ref<Column[]>([
55-
{ key: "label", sortOn: i => i.label },
56-
{ key: "form", sortOn: i => i.form },
57-
{ key: "count", sortOn: i => i.count },
58-
{ key: "job", sortOn: i => i.job }
54+
const columns = ref<Column<Entity>[]>([
55+
{ key: "label", sortOn: (e: Entity): string => e.label },
56+
{ key: "form", sortOn: (e: Entity): string => e.form },
57+
{ key: "count", sortOn: (e: Entity): number => e.count },
58+
{ key: "job", sortOn: (e: Entity): string => e.job }
5959
])
6060
6161
function filter(entity: Entity): boolean {

client/src/stores/evaluation/entities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { jobsEntitiesPath } from "@/api/evaluation"
22
import { useAxios } from "@/api/useAxios"
33
import stores from "@/stores"
4+
import type { JobsEntities } from "@/types/evaluation/entities"
45

56
const useEntities = defineStore("entities", () => {
67
const { corpusId } = storeToRefs(stores.useCorpora())
7-
const { loading, data: entities } = useAxios(() =>
8+
const { loading, data: entities } = useAxios<JobsEntities>(() =>
89
jobsEntitiesPath(corpusId.value)
910
)
1011

client/src/types/evaluation/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type Entity = {
22
label: string
33
form: string
44
count: number
5+
job: string
56
}
67

78
export type DocumentEntities = {

client/src/views/annotate/subviews/evaluate/subviews/EntitiesView.vue

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
<GTable class="table" :loading :items :columns sortColumn="document">
1010
<template #header>
11+
<legend class="entities-legend">
12+
<p>Legend:</p>
13+
<div>
14+
<span v-for="(job, i) in Object.keys(entities?.jobs ?? {})" :key="i">
15+
<strong>{{ i + 1 }}:</strong> {{ job }}
16+
</span>
17+
</div>
18+
</legend>
1119
<form class="filter" @submit.prevent>
1220
<fieldset>
1321
<label for="entities-select">Entities</label>
1422
<MultiSelect id="entities-select" v-model="selectedEntities" :options="entityOptions"
15-
placeholder="Select entities" :maxSelectedLabels="3" />
23+
placeholder="Select entities" :maxSelectedLabels="3" optionLabel="text"
24+
optionValue="value" />
1625
</fieldset>
1726
<fieldset>
1827
<label for="jobs-select">Jobs</label>
@@ -56,7 +65,32 @@ const selectedEntities = ref<string[]>([])
5665
const selectedJobs = ref<string[]>([])
5766
5867
// --- computed ---
59-
const entityOptions = computed(() => ["total"].concat(Object.keys(entities.value?.stddev?.stddev ?? {}).toSorted()))
68+
const entityLegend = computed(() => {
69+
if (!entities.value) return {}
70+
const legend = {}
71+
for (const [jobName, jobData] of Object.entries(entities.value.jobs)) {
72+
legend[jobName] = Object.keys(jobData.summary)
73+
}
74+
return legend
75+
})
76+
const entityOptions = computed(() => {
77+
const options = [{ text: "Total", value: "total" }]
78+
const labels = Object.keys(entities.value?.stddev?.stddev ?? {}).toSorted()
79+
for (const label of labels) {
80+
// in which indices of entittyLegend does this label occur?
81+
const occurence = []
82+
for (const [i, job] of Object.keys(entities.value.jobs).entries()) {
83+
console.log("job", job, "i", i)
84+
if (entities.value.jobs[job].summary[label] !== undefined) {
85+
occurence.push(i + 1) // +1 because we want to start from 1, not 0
86+
}
87+
}
88+
// ex.: LOC (1, 2, 3)
89+
const text = `${label} (${occurence})`
90+
options.push({ text: text, value: label })
91+
}
92+
return options
93+
})
6094
const jobOptions = computed(() => Object.keys(entities.value?.jobs ?? {}).toSorted())
6195
const items = computed<DocumentEntitiesRow[]>(() => convertJobsEntities(entities.value))
6296
const columns = computed<Column<Record<string, number>>[]>(() => {
@@ -202,4 +236,17 @@ function formatNumber(value: unknown): string | unknown {
202236
align-items: center;
203237
}
204238
}
239+
240+
.entities-legend {
241+
display: flex;
242+
flex-direction: column;
243+
gap: 0.25rem;
244+
align-items: center;
245+
246+
div {
247+
display: flex;
248+
flex-wrap: wrap;
249+
gap: 0.5rem;
250+
}
251+
}
205252
</style>

0 commit comments

Comments
 (0)