Preferred title in entries & unused fields in contents

This commit is contained in:
Simon Martens
2025-02-09 14:05:27 +01:00
parent 851de285aa
commit 1b54e0aef1
5 changed files with 62 additions and 22 deletions

View File

@@ -5,4 +5,6 @@ type Deprecated struct {
Norm string `json:"norm"` Norm string `json:"norm"`
BiblioID int `json:"biblio"` BiblioID int `json:"biblio"`
Status []string `json:"status"` Status []string `json:"status"`
Gesichtet bool `json:"gesichtet"`
Erfasst bool `json:"erfasst"`
} }

View File

@@ -1,5 +1,6 @@
package datatypes package datatypes
// INFO: use this if your key is unique
func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T { func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
m := make(map[U]T) m := make(map[U]T)
for _, v := range data { for _, v := range data {
@@ -7,3 +8,12 @@ func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
} }
return m return m
} }
// INFO: use this if your key is not unique
func MakeMultiMap[T any, U comparable](data []T, f func(T) U) map[U][]T {
m := make(map[U][]T)
for _, v := range data {
m[f(v)] = append(m[f(v)], v)
}
return m
}

View File

@@ -61,7 +61,6 @@ func partialsFields(app core.App) *core.FieldsList {
// Other discerning Information // Other discerning Information
&core.NumberField{Name: dbmodels.YEAR_FIELD, Required: false}, &core.NumberField{Name: dbmodels.YEAR_FIELD, Required: false},
&core.TextField{Name: dbmodels.EDITION_FIELD, Required: false},
// Media Information // Media Information
&core.SelectField{ &core.SelectField{
@@ -80,18 +79,6 @@ func partialsFields(app core.App) *core.FieldsList {
// Physical Description // Physical Description
&core.TextField{Name: dbmodels.EXTENT_FIELD, Required: false}, &core.TextField{Name: dbmodels.EXTENT_FIELD, Required: false},
&core.TextField{Name: dbmodels.DIMENSIONS_FIELD, Required: false}, &core.TextField{Name: dbmodels.DIMENSIONS_FIELD, Required: false},
&core.SelectField{
Name: dbmodels.MEDIA_TYPE_FIELD,
Required: false,
Values: dbmodels.MEDIA_TYPE_VALUES,
MaxSelect: len(dbmodels.MEDIA_TYPE_VALUES),
},
&core.SelectField{
Name: dbmodels.CARRIER_TYPE_FIELD,
Required: false,
Values: dbmodels.CARRIER_TYPE_VALUES,
MaxSelect: len(dbmodels.CARRIER_TYPE_VALUES),
},
// Musenalm specific data // Musenalm specific data
&core.SelectField{ &core.SelectField{
@@ -146,5 +133,4 @@ func partialsIndexes(collection *core.Collection) {
addIndex(collection, dbmodels.PLACE_STMT_FIELD, false) addIndex(collection, dbmodels.PLACE_STMT_FIELD, false)
addIndex(collection, dbmodels.PUBLICATION_STMT_FIELD, false) addIndex(collection, dbmodels.PUBLICATION_STMT_FIELD, false)
addIndex(collection, dbmodels.YEAR_FIELD, false) addIndex(collection, dbmodels.YEAR_FIELD, false)
addIndex(collection, dbmodels.EDITION_FIELD, false)
} }

View File

@@ -56,7 +56,7 @@ func init() {
wg.Wait() wg.Wait()
if records, err := seed.RecordsFromBände(app, adb.Bände, adb.Orte); err == nil { if records, err := seed.RecordsFromBände(app, *adb); err == nil {
if err = seed.BatchSave(app, records); err != nil { if err = seed.BatchSave(app, records); err != nil {
panic(err) panic(err)
} }

View File

@@ -2,6 +2,8 @@ package seed
import ( import (
"fmt" "fmt"
"slices"
"strconv"
"strings" "strings"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels" "github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
@@ -12,32 +14,35 @@ import (
func RecordsFromBände( func RecordsFromBände(
app core.App, app core.App,
entries xmlmodels.Bände, adb xmlmodels.AccessDB,
orte xmlmodels.Orte,
) ([]*core.Record, error) { ) ([]*core.Record, error) {
collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE) collection, err := app.FindCollectionByNameOrId(dbmodels.ENTRIES_TABLE)
records := make([]*core.Record, 0, len(entries.Bände)) records := make([]*core.Record, 0, len(adb.Bände.Bände))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return records, err return records, err
} }
omap := datatypes.MakeMap(orte.Orte, func(o xmlmodels.Ort) string { return o.ID }) omap := datatypes.MakeMap(adb.Orte.Orte, func(o xmlmodels.Ort) string { return o.ID })
relmap := datatypes.MakeMultiMap(
adb.Relationen_Bände_Reihen.Relationen,
func(r xmlmodels.Relation_Band_Reihe) string { return r.Band },
)
rmap := datatypes.MakeMap(adb.Reihen.Reihen, func(r xmlmodels.Reihe) string { return r.ID })
ocoll, err := app.FindCollectionByNameOrId(dbmodels.PLACES_TABLE) ocoll, err := app.FindCollectionByNameOrId(dbmodels.PLACES_TABLE)
if err != nil { if err != nil {
app.Logger().Error("Error finding collection", "error", err, "collection", dbmodels.PLACES_TABLE) app.Logger().Error("Error finding collection", "error", err, "collection", dbmodels.PLACES_TABLE)
return records, err return records, err
} }
for i := 0; i < len(entries.Bände); i++ { for i := 0; i < len(adb.Bände.Bände); i++ {
band := entries.Bände[i] band := adb.Bände.Bände[i]
record := core.NewRecord(collection) record := core.NewRecord(collection)
// TODO: Hier bevorzugter reihentitel + jahr, oder irgendein reihentitel, oder reihentitelALT // TODO: Hier bevorzugter reihentitel + jahr, oder irgendein reihentitel, oder reihentitelALT
if band.ReihentitelALT == "" { if band.ReihentitelALT == "" {
continue continue
} }
record.Set(dbmodels.PREFERRED_TITLE_FIELD, NormalizeString(band.ReihentitelALT))
record.Set(dbmodels.TITLE_STMT_FIELD, NormalizeString(band.Titelangabe)) record.Set(dbmodels.TITLE_STMT_FIELD, NormalizeString(band.Titelangabe))
record.Set(dbmodels.REFERENCES_FIELD, NormalizeString(band.Nachweis)) record.Set(dbmodels.REFERENCES_FIELD, NormalizeString(band.Nachweis))
record.Set(dbmodels.ANNOTATION_FIELD, NormalizeString(band.Anmerkungen)) record.Set(dbmodels.ANNOTATION_FIELD, NormalizeString(band.Anmerkungen))
@@ -64,6 +69,7 @@ func RecordsFromBände(
record.Set(dbmodels.EDITSTATE_FIELD, dbmodels.EDITORSTATE_VALUES[0]) record.Set(dbmodels.EDITSTATE_FIELD, dbmodels.EDITORSTATE_VALUES[0])
} }
handlePreferredTitleEntry(record, band, rmap, relmap)
handleDeprecated(record, band) handleDeprecated(record, band)
handleOrte(record, band, omap, app, ocoll) handleOrte(record, band, omap, app, ocoll)
@@ -73,6 +79,40 @@ func RecordsFromBände(
return records, nil return records, nil
} }
func handlePreferredTitleEntry(
record *core.Record,
band xmlmodels.Band,
rmap map[string]xmlmodels.Reihe,
rrelmap map[string][]xmlmodels.Relation_Band_Reihe,
) {
rels := rrelmap[band.ID]
if len(rels) == 0 {
record.Set(dbmodels.PREFERRED_TITLE_FIELD, NormalizeString(band.ReihentitelALT))
record.Set(dbmodels.EDITSTATE_FIELD, dbmodels.EDITORSTATE_VALUES[len(dbmodels.EDITORSTATE_VALUES)-2])
return
}
jahr := strconv.Itoa(band.Jahr)
if band.Jahr == 0 {
jahr = "[o.J.]"
} else {
jahr = " (" + jahr + ")"
}
bevti := slices.IndexFunc(rels, func(r xmlmodels.Relation_Band_Reihe) bool { return r.Relation == "1" })
if bevti != -1 {
bevt := rmap[rels[bevti].Reihe]
record.Set(dbmodels.PREFERRED_TITLE_FIELD, NormalizeString(bevt.Titel)+jahr)
return
}
slices.SortFunc(rels, func(a, b xmlmodels.Relation_Band_Reihe) int {
return strings.Compare(a.Relation, b.Relation)
})
record.Set(dbmodels.PREFERRED_TITLE_FIELD, NormalizeString(rmap[rels[0].Reihe].Titel)+jahr)
}
func handleOrte( func handleOrte(
record *core.Record, record *core.Record,
band xmlmodels.Band, band xmlmodels.Band,
@@ -126,6 +166,8 @@ func handleDeprecated(record *core.Record, band xmlmodels.Band) {
Norm: NormalizeString(band.Norm), Norm: NormalizeString(band.Norm),
BiblioID: band.BiblioID, BiblioID: band.BiblioID,
Status: band.Status.Value, Status: band.Status.Value,
Gesichtet: band.Gesichtet,
Erfasst: band.Erfasst,
} }
record.Set(dbmodels.MUSENALM_DEPRECATED_FIELD, depr) record.Set(dbmodels.MUSENALM_DEPRECATED_FIELD, depr)