Fixed bug where punctuation was skipped when occuring inside numbers. Also removed the end of sentence pause marker for punctuation inside words/numbers.
This commit is contained in:
1 parent
22f6df6af9
commit
36736725ea
4 files changed
+85
-26
No files matched your search
@@ -159,19 +159,35 @@ func (p *Processor) Character(char rune) string {
|
||||
|
||||
// Text retains Python's levels and pause handling. At some and most, symbols
|
||||
// embedded between letters or numbers are also named, except apostrophes in
|
||||
// contractions and single numeric separators. A percent sign after a digit is
|
||||
// also named at some and most. Sentence punctuation follows the selected level.
|
||||
// contractions and numeric separators in decimals, grouped numbers, and times.
|
||||
// Multiple dots in a numeric sequence are named. Embedded punctuation names
|
||||
// do not add pause markers. A percent sign after a digit is also named at some
|
||||
// and most. Sentence punctuation follows the selected level.
|
||||
func (p *Processor) Text(text, level string) string {
|
||||
selected := p.levels[level]
|
||||
var result strings.Builder
|
||||
chars := []rune(text)
|
||||
embeddedEnd := 0
|
||||
embedded := false
|
||||
numericEnd, numericDots := 0, 0
|
||||
for index, char := range chars {
|
||||
if unicode.IsDigit(char) && index >= numericEnd {
|
||||
numericEnd, numericDots = index, 0
|
||||
for numericEnd < len(chars) {
|
||||
if unicode.IsDigit(chars[numericEnd]) {
|
||||
numericEnd++
|
||||
} else if chars[numericEnd] == '.' && numericEnd+1 < len(chars) && unicode.IsDigit(chars[numericEnd+1]) {
|
||||
numericDots++
|
||||
numericEnd++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if index >= embeddedEnd {
|
||||
embeddedEnd = index + 1
|
||||
embedded = false
|
||||
if (level == "some" || level == "most") && (unicode.IsPunct(char) || unicode.IsSymbol(char)) {
|
||||
if (level == "some" || level == "most" || level == "all") && (unicode.IsPunct(char) || unicode.IsSymbol(char)) {
|
||||
for embeddedEnd < len(chars) && (unicode.IsPunct(chars[embeddedEnd]) || unicode.IsSymbol(chars[embeddedEnd])) {
|
||||
embeddedEnd++
|
||||
}
|
||||
@@ -180,7 +196,7 @@ func (p *Processor) Text(text, level string) string {
|
||||
if embedded && embeddedEnd == index+1 {
|
||||
before, after := chars[index-1], chars[embeddedEnd]
|
||||
if char == '\'' && unicode.IsLetter(before) && unicode.IsLetter(after) ||
|
||||
strings.ContainsRune(".,:", char) && unicode.IsDigit(before) && unicode.IsDigit(after) {
|
||||
(strings.ContainsRune(",:", char) || char == '.' && numericDots <= 1) && unicode.IsDigit(before) && unicode.IsDigit(after) {
|
||||
embedded = false
|
||||
}
|
||||
}
|
||||
@@ -191,7 +207,7 @@ func (p *Processor) Text(text, level string) string {
|
||||
if selected[char] || (embedded || percentage) && known {
|
||||
result.WriteByte(' ')
|
||||
result.WriteString(p.Character(char))
|
||||
if strings.ContainsRune("',.;:?!", char) {
|
||||
if !embedded && strings.ContainsRune("',.;:?!", char) {
|
||||
result.WriteRune(char)
|
||||
}
|
||||
result.WriteByte(' ')
|
||||
|
||||
Reference in new issue
Block a user