feat(scraper): bound article enrichment diagnostics (#40)
This commit is contained in:
@ -14,9 +14,18 @@ type articleEvidence struct {
|
||||
fullBody *string
|
||||
}
|
||||
|
||||
func inspectEvidence(doc *html.Node, source, expected string) articleEvidence {
|
||||
func inspectEvidence(doc *html.Node, source, expected string, aliases ...string) articleEvidence {
|
||||
e := articleEvidence{}
|
||||
wanted, valid := safeURL(source, expected)
|
||||
wanted, valid := articleIdentity(source, expected)
|
||||
accepted := map[string]bool{}
|
||||
if valid {
|
||||
accepted[wanted] = true
|
||||
}
|
||||
for _, alias := range aliases {
|
||||
if identity, ok := articleIdentity(source, alias); ok {
|
||||
accepted[identity] = true
|
||||
}
|
||||
}
|
||||
key := func(value string) string {
|
||||
if value == "" {
|
||||
return ""
|
||||
@ -29,7 +38,7 @@ func inspectEvidence(doc *html.Node, source, expected string) articleEvidence {
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
value, ok := safeURL(source, base.ResolveReference(ref).String())
|
||||
value, ok := articleIdentity(source, base.ResolveReference(ref).String())
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
@ -96,7 +105,7 @@ func inspectEvidence(doc *html.Node, source, expected string) articleEvidence {
|
||||
if value != "" {
|
||||
articleIDs++
|
||||
}
|
||||
if valid && key(value) == wanted {
|
||||
if accepted[key(value)] {
|
||||
e.associated = true
|
||||
matching = true
|
||||
if x["isAccessibleForFree"] == false || strings.EqualFold(identity(x["isAccessibleForFree"]), "false") {
|
||||
@ -132,7 +141,7 @@ func inspectEvidence(doc *html.Node, source, expected string) articleEvidence {
|
||||
}
|
||||
if value != "" {
|
||||
primary++
|
||||
if valid && key(value) == wanted {
|
||||
if accepted[key(value)] {
|
||||
e.associated = true
|
||||
} else {
|
||||
e.mismatch = true
|
||||
|
||||
Reference in New Issue
Block a user