aboutsummaryrefslogtreecommitdiffstats
path: root/skate/cmd
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-06-10 01:48:45 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-06-10 01:48:45 +0200
commit2b88452ec73e0a34dedcfbcc515eb6a91ce7e3e6 (patch)
treeda06929afea84d372f7de8247536444945c666e8 /skate/cmd
parentb85f3cab82f1bcc757021daadfc65a68ce834f6d (diff)
downloadrefcat-2b88452ec73e0a34dedcfbcc515eb6a91ce7e3e6.tar.gz
refcat-2b88452ec73e0a34dedcfbcc515eb6a91ce7e3e6.zip
add test cases
Diffstat (limited to 'skate/cmd')
-rw-r--r--skate/cmd/skate-resolve-journal-name/main.go34
1 files changed, 17 insertions, 17 deletions
diff --git a/skate/cmd/skate-resolve-journal-name/main.go b/skate/cmd/skate-resolve-journal-name/main.go
index 0bd4866..8929d6c 100644
--- a/skate/cmd/skate-resolve-journal-name/main.go
+++ b/skate/cmd/skate-resolve-journal-name/main.go
@@ -32,7 +32,7 @@ var (
column = flag.Int("f", 2, "column to find the release schema document in (1-indexed)")
sep = flag.String("d", "\t", "delimiter to use")
bestEffort = flag.Bool("B", false, "only log errors, do not halt")
- abbrevFile = flag.String("A", "", "path to abbreviate file")
+ abbrevFile = flag.String("A", "", "path to abbreviations file")
keepResolvedOnly = flag.Bool("R", false, "keep only lines, where we could resolve an abbreviation")
)
@@ -102,13 +102,9 @@ func main() {
}
}
-type NameAbbrev struct {
- Name string `json:"name"`
- Abbrev string `json:"abbrev"`
-}
-
// createAbbreviationMatchSet creates a match set from JSONL abbreviations
-// file. It also returns a mapping from abbreviations to full journal names for that abbreviation.
+// file. It also returns a mapping from abbreviations to full journal names for
+// that abbreviation.
func createAbbreviationMatchSet(filename string) (*skate.MatchSet, map[string][]string, error) {
f, err := os.Open(filename)
if err != nil {
@@ -116,11 +112,15 @@ func createAbbreviationMatchSet(filename string) (*skate.MatchSet, map[string][]
}
defer f.Close()
var (
- sm = make(map[string]set.Set)
- m = make(map[string][]string)
- br = bufio.NewReader(f)
- na NameAbbrev
- abbreviations []string
+ sm = make(map[string]set.Set)
+ m = make(map[string][]string)
+ br = bufio.NewReader(f)
+ nameAbbrev struct {
+ Name string `json:"name"`
+ Abbrev string `json:"abbrev"`
+ }
+ abbrevs []string
+ key string
)
for {
b, err := br.ReadBytes('\n')
@@ -130,19 +130,19 @@ func createAbbreviationMatchSet(filename string) (*skate.MatchSet, map[string][]
if err != nil {
return nil, nil, err
}
- if err := json.Unmarshal(b, &na); err != nil {
+ if err := json.Unmarshal(b, &nameAbbrev); err != nil {
return nil, nil, err
}
- key := strings.ToLower(na.Abbrev)
+ key = strings.ToLower(nameAbbrev.Abbrev)
if _, ok := sm[key]; !ok {
sm[key] = set.New()
}
- sm[key].Add(strings.ToLower(na.Name))
+ sm[key].Add(strings.ToLower(nameAbbrev.Name))
}
for k, v := range sm {
- abbreviations = append(abbreviations, k)
+ abbrevs = append(abbrevs, k)
m[k] = v.Slice()
}
- matchSet := skate.NewMatchSet(abbreviations)
+ matchSet := skate.NewMatchSet(abbrevs)
return matchSet, m, nil
}