Skip to content

Commit

Permalink
extend cf to infraspecies (close #245)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimus committed Sep 26, 2023
1 parent 704393c commit 190627b
Show file tree
Hide file tree
Showing 9 changed files with 4,672 additions and 4,479 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## [v1.7.5] - 2023-09-12 Tue

- Fix [#249]: ignore `cf` at the end of the strings.
- Fix [#249]: allow `cf` at the end of the strings, cf for infraspecies.
- Fix [#248]: do not escape double quotes for TSV output.
- Fix [#246]: ignore `ms` at the end of the strings.

Expand Down
18 changes: 9 additions & 9 deletions ent/parsed/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ type InfraspeciesElem struct {

// Comparison are details for a surrogate comparison name.
type Comparison struct {
// Genus is the genus of a name.
Genus string `json:"genus"`
// Species is a specific epithet of a name.
Species string `json:"species,omitempty"`
// Cultivar is a value of a cultivar of a binomial.
Cultivar string `json:"cultivar,omitempty"`
// SpeciesAuthorship the authorship of Species.
SpeciesAuthorship *Authorship `json:"authorship,omitempty"`
// Genus is used if no species information is given
Genus string `json:"genus,omitempty"`

// Species are details for the binomial part of a name.
*Species

// InfraSpecies is an infraspecific epthet of a name.
InfraSpecies *InfraspeciesElem `json:"infraspecies,omitempty"`

// CompMarker, usually "cf.".
CompMarker string `json:"comparisonMarker"`
}
Expand Down Expand Up @@ -91,7 +92,6 @@ type DetailsGraftChimeraFormula struct {
// isDetails implements Details interface.
func (DetailsHybridFormula) isDetails() {}


// isDetails implements Details interface.
func (DetailsGraftChimeraFormula) isDetails() {}

Expand Down
67 changes: 58 additions & 9 deletions ent/parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,60 @@ func (p *Engine) newApproxNode(n *node32) *approxNode {
}

type comparisonNode struct {
Genus *parsed.Word
SpEpithet *spEpithetNode
Comparison *parsed.Word
Genus *parsed.Word
SpEpithet *spEpithetNode
InfraSpEpithet *infraspEpithetNode
Comparison *parsed.Word
Cardinality int
}

func (p *Engine) newComparisonNode(n *node32) *comparisonNode {
n = n.up
switch n.pegRule {
case ruleNameCompIsp:
return p.newCompIspNode(n)
case ruleNameCompSp:
return p.newCompSpNode(n)
default:
var res *comparisonNode
return res
}
}

func (p *Engine) newCompIspNode(n *node32) *comparisonNode {
var cn *comparisonNode
if n.pegRule != ruleNameComp {
return cn
n = n.up
var gen, comp *parsed.Word
var spEp *spEpithetNode
var ispEp *infraspEpithetNode
for n != nil {
switch n.pegRule {
case ruleGenusWord:
gen = p.newWordNode(n, parsed.GenusType)
case ruleComparison:
comp = p.newWordNode(n, parsed.ComparisonMarkerType)
case ruleSpeciesEpithet:
spEp = p.newSpeciesEpithetNode(n)
p.cardinality = 2
case ruleInfraspEpithet:
ispEp = p.newInfraspEpithetNode(n)
p.cardinality = 3
}
n = n.next
}
cn = &comparisonNode{
Genus: gen,
Comparison: comp,
SpEpithet: spEp,
InfraSpEpithet: ispEp,
Cardinality: 3,
}
return cn

}

func (p *Engine) newCompSpNode(n *node32) *comparisonNode {
var cn *comparisonNode
n = n.up
var gen, comp *parsed.Word
var spEp *spEpithetNode
Expand All @@ -560,9 +604,10 @@ func (p *Engine) newComparisonNode(n *node32) *comparisonNode {
n = n.next
}
cn = &comparisonNode{
Genus: gen,
Comparison: comp,
SpEpithet: spEp,
Genus: gen,
Comparison: comp,
SpEpithet: spEp,
Cardinality: 2,
}
return cn
}
Expand Down Expand Up @@ -1137,9 +1182,13 @@ func (n *node32) flatChildren() []*node32 {
func (p *Engine) newWordNode(n *node32, wt parsed.WordType) *parsed.Word {
t := n.token32
val := p.nodeValue(n)
norm := val
if n.pegRule == ruleComparison {
norm = "cf."
}
wrd := parsed.Word{
Verbatim: val,
Normalized: val,
Normalized: norm,
Type: wt,
Start: int(t.begin),
End: int(t.end),
Expand Down
2 changes: 2 additions & 0 deletions ent/parser/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ var nodeRules = map[pegRule]struct{}{
ruleName: {},
ruleNameApprox: {},
ruleNameComp: {},
ruleNameCompSp: {},
ruleNameCompIsp: {},
ruleNameSpecies: {},
ruleNamedGenusGraftChimera: {},
ruleNamedGenusHybrid: {},
Expand Down
6 changes: 5 additions & 1 deletion ent/parser/grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ NameUninomial <- (UninomialCombo / Uninomial) (_ CultivarWordGroup)?

NameApprox <- GenusWord (_ SpeciesEpithet)? _ Approximation ApproxNameIgnored

NameComp <- GenusWord _ Comparison (_ SpeciesEpithet)?
NameComp <- NameCompIsp / NameCompSp

NameCompSp <- GenusWord _ Comparison (_ SpeciesEpithet)?

NameCompIsp <- GenusWord _ SpeciesEpithet _ Comparison (_ InfraspEpithet)?

NameSpecies <- GenusWord (_? ( Subgenus / SubgenusOrSuperspecies))?
_ SpeciesEpithet (_ InfraspGroup)? (_ CultivarWordGroup)?
Expand Down
Loading

0 comments on commit 190627b

Please sign in to comment.