Akron | 78f6714 | 2022-04-09 14:10:44 +0200 | [diff] [blame] | 1 | ! This tokenizer is based on work by |
| 2 | ! - StandardTokenizerImpl by the Lucene project |
| 3 | ! under the Apache License |
| 4 | ! - https://github.com/dlwh/epic by David Hall (2014) |
| 5 | ! under the Apacahe License |
| 6 | ! - KorAPTokenizerImpl.jflex by Marc Kupietz (2016) |
| 7 | ! under the Apache License |
| 8 | ! - https://github.com/coltekin/TRmorph/tokenize.xfst by Çağrı Çöltekin (2011-2015) |
| 9 | ! under the MIT License |
| 10 | |
| 11 | define NLout "@_TOKEN_SYMBOL_@"; |
| 12 | ! define NLout "\u000a"; |
| 13 | |
| 14 | define Digit [%0|1|2|3|4|5|6|7|8|9]; |
| 15 | define AsciiLetter [a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z]; |
| 16 | define HexLetter [Digit|a|A|b|B|c|C|d|D|e|E|f|F]; |
| 17 | define EOT "\u0004"; |
| 18 | |
| 19 | !!!!!!!!!!!!!!!!! |
| 20 | ! <from tmorph> ! |
| 21 | !!!!!!!!!!!!!!!!! |
| 22 | define WS [" "|"\u0009"|"\u00a0"|"\u1680"| |
| 23 | "\u2000"|"\u2001"|"\u2002"|"\u2003"|"\u2004"|"\u2005"| |
| 24 | "\u2006"|"\u2007"|"\u2008"|"\u2009"|"\u200a"| |
| 25 | "\u202f"|"\u205f"|"\u3000"]; |
| 26 | |
| 27 | define NL ["\u000a"|"\u000b"|"\u000c"|"\u000d"|"\u0085"|"\u2028"|"\u2029"|EOT]; |
| 28 | |
| 29 | ! Punctuation that ends sentences |
| 30 | ! Differs! |
| 31 | define SP [["."|"?"|"!"]+|"…"]; |
| 32 | |
| 33 | ! Left punctuation |
| 34 | define LP ["("|"["|"{"| |
| 35 | "“"|"‘"|"‹"|"«"| |
| 36 | "'"|%"| |
| 37 | ! differs |
| 38 | ["'" "'"] | |
| 39 | "*"|"/"|"_"| ! Can be Markdown |
| 40 | ! from book |
| 41 | [%, %,]]; |
| 42 | |
| 43 | ! Right punctuation - excluding the characters that can be used as apostrophe |
| 44 | define RP [SP|","|";"|":"| |
| 45 | ")"|"]"|"}"| |
| 46 | "”"|"›"|"»"|%"|[%’ %’]|["'" "'"]|[%‘ %‘]| |
| 47 | "*"|"/"|"_"]; ! Can be Markdown |
| 48 | |
| 49 | define DQuotes ["”"|%"|"»"|"«"]; |
| 50 | |
| 51 | define Sym ["-"|"+"|"<"|">"|"*"|"/"|%=|%@|%&]; |
| 52 | define Apos %'|%’|%`; |
| 53 | define Punct [LP|RP|Sym]; |
| 54 | !define nonSym \[WS|LP|RP|Sym]; |
| 55 | !!!!!!!!!!!!!!!!!! |
| 56 | ! </from tmorph> ! |
| 57 | !!!!!!!!!!!!!!!!!! |
| 58 | |
| 59 | define Emdash [%- %- (%-)+ | ["\u2014"|"\u2015"|"\u2e3a"|"\u2e3b"|"\ufe58"]+]; |
| 60 | define Dash ["-"|"\u2011"|"\u2012"|"\u2013"|"\u2e1a"|"\ufe63"|"\uff0d"]; |
Akron | 6dcb6ce | 2022-04-09 16:09:51 +0200 | [diff] [blame^] | 61 | define Alldash ["-"|"\u2011"|"\u2012"|"\u2013"|"\u2e1a"|"\ufe63"|"\uff0d"|"\u2014"|"\u2015"|"\u2e3a"|"\u2e3b"|"\ufe58"]; |
Akron | 78f6714 | 2022-04-09 14:10:44 +0200 | [diff] [blame] | 62 | define Slash ["⁄"|"∕"|"/"|"/"]; |
| 63 | define Asterisk ["*"]; |
| 64 | |
| 65 | define Char \[WS|NL|Punct|Apos]; ! |¨; |
| 66 | |
| 67 | !define Alpha ["a"|"b"|"c"|"d"|"e"|"f"|"g"|"h"|"i"|"j"|"k"|"l"|"m"|"n"|"o"|"p"|"q"|"r"|"s"|"t"|"u"|"v"|"w"|"x"|"y"|"z"|"_"]; |
| 68 | |
| 69 | define SentenceEnd SP NLout [DQuotes (NLout ")") | ["›"|%‹|%’|"'"] ( NLout DQuotes (NLout ")") | NLout ")" ) | ")" ] (NLout SP); |
| 70 | |
| 71 | define NotSentenceExtension [? - "”" - %" - "»" - "«" - "›" - %‹ - %’ - "'" - ")" - NLout]; |