Skip to content

Commit

Permalink
add nom. code option (close #265)
Browse files Browse the repository at this point in the history
To help with ambiguous cases, for example when it is not
clear if `Aus (Bus) cus` has a genus Author `Bus` (bot.)
or it is a `Bus` is a subgenus of `Aus` (zool.). It also
deprecates cultivar flag, which becomes another option for
the code flag. The cultivar flag will be kept for
backward compatibility.
  • Loading branch information
dimus committed Nov 8, 2024
1 parent 82b4486 commit 6f3714a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
52 changes: 52 additions & 0 deletions ent/nomcode/nomcode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package nomcode

import (
"log/slog"
"strings"
)

// Code represents a nomenclatural code.
type Code int

// Constants for different nomenclatural codes.
const (
Unknown Code = iota // Unknown code
Zoological // Zoological code
Botanical // Botanical code
Cultivar // Cultivar code
)

// New creates a new Code from a string representation.
// It accepts short codes ('b', 'z', 'c') and full names
// ('botanical', 'zoological', 'cultivar') as well as
// official abbreviations ('icn', 'iczn', 'icncp').
// The input string is case-insensitive.
func New(s string) Code {
sOrig := s
s = strings.ToLower(s)
switch s {
case "b", "bot", "botanical", "icn":
return Botanical
case "z", "zoo", "zoological", "iczn":
return Zoological
case "c", "cult", "cultivar", "icncp":
return Cultivar
default:
slog.Warn("Cannot determine nomenclatural code", "input", sOrig)
return Unknown
}
}

// String returns the official abbreviation of the nomenclatural code.
func (c Code) String() string {
switch c {
case Zoological:
return "ICZN"
case Botanical:
return "ICN"
case Cultivar:
return "ICNCP"
default:
return ""
}
}
25 changes: 21 additions & 4 deletions gnparser/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ func init() {
"maximum number of names in a batch send for processing.")

rootCmd.Flags().BoolP("cultivar", "C", false,
"include cultivar epithets and graft-chimeras in normalized and canonical outputs")
"parse according to cultivar code ICNCP (DEPRECATED, use nomenclatural-code instead)")

codeHelp := `Modifies the parser's behavior in ambiguous cases, sometimes
introducing additional parsing rules.
Accepted values are:
- 'bot', 'icn', 'botanical' for botanical code
- 'cult', 'icncp', 'cultivar' for cultivar code
- 'zoo', 'iczn', 'zoological' for zoological code
If not set, the parser will attempt to determine the appropriate code/s.`
rootCmd.Flags().StringP("nomenclatural-code", "n", "", codeHelp)

rootCmd.Flags().BoolP("capitalize", "c", false,
"capitalize the first letter of input name-strings")
Expand All @@ -149,9 +160,15 @@ func init() {

rootCmd.Flags().BoolP("details", "d", false, "provides more details")

formatHelp := "sets output format. Can be one of:\n" +
"'csv', 'tsv', 'compact', 'pretty'\n" +
"default is 'csv'"
formatHelp := `Sets the output format.
Accepted values are:
- 'csv': Comma-separated values
- 'tsv': Tab-separated values
- 'compact': Compact JSON format
- 'pretty': Human-readable JSON format
If not set, the output format defaults to 'csv'.`
rootCmd.Flags().StringP("format", "f", "", formatHelp)

rootCmd.Flags().BoolP("ignore_tags", "i", false,
Expand Down

0 comments on commit 6f3714a

Please sign in to comment.