Finalized resolver

This commit is contained in:
Simon Martens
2025-01-03 18:57:22 +01:00
parent e6a77ab557
commit 9ca2ebb75f
10 changed files with 225 additions and 64 deletions

View File

@@ -3,7 +3,8 @@ package xmlmodels
import (
"encoding/json"
"encoding/xml"
"strings"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
)
type Work struct {
@@ -20,15 +21,6 @@ func (w Work) Name() string {
return "work"
}
func (p Work) ReferencesAgent(a string) (*AgentRef, bool) {
for _, i := range p.AgentRefs {
if strings.HasPrefix(i.Ref, a) {
return &i, true
}
}
return nil, false
}
type Citation struct {
XMLName xml.Name `xml:"zitation"`
Title string `xml:"title"`
@@ -37,6 +29,22 @@ type Citation struct {
Inner
}
func (w Work) References() xmlprovider.ResolvingMap[Work] {
refs := make(xmlprovider.ResolvingMap[Work])
for _, ref := range w.AgentRefs {
refs[ref.Name()] = append(refs[ref.Name()], xmlprovider.Resolved[Work]{
Item: &w, // Reference to the current Work item
Reference: ref.Ref, // Reference ID
Category: ref.Category, // Category of the reference
Cert: !ref.Unsicher, // Certainty flag (true if not unsure)
Conjecture: false,
Comment: ref.Inner.InnerXML,
})
}
return refs
}
func (w Work) String() string {
data, _ := json.MarshalIndent(w, "", " ")
return string(data)