From 4402bc6ee33399062fd52acca7e43f5010a248ff Mon Sep 17 00:00:00 2001 From: Mau Zsofia Abraham Date: Sat, 19 Oct 2024 13:22:53 +0200 Subject: [PATCH 1/8] Support multiple informants --- .../explore-samples-form-window-content.vue | 20 +++-- composables/use-tei-headers.ts | 80 +++++++++---------- types/teiCorpus.d.ts | 11 +-- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/components/explore-samples-form-window-content.vue b/components/explore-samples-form-window-content.vue index 7690567..86ac37b 100644 --- a/components/explore-samples-form-window-content.vue +++ b/components/explore-samples-form-window-content.vue @@ -95,7 +95,8 @@ const uniqueFilter = function (value: unknown, index: number, array: Array item.person.name) + .map((item) => item.person.map((i) => i.name)) + .flat() .filter(uniqueFilter) .map((item: string) => { return { label: item, value: item }; @@ -123,7 +124,8 @@ const personsFilter = computed(() => simpleItems.value .filter((item) => { if (!params.value.dataTypes.includes(item.dataType)) return false; - if (persons.value.length > 0) return persons.value.includes(item.person.name); + if (persons.value.length > 0) + return item.person.forEach((p) => persons.value.includes(p.name)); else if (places.value.length > 0) { const found = places.value.map((place) => { const p = place.split(":"); @@ -134,10 +136,16 @@ const personsFilter = computed(() => }); if (!found.includes(true)) return false; } - if (sex.value.length > 0 && !sex.value.includes(item.person.sex)) return false; - return !( - age.value[0]! > parseInt(item.person.age) || age.value[1]! < parseInt(item.person.age) - ); + if (sex.value.length > 0) { + if ( + // If none of the participants are of the given sex + !item.person.map((p) => sex.value.includes(p.sex)).includes(true) + ) + return false; + } + return item.person + .map((p) => age.value[0]! > parseInt(p.age) && age.value[1]! < parseInt(p.age)) + .includes(true); }) .map((item) => item.id), ); diff --git a/composables/use-tei-headers.ts b/composables/use-tei-headers.ts index fa10211..95d1a19 100644 --- a/composables/use-tei-headers.ts +++ b/composables/use-tei-headers.ts @@ -15,6 +15,29 @@ import dataTypes from "../config/dataTypes"; type RawTEIItems = ComputedRef>; +const extractPersons = function (item: TEI, corpusMetadata: TeiHeader | undefined) { + const corpusPersons = corpusMetadata?.profileDesc?.particDesc?.listPerson; + const results = []; + if (corpusPersons && item.teiHeader.profileDesc?.particDesc?.listPerson) { + const persons = item.teiHeader.profileDesc.particDesc.listPerson + .map((item: Person) => { + return (item["@sameAs"] ?? item.$ ?? "").replace("corpus:", ""); + }) + .filter((item: string | undefined) => item); + + for (const personId of persons) { + const person = corpusPersons.find((item: Person) => item["@id"] === personId); + if (person) + results.push({ + name: person["@id"] ?? "", + sex: person["@sex"] ?? "", + age: person["@age"] ?? "", + }); + } + } + return results; +}; + const extractMetadata = function ( item: TEI, dataType: string, @@ -30,11 +53,13 @@ const extractMetadata = function ( region: "", country: "", }, - person: { - name: "", - age: "", - sex: "", - }, + person: [ + { + name: "", + age: "", + sex: "", + }, + ], resp: "", dataType: "Text", secondaryDataType: "", @@ -42,6 +67,7 @@ const extractMetadata = function ( "@hasTEIw": "false", teiHeader: item.teiHeader, } as simpleTEIMetadata; + template.id = item["@id"] ? item["@id"] : item.teiHeader.fileDesc.publicationStmt.idno?.$ @@ -109,28 +135,8 @@ const extractMetadata = function ( if (name) template.resp = name; } + template.person = extractPersons(item, corpusMetadata); if (template.dataType === "CorpusText" && corpusMetadata) { - const corpusPersons = corpusMetadata.profileDesc?.particDesc?.listPerson; - if (corpusPersons && item.teiHeader.profileDesc?.particDesc?.listPerson) { - const persons = item.teiHeader.profileDesc.particDesc.listPerson - .map((item: Person) => { - if (!item["@sameAs"]) return; - return item["@sameAs"].replace("corpus:", ""); - }) - .filter((item: string | undefined) => item); - - const person = corpusPersons.find((item: Person) => item["@id"] === persons[0]); - if (person) { - if (person["@id"]) template.person.name = person["@id"]; - if (person["@sex"]) { - template.person.sex = person["@sex"]; - } - if (person["@age"]) { - template.person.age = person["@age"]; - } - } - } - const subtype = item.teiHeader.profileDesc?.textClass?.catRef ? item.teiHeader.profileDesc.textClass.catRef["@target"] : ""; @@ -153,19 +159,9 @@ const extractMetadata = function ( default: break; } - } else { - const person = item.teiHeader.profileDesc?.particDesc?.person; - if (person?.$) { - template.person.name = person.$; - if (person["@sex"]) { - template.person.sex = person["@sex"]; - } - if (person["@age"]) { - template.person.age = person["@age"]; - } - } } - if (template.person.name) { + + if (!template.person.at(0)?.name) { // this is true only for SHAWI data, needs to be checked in the future. template.label = template.id; } else if (item.teiHeader.fileDesc.titleStmt.titles?.at(0)?.$) { @@ -176,11 +172,13 @@ const extractMetadata = function ( if (template.dataType === "CorpusText" && item.teiHeader.fileDesc.titleStmt.titles?.at(0)) { template.label = item.teiHeader.fileDesc.titleStmt.titles[0]!.$!; } else { - template.label = template.person.name - ? template.person.name - : item.teiHeader.fileDesc.titleStmt.titles?.at(0) + if (template.person.at(0)) { + template.label = template.person[0]!.name; + } else { + template.label = item.teiHeader.fileDesc.titleStmt.titles?.at(0) ? item.teiHeader.fileDesc.titleStmt.titles[0]!.$! : template.place.settlement; + } } template["@hasTEIw"] = item["@hasTEIw"] === "true" ? "true" : "false"; diff --git a/types/teiCorpus.d.ts b/types/teiCorpus.d.ts index 83b62f0..c557492 100644 --- a/types/teiCorpus.d.ts +++ b/types/teiCorpus.d.ts @@ -1,6 +1,11 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ import type { JsonValue } from "type-fest"; +type simplePerson = { + name: string; + sex: string; + age: string; +}; export type simpleTEIMetadata = { id: string; label: string; @@ -14,11 +19,7 @@ export type simpleTEIMetadata = { country: string; region: string; }; - person: { - name: string; - sex: string; - age: string; - }; + person: Array; "@hasTEIw": string; teiHeader: TeiHeader; }; From a755fa14941997befb6776f38d827bb769045a06 Mon Sep 17 00:00:00 2001 From: Mau Zsofia Abraham Date: Sat, 19 Oct 2024 14:11:03 +0200 Subject: [PATCH 2/8] Fix sentence number issue --- .../explore-samples-form-window-content.vue | 40 ++++++++++++++++++- components/explore-samples-window-content.vue | 6 +-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/components/explore-samples-form-window-content.vue b/components/explore-samples-form-window-content.vue index 86ac37b..e25ece1 100644 --- a/components/explore-samples-form-window-content.vue +++ b/components/explore-samples-form-window-content.vue @@ -235,6 +235,27 @@ const openSearchResultsWindow = function () { }, 1000); } }; + +/** + * Open search results in new window. + */ +const openSearchResultsNewWindow = function () { + addWindow({ + targetType: "ExploreSamples", + params: resultWindowParams.value, + title: `Search results for ${[words.value.join(","), places.value.join(",")].join(", ")}`, + } as WindowState)!; + addWindow({ + targetType: "WMap", + params: { + title: "Search results", + queryString: "", + endpoint: "compare_markers", + queryParams: queryParams.value, + }, + title: `${params.value.dataTypes[0]}s for ${[words.value.join(","), places.value.join(",")].join(", ")}`, + } as WindowState)!; +}; diff --git a/components/explore-samples-window-content.vue b/components/explore-samples-window-content.vue index 553c897..d62276a 100644 --- a/components/explore-samples-window-content.vue +++ b/components/explore-samples-window-content.vue @@ -9,7 +9,7 @@ const props = defineProps(); const { params } = toRefs(props); const content: Ref = ref(); const tooltip: Ref = ref(null); - +console.log(params); const { simpleItems } = useTEIHeaders(); const filters: Array<"region" | "settlement"> = ["region", "settlement"]; @@ -28,14 +28,14 @@ const ids = computed(() => { }) .filter((item) => { if (params.value.person) { - return params.value.person === item.person.name; + return item.person.map((p) => p.name).includes(params.value.person); } else return true; }) .map((item) => item.id) .join(","); }); -const features: Ref> = ref([]); +const features: Ref> = ref(params.value.features?.split(",") ?? []); const page: Ref = ref(1); watch(params, (value) => { From 5a7ef397b2ac182d0524e7308f2dfd520be6a83b Mon Sep 17 00:00:00 2001 From: Mau Zsofia Abraham Date: Sat, 19 Oct 2024 14:50:19 +0200 Subject: [PATCH 3/8] Support array persons, add number of result --- components/data-list-window-content.vue | 6 +++++- components/data-table-window-content.vue | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/components/data-list-window-content.vue b/components/data-list-window-content.vue index 2773026..d7b2c74 100644 --- a/components/data-list-window-content.vue +++ b/components/data-list-window-content.vue @@ -52,13 +52,17 @@ const debugString = debug ? JSON.stringify(groupedItems, null, 2) : "";

Unspecified country

-

{{ region }}

+

+ {{ region }} + ({{ Object.values(itemsByPlace).flat(2).length }}) +

Unspecified region

{{ place.replace(/^zzz_/, "") }} + ({{ Object.values(itemsBydataType).flat().length }})
Unspecified place
diff --git a/components/data-table-window-content.vue b/components/data-table-window-content.vue index 5d1e5fc..fa436cf 100644 --- a/components/data-table-window-content.vue +++ b/components/data-table-window-content.vue @@ -26,13 +26,13 @@ const items = computed(() => { }); const columns = ref([ - columnHelper.accessor((row) => row.person.name, { + columnHelper.accessor((row) => row.person.at(0)?.name, { id: "label", cell: (info) => { const identifier = info.getValue() + - (info.row.original.person.sex ? `/${info.row.original.person.sex}` : "") + - (info.row.original.person.age ? `/${info.row.original.person.age}` : ""); + (info.row.original.person.at(0)?.sex ? `/${info.row.original.person.at(0)?.sex}` : "") + + (info.row.original.person.at(0)?.age ? `/${info.row.original.person.at(0)?.age}` : ""); let linked_id: string | undefined = undefined; let linked_type: string | undefined = undefined; if (info.row.original.secondaryDataType === "Sample Text") { @@ -43,7 +43,10 @@ const columns = ref([ if (linked_type) { linked_id = simpleItems.value.find((i) => { - return i.dataType === linked_type && i.person.name === info.row.original.person.name; + return ( + i.dataType === linked_type && + i.person.at(0)?.name === info.row.original.person.at(0)?.name + ); })?.id; } return linked_id @@ -61,20 +64,20 @@ const columns = ref([ header: "Name", footer: (props) => props.column.id, }), - columnHelper.accessor((row) => row.person.name, { + columnHelper.accessor((row) => row.person.at(0)?.name, { id: "name", cell: (info) => info.getValue(), header: "Name", footer: (props) => props.column.id, }), - columnHelper.accessor((row) => row.person.age, { + columnHelper.accessor((row) => row.person.at(0)?.age, { id: "age", cell: (info) => info.getValue(), header: "Age", footer: (props) => props.column.id, filterFn: "inNumberRange", }), - columnHelper.accessor((row) => row.person.sex, { + columnHelper.accessor((row) => row.person.at(0)?.sex, { id: "sex", cell: (info) => info.getValue(), header: "Sex", @@ -139,8 +142,9 @@ const setFilters = function (value: ColumnFiltersState) {