Search Index Build

This commit is contained in:
Simon Martens
2025-02-17 21:42:20 +01:00
parent d109f7a040
commit fd2fa157b2
18 changed files with 611 additions and 16 deletions

View File

@@ -3,6 +3,11 @@ package xmlmodels
import (
"encoding/json"
"encoding/xml"
"strings"
)
const (
AGENT_TYPE = "agent"
)
type Agent struct {
@@ -24,3 +29,21 @@ func (a Agent) String() string {
data, _ := json.MarshalIndent(a, "", " ")
return string(data)
}
func (a Agent) Readable(_ *Library) map[string]interface{} {
ret := map[string]interface{}{
"ID": a.ID,
"Names": strings.Join(a.Names, "; "),
"Life": a.Life,
}
for k, v := range a.AnnotationNote.Readable() {
ret[k] = v
}
return ret
}
func (a Agent) Type() string {
return AGENT_TYPE
}

View File

@@ -3,6 +3,11 @@ package xmlmodels
import (
"encoding/json"
"encoding/xml"
"strings"
)
const (
CATEGORY_TYPE = "category"
)
type Category struct {
@@ -21,3 +26,20 @@ func (c Category) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
func (c Category) Readable(_ *Library) map[string]interface{} {
ret := map[string]interface{}{
"ID": c.ID,
"Names": strings.Join(c.Names, "; "),
}
for k, v := range c.AnnotationNote.Readable() {
ret[k] = v
}
return ret
}
func (c Category) Type() string {
return CATEGORY_TYPE
}

View File

@@ -3,6 +3,7 @@ package xmlmodels
import (
"encoding/xml"
"errors"
"strings"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/xsdtime"
)
@@ -38,6 +39,24 @@ type AnnotationNote struct {
Notes []Note `xml:"vermerk"`
}
func (an AnnotationNote) Readable() map[string]interface{} {
ret := make(map[string]interface{})
annnotations := make([]string, len(an.Annotations))
for _, a := range an.Annotations {
annnotations = append(annnotations, a.Chardata)
}
ret["Annotations"] = strings.Join(annnotations, "; ")
nots := make([]string, len(an.Notes))
for _, n := range an.Notes {
nots = append(nots, n.Chardata)
}
ret["Notes"] = strings.Join(nots, "; ")
return ret
}
type Annotation struct {
XMLName xml.Name `xml:"anmerkung"`
Value
@@ -57,7 +76,7 @@ type Identifier struct {
func (i Identifier) Keys() []string {
if len(i.keys) == 0 {
i.keys = append(i.keys, i.ID)
i.keys = []string{i.ID}
}
return i.keys
}
@@ -69,6 +88,19 @@ type Reference struct {
Inner Inner
}
func (r Reference) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
if r.Category != "" {
cat := lib.Categories.Item(r.Category)
if cat != nil {
data["ReferenceCategory"] = cat.Names
}
}
data["ReferenceComment"] = r.Inner.InnerXML
return data
}
type Value struct {
Chardata string `xml:",chardata"`
}

View File

@@ -6,6 +6,10 @@ import (
"strconv"
)
const (
ISSUE_TYPE = "issue"
)
type Issue struct {
XMLName xml.Name `xml:"stueck"`
Number Nummer `xml:"nummer"`
@@ -57,3 +61,22 @@ func (i Issue) String() string {
data, _ := json.MarshalIndent(i, "", " ")
return string(data)
}
func (i Issue) Readable(_ *Library) map[string]interface{} {
ret := map[string]interface{}{
"ID": i.ID,
"Number": i.Number.No,
"Year": i.Datum.When.Year,
"Date": i.Datum.When.String(),
}
for k, v := range i.AnnotationNote.Readable() {
ret[k] = v
}
return ret
}
func (i Issue) Type() string {
return ISSUE_TYPE
}

View File

@@ -10,6 +10,10 @@ import (
"github.com/google/uuid"
)
const (
PIECES_CATEGORY = "piece"
)
type Piece struct {
XMLName xml.Name `xml:"beitrag"`
IssueRefs []IssueRef `xml:"stueck"`
@@ -39,13 +43,14 @@ func (p Piece) Keys() []string {
return p.keys
}
ret := make([]string, 2)
ret := make([]string, 0, 3)
if p.ID != "" {
ret = append(ret, p.ID)
}
// TODO: sensible IDs
uid := uuid.New()
ret = append(ret, uid.String())
for _, i := range p.IssueRefs {
ret = append(ret, strconv.Itoa(i.When.Year)+"-"+strconv.Itoa(i.Nr)+"-"+uid.String())
@@ -212,3 +217,49 @@ func (p Piece) ReferencesWork(id string) (*WorkRef, bool) {
}
return nil, false
}
func (p Piece) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
data["Title"] = p.Title
data["Incipit"] = p.Incipit
for k, v := range p.AnnotationNote.Readable() {
data[k] = v
}
agents := make([]map[string]interface{}, len(p.AgentRefs))
for k, v := range p.AgentRefs {
agents[k] = v.Readable(lib)
}
data["Agents"] = agents
works := make([]map[string]interface{}, len(p.WorkRefs))
for k, v := range p.WorkRefs {
works[k] = v.Readable(lib)
}
data["Works"] = works
places := make([]map[string]interface{}, len(p.PlaceRefs))
for k, v := range p.PlaceRefs {
places[k] = v.Readable(lib)
}
data["Places"] = places
categories := make([]map[string]interface{}, len(p.CategoryRefs))
for k, v := range p.CategoryRefs {
categories[k] = v.Readable(lib)
}
data["Categories"] = categories
issuerefs := make([]map[string]interface{}, len(p.IssueRefs))
for k, v := range p.IssueRefs {
issuerefs[k] = v.Readable(lib)
}
data["Issues"] = issuerefs
return data
}
func (p Piece) Type() string {
return PIECES_CATEGORY
}

View File

@@ -5,6 +5,10 @@ import (
"encoding/xml"
)
const (
PLACE_TYPE = "place"
)
type Place struct {
XMLName xml.Name `xml:"ort"`
Names []string `xml:"name"`
@@ -22,3 +26,20 @@ func (p Place) String() string {
data, _ := json.MarshalIndent(p, "", " ")
return string(data)
}
func (p Place) Readable(_ *Library) map[string]interface{} {
ret := map[string]interface{}{
"ID": p.ID,
"Names": p.Names,
}
for k, v := range p.AnnotationNote.Readable() {
ret[k] = v
}
return ret
}
func (p Place) Type() string {
return PLACE_TYPE
}

View File

@@ -1,6 +1,9 @@
package xmlmodels
import "encoding/xml"
import (
"encoding/xml"
"strconv"
)
type AgentRef struct {
XMLName xml.Name `xml:"akteur"`
@@ -12,6 +15,19 @@ func (ar AgentRef) Name() string {
return x.Name()
}
func (ar AgentRef) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
agent := lib.Agents.Item(ar.Ref)
if agent != nil {
data["AgentNames"] = agent.Names
}
for k, v := range ar.Reference.Readable(lib) {
data[k] = v
}
return data
}
type IssueRef struct {
XMLName xml.Name `xml:"stueck"`
Nr int `xml:"nr,attr"`
@@ -22,6 +38,25 @@ type IssueRef struct {
Reference // Nicht im Schema
}
func (ir IssueRef) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
if ir.When.Year != 0 {
data["IssueYear"] = ir.When.Year
} else {
return data
}
issuekey := strconv.Itoa(ir.When.Year) + "-" + strconv.Itoa(ir.Nr)
issue := lib.Issues.Item(issuekey)
if issue != nil {
data["IssueDate"] = issue.Datum.When.String()
}
data["IssueNumber"] = ir.Nr
return data
}
func (ir IssueRef) Name() string {
var x Issue
return x.Name()
@@ -32,6 +67,19 @@ type PlaceRef struct {
Reference
}
func (pr *PlaceRef) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
place := lib.Places.Item(pr.Ref)
if place != nil {
data["PlaceNames"] = place.Names
}
for k, v := range pr.Reference.Readable(lib) {
data[k] = v
}
return data
}
func (pr PlaceRef) Name() string {
var x Place
return x.Name()
@@ -47,12 +95,45 @@ func (cr CategoryRef) Name() string {
return x.Name()
}
func (cr CategoryRef) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
cat := lib.Categories.Item(cr.Ref)
if cat != nil {
data["CategoryNames"] = cat.Names
}
for k, v := range cr.Reference.Readable(lib) {
data[k] = v
}
return data
}
type WorkRef struct {
XMLName xml.Name `xml:"werk"`
Page string `xml:"s,attr"`
Reference
}
func (wr WorkRef) Readable(lib *Library) map[string]interface{} {
data := make(map[string]interface{})
work := lib.Works.Item(wr.Ref)
if work != nil {
data["WorkTitle"] = work.Citation.Title
data["WorkYear"] = work.Citation.Year
data["WorkPreferredTitle"] = work.PreferredTitle
prefs := make([]map[string]interface{}, len(work.AgentRefs))
for k, v := range work.AgentRefs {
prefs[k] = v.Readable(lib)
}
data["WorkAgents"] = prefs
}
for k, v := range wr.Reference.Readable(lib) {
data[k] = v
}
return data
}
func (wr WorkRef) Name() string {
var x Work
return x.Name()

View File

@@ -7,6 +7,10 @@ import (
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
)
const (
WORKS_CATEGORY = "work"
)
type Work struct {
XMLName xml.Name `xml:"werk"`
URLs []URL `xml:"url"`
@@ -49,3 +53,30 @@ func (w Work) String() string {
data, _ := json.MarshalIndent(w, "", " ")
return string(data)
}
func (w Work) Readable(lib *Library) map[string]interface{} {
ret := map[string]interface{}{
"ID": w.ID,
"PreferredTitle": w.PreferredTitle,
"Title": w.Citation.Title,
"Year": w.Citation.Year,
"CitationTitle": w.Citation.Title,
}
for k, v := range w.AnnotationNote.Readable() {
ret[k] = v
}
agents := make([]map[string]interface{}, len(w.AgentRefs))
for k, v := range w.AgentRefs {
agents[k] = v.Readable(lib)
}
ret["Agents"] = agents
return ret
}
func (w Work) Type() string {
return WORKS_CATEGORY
}