diff options
Diffstat (limited to 'extra')
-rw-r--r-- | extra/mag/magrefs-mem.go | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/extra/mag/magrefs-mem.go b/extra/mag/magrefs-mem.go index 403e021..ea7f207 100644 --- a/extra/mag/magrefs-mem.go +++ b/extra/mag/magrefs-mem.go @@ -13,6 +13,7 @@ import ( "os" "strconv" "strings" + "sync/atomic" _ "github.com/mattn/go-sqlite3" "github.com/miku/parallel" @@ -21,6 +22,8 @@ import ( var ( mappingFile = flag.String("f", "", "two column TSV with key and value") cache = make(map[int]string) + + edgeMissingDOI int64 // number of edges that have one or zero DOI, but not both ) func populateCache(r io.Reader, cache map[int]string) error { @@ -69,27 +72,34 @@ func main() { log.Fatal(err) } pp := parallel.NewProcessor(os.Stdin, os.Stdout, func(p []byte) ([]byte, error) { - fields := strings.Split(string(p), "\t") + var ( + s, t, v, w string + source, target int + err error + ok bool + complete = true + fields = strings.Split(string(p), "\t") + ) if len(fields) < 2 { return nil, nil } - s, t := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1]) - source, err := strconv.Atoi(s) - if err != nil { + s, t = strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1]) + if source, err = strconv.Atoi(s); err != nil { log.Printf("skipping invalid source id: %s (%v)", s, err) return nil, nil } - target, err := strconv.Atoi(t) - if err != nil { + if target, err = strconv.Atoi(t); err != nil { log.Printf("skipping invalid target id: %s (%v)", t, err) return nil, nil } - v, ok := cache[source] - if !ok { - return nil, nil + if v, ok = cache[source]; !ok { + complete = false + } + if w, ok = cache[target]; !ok { + complete = false } - w, ok := cache[target] - if !ok { + if !complete { + atomic.AddInt64(&edgeMissingDOI, 1) return nil, nil } line := fmt.Sprintf("%s\t%s\n", v, w) @@ -98,4 +108,5 @@ func main() { if err := pp.Run(); err != nil { log.Fatal(err) } + log.Printf("edges without DOI: %d", edgeMissingDOI) } |