Mercurial > hg > mpdl-group
view software/mpdl-services/mpiwg-mpdl-lt/bin/de/mpg/mpiwg/berlin/mpdl/lt/text/norm/lang/MpdlNormalizerLexZH.lex @ 23:e845310098ba
diverse Korrekturen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Nov 2012 12:35:19 +0100 |
parents | |
children |
line wrap: on
line source
/* * Normalization rules for Chinese text * [this is a JFlex specification] * * Wolfgang Schmidle * version 2011-02-28 * */ package de.mpg.mpiwg.berlin.mpdl.lt.text.norm.lang; %% %public %class MpdlNormalizerLexZH %type java.lang.String %unicode // classical Chinese: zh, zho, zho-Hant %states DISP, DICT, SEARCH %{ private String original = ""; private String normalized = ""; private int problem = 0; private void add (String norm) { original += yytext(); normalized += norm; } %} ZWS = [\u{200b}] END = \n %% // Normalization in Chinese means that character variants will be replaced by their standard characters // if there is no doubt about what the standard character is. // The input is supposed to be a single Chinese character, but strings of characters are also handled correctly. <DISP, DICT, SEARCH> { // Codepoint < FFFF 倂 { add("併"); } // 5002 --> 4F75 傁 | 叜 { add("叟"); } // 5081, 53DC --> 53DF 竒 { add("奇"); } // 7AD2 --> 5947 幷 { add("并"); } // 5E77 --> 5E76 牀 { add("床"); } // 7240 --> 5E8A 旹 { add("時"); } // 65F9 --> 6642 歴 { add("歷"); } // 6B74 --> 6B77 爲 { add("為"); } // 7232 --> 70BA 隂 { add("陰"); } // 9682 --> 9670 靣 { add("面"); } // 9763 --> 9762 精 { add("精"); } // FA1D --> 7CBE (FA1D is a compatibility ideograph) // Codepoint > FFFF // note that [ABC] is not equivalent to A | B | C for codepoints above FFFF due to their internal encoding: // for example, 庶 (U+2F88D) is represented as a sequence of two codepoints: D87E DC8D // i.e. never use [ABC] but A | B | C 庶 { add("庶"); } // 2F88D --> 5EB6 (2F88D is a compatibility ideograph) } <DICT, SEARCH> { // remove Zero Width Space (if there is any in the the input string) {ZWS} { add(""); } } // default @ { problem = 1; add(yytext()); } . { add(yytext()); } <DISP, SEARCH> { {END} { switch (problem) { case 1: return original; default: return normalized; } } } <DICT> { {END} { switch (problem) { case 1: return ""; default: return normalized; } } } /* Annahmen: - die Routine wird zeichenweise (oder mit mehr als einem Zeichen) aufgerufen, mit einem \n am Ende des Strings - es gibt keine Zeilenumbrüche TO DO: ZH: Liste ergänzen ZH: was ist, wenn man wirklich die Variante, die im Text steht, nachschlagen will? Dann muss man das Zeichen wohl selbst rauskopieren. ZH: sollen lateinische Buchstaben bewirken, dass problem = 1 ist? ZH: sollen Zeilenumbrüche rausgenommen werden, auch wenn sie in korrekt markiertem Text nicht vorkommen? ZH: was ist, wenn beijing übergeben wird und einen Zeilenumbruch enthält? Verlässt sich der Wrapper darauf, dass die Zeichenzahl gleich bleibt, oder macht er ein hyphen rein? was macht <place> oder <reg>? */