mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-12 08:50:01 +00:00
tokenizer.c: Support colon tokens.
This commit is contained in:
@@ -96,9 +96,10 @@ typedef enum {
|
||||
ESPEAKNG_CTYPE_QUESTION_MARK,
|
||||
ESPEAKNG_CTYPE_EXCLAMATION_MARK,
|
||||
ESPEAKNG_CTYPE_COMMA,
|
||||
ESPEAKNG_CTYPE_COLON,
|
||||
} espeakng_CTYPE;
|
||||
|
||||
#define ESPEAKNG_CTYPE_PROPERTY_MASK 0xF00000000000C001ull
|
||||
#define ESPEAKNG_CTYPE_PROPERTY_MASK 0xF80000000000C001ull
|
||||
|
||||
// Reference: http://www.unicode.org/reports/tr14/tr14-32.html -- Unicode Line Breaking Algorithm
|
||||
static espeakng_CTYPE codepoint_type(uint32_t c)
|
||||
@@ -145,6 +146,8 @@ static espeakng_CTYPE codepoint_type(uint32_t c)
|
||||
return ESPEAKNG_CTYPE_EXCLAMATION_MARK;
|
||||
case ESPEAKNG_PROPERTY_COMMA:
|
||||
return ESPEAKNG_CTYPE_COMMA;
|
||||
case ESPEAKNG_PROPERTY_COLON:
|
||||
return ESPEAKNG_CTYPE_COLON;
|
||||
}
|
||||
|
||||
// 4. Classify the remaining codepoints.
|
||||
@@ -292,6 +295,10 @@ tokenizer_state_default(espeak_ng_TOKENIZER *tokenizer)
|
||||
current += utf8_out(c, current);
|
||||
*current = '\0';
|
||||
return ESPEAKNG_TOKEN_COMMA;
|
||||
case ESPEAKNG_CTYPE_COLON:
|
||||
current += utf8_out(c, current);
|
||||
*current = '\0';
|
||||
return ESPEAKNG_TOKEN_COLON;
|
||||
default:
|
||||
current += utf8_out(c, current);
|
||||
*current = '\0';
|
||||
|
||||
@@ -55,6 +55,7 @@ typedef enum
|
||||
ESPEAKNG_TOKEN_QUESTION_MARK,
|
||||
ESPEAKNG_TOKEN_EXCLAMATION_MARK,
|
||||
ESPEAKNG_TOKEN_COMMA,
|
||||
ESPEAKNG_TOKEN_COLON,
|
||||
} espeak_ng_TOKEN_TYPE;
|
||||
|
||||
espeak_ng_TOKEN_TYPE
|
||||
|
||||
+12
-1
@@ -465,7 +465,7 @@ test_Latn_punctuation_tokens()
|
||||
espeak_ng_TOKENIZER *tokenizer = create_tokenizer();
|
||||
espeak_ng_TEXT_DECODER *decoder = create_text_decoder();
|
||||
|
||||
assert(text_decoder_decode_string(decoder, ". ? ! ,", -1, ESPEAKNG_ENCODING_US_ASCII) == ENS_OK);
|
||||
assert(text_decoder_decode_string(decoder, ". ? ! , :", -1, ESPEAKNG_ENCODING_US_ASCII) == ENS_OK);
|
||||
assert(tokenizer_reset(tokenizer, decoder, ESPEAKNG_TOKENIZER_OPTION_TEXT) == 1);
|
||||
|
||||
assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_FULL_STOP);
|
||||
@@ -496,6 +496,14 @@ test_Latn_punctuation_tokens()
|
||||
assert(tokenizer_get_token_text(tokenizer) != NULL);
|
||||
assert(strcmp(tokenizer_get_token_text(tokenizer), ",") == 0);
|
||||
|
||||
assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_WHITESPACE);
|
||||
assert(tokenizer_get_token_text(tokenizer) != NULL);
|
||||
assert(strcmp(tokenizer_get_token_text(tokenizer), " ") == 0);
|
||||
|
||||
assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_COLON);
|
||||
assert(tokenizer_get_token_text(tokenizer) != NULL);
|
||||
assert(strcmp(tokenizer_get_token_text(tokenizer), ":") == 0);
|
||||
|
||||
assert(tokenizer_read_next_token(tokenizer) == ESPEAKNG_TOKEN_END_OF_BUFFER);
|
||||
assert(tokenizer_get_token_text(tokenizer) != NULL);
|
||||
assert(*tokenizer_get_token_text(tokenizer) == '\0');
|
||||
@@ -597,6 +605,9 @@ print_tokens(espeak_ng_TEXT_DECODER *decoder)
|
||||
case ESPEAKNG_TOKEN_COMMA:
|
||||
printf("comma : %s\n", tokenizer_get_token_text(tokenizer));
|
||||
break;
|
||||
case ESPEAKNG_TOKEN_COLON:
|
||||
printf("colon : %s\n", tokenizer_get_token_text(tokenizer));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user