Skip to content

Commit

Permalink
optional name detection by annotation (close #143)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimus committed Jul 27, 2023
1 parent e3123c9 commit 7d85860
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/ent/token/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type Features struct {
// Abbr feature: token ends with a period.
Abbr bool

// HasAnnotation is true if there is an apparent nomenclatural annotation
// attached to a name candidate. This feature can only be set for the
// first token of a candidate.
HasAnnotation bool

// PotentialBinomialGenus feature: the token might be a genus of name.
PotentialBinomialGenus bool

Expand Down
13 changes: 8 additions & 5 deletions pkg/ent/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/gnames/gnfinder/pkg/io/dict"
)

// tokenSN represents a word separated by spaces in a text. Words that are
// split by new lines are concatenated.
// tokenSN (a token for a 'Scientific Name') represents a word separated by
// spaces in a text. Words that are split by new lines are concatenated.
type tokenSN struct {
gner.TokenNER

Expand Down Expand Up @@ -218,10 +218,13 @@ func checkRank(t TokenSN, d *dict.Dictionary) bool {

// UpperIndex takes an index of a token and length of the tokens slice and
// returns an upper index of what could be a slice of a name. We expect that
// that most of the names will fit into 5 words. Other cases would require
// more thorough algorithims that we can run later as plugins.
// that most of the names will fit into 5 words. We also expect that annotation
// will be located not further away than 10 words away.
// Other cases would require more thorough algorithims that we can run
// later as plugins.
func UpperIndex(i int, l int) int {
upperIndex := i + 5
// 10 here is 5 tokens for name, 5 tokens for annotation
upperIndex := i + 10
if l < upperIndex {
upperIndex = l
}
Expand Down

0 comments on commit 7d85860

Please sign in to comment.