-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbshare.go
69 lines (60 loc) · 1.83 KB
/
dbshare.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package dbshare
import (
"database/sql"
"fmt"
"strconv"
"github.com/gnames/gnames/config"
"github.com/gnames/gnparser/ent/parsed"
)
func DBURL(cnf config.Config) string {
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable",
cnf.PgUser, cnf.PgPass, cnf.PgHost, cnf.PgPort, cnf.PgDB)
}
// MatchRecords connects result data to input name-string. Input name-string
// is a key.
type VerifSQL struct {
CanonicalID sql.NullString
Canonical sql.NullString
CanonicalFull sql.NullString
Name sql.NullString
Cardinality int
RecordID sql.NullString
NameStringID sql.NullString
DataSourceID int
LocalID sql.NullString
OutlinkID sql.NullString
AcceptedRecordID sql.NullString
AcceptedNameID sql.NullString
AcceptedName sql.NullString
Classification sql.NullString
ClassificationRanks sql.NullString
ClassificationIds sql.NullString
ParseQuality int
}
var QueryFields = `
v.canonical_id, v.name, v.data_source_id, v.record_id,
v.name_string_id, v.local_id, v.outlink_id, v.accepted_record_id,
v.accepted_name_id, v.accepted_name, v.classification,
v.classification_ranks, v.classification_ids, v.parse_quality
`
// ProcessAuthorship converts year to int and provides authors as a slice.
func ProcessAuthorship(au *parsed.Authorship) ([]string, int) {
authors := make([]string, 0, 2)
var year int
if au == nil {
return authors, year
}
authors = au.Authors
year, _ = strconv.Atoi(au.Year)
if year > 0 && au.Original != nil &&
au.Original.Year != nil && !au.Original.Year.IsApproximate {
return authors, year
}
if au.Combination != nil && au.Combination.Year != nil {
year, _ = strconv.Atoi(au.Combination.Year.Value)
if au.Combination.Year.IsApproximate {
year = 0
}
}
return authors, year
}