diff --git a/bin/anystyle b/bin/anystyle index 16fe73f..18cd073 100755 --- a/bin/anystyle +++ b/bin/anystyle @@ -200,6 +200,37 @@ command :parse do |cmd| end end + +desc 'Parse a single reference' +long_desc %{ + This manual page documents the AnyStyle `parse_reference' command. + + The input argument will be the reference to be parsed + + AnyStyle `parse_reference' supports the following formats: + bib BibTeX (normalized); + csl CSL/JSON (normalized); + json AnyStyle JSON (normalized); + ref One reference per line, suitable for parser input; + txt Same as `ref'; + xml XML, suitable for training the parser model. + + You can specify multiple output formats, separated by commas. + +EXAMPLES + anystyle -f json,xml parse_reference "A. Author, Some title, publisher name, pp103-102, DOI:10.000/xyz" + + Parse the input reference and print the result to STDOUT in JSON and XML + +}.lstrip + +arg :input +command :parse_reference do |cmd| + cmd.action do |opts, params, args| + Commands::ParseReference.new(opts).run(args, params) + end +end + desc 'Check tagged documents or references' long_desc %{ This manual page documents the AnyStyle `check' command. AnyStyle `check' diff --git a/lib/anystyle/cli.rb b/lib/anystyle/cli.rb index 4811759..443bc1e 100644 --- a/lib/anystyle/cli.rb +++ b/lib/anystyle/cli.rb @@ -7,4 +7,5 @@ require 'anystyle/cli/commands/check' require 'anystyle/cli/commands/find' require 'anystyle/cli/commands/parse' +require 'anystyle/cli/commands/parse_reference' require 'anystyle/cli/commands/train' diff --git a/lib/anystyle/cli/commands/parse_reference.rb b/lib/anystyle/cli/commands/parse_reference.rb new file mode 100644 index 0000000..25f5d17 --- /dev/null +++ b/lib/anystyle/cli/commands/parse_reference.rb @@ -0,0 +1,18 @@ +module AnyStyle + module CLI + module Commands + class ParseReference < Base + def run(args, params) + set_output_folder args[1] + ref = args[0] + dataset = parse(ref) + say "Parsing citation: #{ref} ..." + each_format do |fmt| + res = format(dataset, fmt) + STDOUT.puts(res) + end + end + end + end + end +end