view software/mpdl-services/mpiwg-mpdl-lt/bin/de/mpg/mpiwg/berlin/mpdl/lt/text/norm/lang/MpdlNormalizerLexEL.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 Greek text
 * [this is a JFlex specification]
 *
 * Wolfgang Schmidle 
 * version 2011-08-03
 *
 */

package de.mpg.mpiwg.berlin.mpdl.lt.text.norm.lang;

%%

%public
%class MpdlNormalizerLexEL
%type java.lang.String
%unicode

// Greek: el, grc

%states DISP, DICT, SEARCH
%state SIGMA

%{
	private String original = "";
	private String normalized = "";
	private int problem = 0;
	
	private void add (String norm) {
		original += yytext(); 
		normalized += norm;
	}

	private static final String LB = "[\u002d\u00ad] ";
%}

hyphen = [-\u{00ad}]  // hyphen and soft hyphen
LB = {hyphen} \u0020
// lb = ({hyphen} \u0020)?

END = \n

wordend =  [νρς]? {END}

Latin = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]


%%

// jump over empty xml elements
"<"[^><]+"/>" { add(yytext()); }
"-<"[^><]+"/>" { add(yytext()); }
"<"[^><]+"></"[^><]+">" { add(yytext()); }
"-<"[^><]+"></"[^><]+">" { add(yytext()); }


// always replace tonos by oxia 
// (although this should really be corrected in the text rather than normalized)
ά { add("ά"); }
έ { add("έ"); }
ή { add("ή"); }
ί { add("ί"); }
ό { add("ό"); }
ύ { add("ύ"); }
ώ { add("ώ"); }


<DICT, SEARCH, SIGMA> {

ὰ / {wordend} { add("ά"); }
ᾲ / {wordend} { add("ᾴ"); }
ὲ / {wordend} { add("έ"); }
ὴ / {wordend} { add("ή"); }
ῂ / {wordend} { add("ῄ"); }
ὶ / {wordend} { add("ί"); }
ὸ / {wordend} { add("ό"); }
ὺ / {wordend} { add("ύ"); }
ὼ / {wordend} { add("ώ"); }
ῲ / {wordend} { add("ῴ"); }

// other candidates: Ὰ Ὲ Ὴ Ὶ Ὺ Ὸ Ὼ

}

<SIGMA> {

ς { add("σ"); }

}

// default

@ { problem = 1; add(yytext()); }
{Latin} { problem = 1; add(yytext()); }

{LB} { add(yytext()); }
. { add(yytext()); }


<DISP> {

{END} {
		switch (problem) {
			case 1: return original;
			default: return normalized;
		}
	}
}

<DICT, SIGMA> {

{END} {
		switch (problem) {
			case 1: return "";
			default: return normalized.replaceAll(LB, "");
		}
	}
}

<SEARCH> {

{END} {
		switch (problem) {
			case 1: return original;
			default: return normalized.replaceAll(LB, "").toLowerCase();
		}
	}
}


/*

Annahmen:
- die Routine wird wortweise aufgerufen, mit einem \n am Ende des Strings
- Zeilenumbrüche innerhalb des Wortes sind als hyphen/soft hyphen plus space markiert

TO DO:

EL: tonos --> oxia wieder rausnehmen, weil es im Text geändert werden muss?
EL: gibt es noch weitere Fälle, wo legitimerweise ein Gravis vorkommen kann?
EL: kommen Großbuchstaben mit Gravis bei uns jemals vor, und sollen sie normalisiert werden?
EL: neuer State BETACODE ?
EL: nicht falsche Zeichen definieren, sondern erlaubte Zeichen

*/