Akteure beginning

This commit is contained in:
Simon Martens
2024-12-26 01:26:51 +01:00
parent 4de0eab443
commit 86152bd46d
47 changed files with 61845 additions and 23644 deletions

View File

@@ -1 +0,0 @@
package providers

View File

@@ -1 +0,0 @@
package providers

View File

@@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"strconv"
"strings"
"github.com/google/uuid"
)
@@ -60,6 +61,15 @@ func (p Piece) ReferencesIssue(y, no int) (*IssueRef, bool) {
return nil, false
}
func (p Piece) ReferencesAgent(a string) (*AgentRef, bool) {
for _, i := range p.AgentRefs {
if strings.HasPrefix(i.Ref, a) {
return &i, true
}
}
return nil, false
}
// TODO: We can make this fast depending on which category to look for
// but we'll have to define rules for every single category (~35 of them)
func (p Piece) IsCat(k string) bool {

View File

@@ -3,6 +3,7 @@ package xmlprovider
import (
"encoding/xml"
"fmt"
"strings"
)
type Work struct {
@@ -10,11 +11,20 @@ type Work struct {
URLs []URL `xml:"url"`
Citation Citation `xml:"zitation"`
PreferredTitle string `xml:"preferred"`
Akteur []AgentRef `xml:"akteur"`
AgentRefs []AgentRef `xml:"akteur"`
Identifier
AnnotationNote
}
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"`
@@ -24,5 +34,5 @@ type Citation struct {
}
func (w Work) String() string {
return fmt.Sprintf("URLs: %v, Citation: %v, PreferredTitle: %s, Akteur: %v, Identifier: %v, AnnotationNote: %v\n", w.URLs, w.Citation, w.PreferredTitle, w.Akteur, w.Identifier, w.AnnotationNote)
return fmt.Sprintf("URLs: %v, Citation: %v, PreferredTitle: %s, Akteur: %v, Identifier: %v, AnnotationNote: %v\n", w.URLs, w.Citation, w.PreferredTitle, w.AgentRefs, w.Identifier, w.AnnotationNote)
}

View File

@@ -142,25 +142,15 @@ func (p *XMLProvider[T]) Item(id string) *T {
return i
}
func (p *XMLProvider[T]) Find(fn func(*T) bool) []*T {
var items []*T
p.Items.Range(func(key, value interface{}) bool {
if fn(value.(*T)) {
items = append(items, value.(*T))
func (p *XMLProvider[T]) Find(fn func(*T) bool) []T {
p.mu.Lock()
defer p.mu.Unlock()
var items []T
for _, item := range p.Array {
if fn(&item) {
items = append(items, item)
}
return true
})
return items
}
func (p *XMLProvider[T]) FindKey(fn func(string) bool) []*T {
var items []*T
p.Items.Range(func(key, value interface{}) bool {
if fn(key.(string)) {
items = append(items, value.(*T))
}
return true
})
}
return items
}