diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-04-24 02:29:10 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-04-24 02:29:10 +0200 |
commit | e7f8c117c3586c6387a744043ad68c1850471719 (patch) | |
tree | 84f01a142e89635548790a0b73c137c7a888a87d /skate/cmd | |
parent | 19aa629f7f4c6345769784147493e2598d746dd3 (diff) | |
download | refcat-e7f8c117c3586c6387a744043ad68c1850471719.tar.gz refcat-e7f8c117c3586c6387a744043ad68c1850471719.zip |
wip: move to prefixed, w/ skate-map
Diffstat (limited to 'skate/cmd')
-rw-r--r-- | skate/cmd/skate-map/main.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/skate/cmd/skate-map/main.go b/skate/cmd/skate-map/main.go new file mode 100644 index 0000000..c5fb798 --- /dev/null +++ b/skate/cmd/skate-map/main.go @@ -0,0 +1,58 @@ +// skate-map runs a given map function over input data. We mostly want to +// extract a key from a json document. +package main + +import ( + "flag" + "fmt" + "log" + "os" + "runtime" + "text/tabwriter" + + "git.archive.org/martin/cgraph/skate" + "git.archive.org/martin/cgraph/skate/parallel" +) + +var ( + mapperName = flag.String("m", "", "mapper to run") + numWorkers = flag.Int("w", runtime.NumCPU(), "number of workers") + batchSize = flag.Int("b", 50000, "batch size") + verbose = flag.Bool("verbose", false, "show progress") + extraValue = flag.String("x", "", "extra value to pass to configurable mappers") +) + +func main() { + flag.Parse() + // XXX: introduce prefixes + availableMappers := map[string]skate.Mapper{ + "id": skate.Identity, + "ff": skate.CreateFixedFieldFunc(*extraValue), + "title": skate.MapperTitle, + "tnorm": skate.MapperTitleNormalized, + "tnysi": skate.MapperTitleNysiis, + "tsand": skate.MapperTitleSandcrawler, + } + switch { + case *mapperName != "": + if f, ok := availableMappers[*mapperName]; !ok { + log.Fatal("unknown mapper name: %v", *mapperName) + } else { + pp := parallel.NewProcessor(os.Stdin, os.Stdout, f) + pp.NumWorkers = *numWorkers + pp.BatchSize = *batchSize + pp.Verbose = *verbose + if err := pp.Run(); err != nil { + log.Fatal(err) + } + } + default: + fmt.Println("skate-map available mappers") + fmt.Println() + w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0) + for k, v := range availableMappers { + fmt.Fprintf(w, "%s\t%s\n", k, skate.NameOf(v)) + } + w.Flush() + } +} |