diff options
Diffstat (limited to 'vendor/github.com/DavidBelicza/TextRank/v2/parse/rule.go')
| -rw-r--r-- | vendor/github.com/DavidBelicza/TextRank/v2/parse/rule.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/github.com/DavidBelicza/TextRank/v2/parse/rule.go b/vendor/github.com/DavidBelicza/TextRank/v2/parse/rule.go new file mode 100644 index 0000000..0f6ec91 --- /dev/null +++ b/vendor/github.com/DavidBelicza/TextRank/v2/parse/rule.go @@ -0,0 +1,52 @@ +package parse + +// Rule interface and its methods make possible the polimorf usage of process +// how Rule retrieve tokens from text. +type Rule interface { + IsWordSeparator(rune rune) bool + IsSentenceSeparator(rune rune) bool +} + +// RuleDefault struct implements the Rule interface. It contains the separator +// characters and can decide a character is separator or not. +type RuleDefault struct { + wordSeparators [21]string + sentenceSeparators [3]string +} + +// NewRule constructor retrieves a RuleDefault pointer. +func NewRule() *RuleDefault { + return &RuleDefault{ + [21]string{" ", ",", "'", "’", "\"", ")", "(", "[", "]", "{", "}", "\"", ";", "\n", ">", "<", "%", "@", "&", "=", "#"}, + [3]string{"!", ".", "?"}, + } +} + +// IsWordSeparator method retrieves true when a character is a kind of special +// character and possibly it separates to words from each other. It also checks +// for sentence separator by IsSentenceSeparator method. +func (r *RuleDefault) IsWordSeparator(rune rune) bool { + chr := string(rune) + + for _, val := range r.wordSeparators { + if chr == val { + return true + } + } + + return r.IsSentenceSeparator(rune) +} + +// IsSentenceSeparator method retrieves true when a character is a kind of +// special character and possibly it separates to words from each other. +func (r *RuleDefault) IsSentenceSeparator(rune rune) bool { + chr := string(rune) + + for _, val := range r.sentenceSeparators { + if chr == val { + return true + } + } + + return false +} |
