Fixed ACIP->Unicode spaces/tshegs and newlines, especially with shads.

"NGA," becomes "NGA-tsheg-," automatically now.
This commit is contained in:
dchandler 2003-09-05 05:08:47 +00:00
parent 5c240ac072
commit 717c3b94f3
8 changed files with 151 additions and 107 deletions

View file

@ -797,7 +797,8 @@ public class DuffPane extends TibetanPane implements FocusListener {
before_vowel.add(dc_1);
before_vowel.add(dc_2);
java.util.List after_vowel = TibTextUtils.getVowel(dc_1, dc_2, v);
java.util.List after_vowel = new ArrayList();
TibTextUtils.getVowel(after_vowel, dc_1, dc_2, v);
if (after_vowel.size() >= before_vowel.size()) {
setNumberOfGlyphsForLastVowel(after_vowel.size()
- before_vowel.size());
@ -842,7 +843,8 @@ public class DuffPane extends TibetanPane implements FocusListener {
private void printAChenWithVowel(String v) {
DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(TibetanMachineWeb.ACHEN);
DuffCode dc = dc_array[TibetanMachineWeb.TMW];
java.util.List achenlist = TibTextUtils.getVowel(dc,v);
java.util.List achenlist = new ArrayList();
TibTextUtils.getVowel(achenlist, dc, v);
DuffData[] dd = TibTextUtils.convertGlyphs(achenlist);
getTibDoc().insertDuff(caret.getDot(), dd);
}

View file

@ -375,7 +375,7 @@ public class TibTextUtils implements THDLWylieConstants {
if (!chars.isEmpty()) {
glyphs.addAll(getGlyphs(chars, true, !isSanskrit, isSanskrit));
dc = (DuffCode)glyphs.removeLast(); //LinkedList implementation
glyphs.addAll(getVowel(dc, next));
getVowel(glyphs, dc, next);
chars.clear();
}
else { //if previous is punctuation or null, then achen plus vowel - otherwise, previous could be vowel
@ -387,13 +387,13 @@ public class TibTextUtils implements THDLWylieConstants {
if (!TibetanMachineWeb.isWyliePunc(TibetanMachineWeb.getWylieForGlyph(dc, weDoNotCareIfThereIsCorrespondingWylieOrNot))) {
DuffCode dc_2 = (DuffCode)glyphs.removeLast();
DuffCode dc_1 = (DuffCode)glyphs.removeLast();
glyphs.addAll(getVowel(dc_1, dc_2, next));
getVowel(glyphs, dc_1, dc_2, next);
break vowel_block;
}
}
DuffCode[] dc_array = (DuffCode[])TibetanMachineWeb.getTibHash().get(ACHEN);
dc = dc_array[TibetanMachineWeb.TMW];
glyphs.addAll(getVowel(dc, next));
getVowel(glyphs, dc, next);
}
chars.clear();
@ -442,6 +442,7 @@ public class TibTextUtils implements THDLWylieConstants {
default:
String top_char = (String)chars.get(chars.size()-1);
chars.remove(chars.size()-1);
// DLC PERFORMANCE FIXME: make glyphs a parameter
glyphs.addAll(getGlyphs(chars, true, !isSanskrit, isSanskrit));
chars.clear();
chars.add(top_char);
@ -520,39 +521,39 @@ public class TibTextUtils implements THDLWylieConstants {
* @param vowel the vowel you want to affix, in Wylie
* @return a List of glyphs equal to the vowel in context
*/
public static List getVowel(DuffCode context, String vowel) {
return getVowel(null, context, vowel);
public static void getVowel(List l, DuffCode context, String vowel) {
getVowel(l, null, context, vowel);
}
/**
* Gets the vowel sequence for a given vowel in a given context.
* Given a context, this method affixes a vowel and returns the context plus the vowel.
* Since the choice of vowel glyph depends on the consonant to which it is attached,
* generally it is enough to provide just the immediately preceding context. However,
* in some cases, double vowels are allowed - for example 'buo'. To find the correct
* glyph for 'o', we need 'b' in this case, not 'u'. Note also that some Extended
* Wylie vowels correspond to multiple glyphs in TibetanMachineWeb. For example,
* the vowel I consists of both an achung and a reverse gigu. All required glyphs
* are part of the returned List.
* @param context_1 the glyph occurring two glyphs before the vowel you want to affix
* @param context_2 the glyph immediately before the vowel you want to affix
* @param vowel the vowel you want to affix, in Wylie
* @return a List of glyphs equal to the vowel in context
*/
public static List getVowel(DuffCode context_1, DuffCode context_2, String vowel) {
List vowels = new ArrayList();
* Gets the vowel sequence for a given vowel in a given context and
* appends it to l. Given a context, this method affixes a vowel and
* appends the context plus the vowel to l. Since the choice of vowel
* glyph depends on the consonant to which it is attached, generally it
* is enough to provide just the immediately preceding
* context. However, in some cases, double vowels are allowed - for
* example 'buo'. To find the correct glyph for 'o', we need 'b' in
* this case, not 'u'. Note also that some Extended Wylie vowels
* correspond to multiple glyphs in TibetanMachineWeb. For example, the
* vowel I consists of both an achung and a reverse gigu. All required
* glyphs are appended to l.
* @param context_1 the glyph occurring two glyphs before the vowel you
* want to affix
* @param context_2 the glyph immediately before the vowel you want to
* affix
* @param vowel the vowel you want to affix, in Wylie */
public static void getVowel(List l, DuffCode context_1, DuffCode context_2, String vowel) {
//this vowel doesn't correspond to a glyph -
//so you just return the original context
if ( vowel.equals(WYLIE_aVOWEL) ||
TibetanMachineWeb.isTopVowel(context_2)) {
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
return vowels;
l.add(context_2);
return;
}
//first, the three easiest cases: ai, au, and <i
@ -561,36 +562,36 @@ public class TibTextUtils implements THDLWylieConstants {
if (vowel.equals(ai_VOWEL)) {
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
DuffCode[] dc_v = (DuffCode[])TibetanMachineWeb.getTibHash().get(ai_VOWEL);
vowels.add(dc_v[TibetanMachineWeb.TMW]);
return vowels;
l.add(dc_v[TibetanMachineWeb.TMW]);
return;
}
if (vowel.equals(au_VOWEL)) {
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
DuffCode[] dc_v = (DuffCode[])TibetanMachineWeb.getTibHash().get(au_VOWEL);
vowels.add(dc_v[TibetanMachineWeb.TMW]);
return vowels;
l.add(dc_v[TibetanMachineWeb.TMW]);
return;
}
if (vowel.equals(reverse_i_VOWEL)) {
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
if (!TibetanMachineWeb.isTopVowel(context_2)) {
DuffCode[] dc_v = (DuffCode[])TibetanMachineWeb.getTibHash().get(reverse_i_VOWEL);
vowels.add(dc_v[TibetanMachineWeb.TMW]);
l.add(dc_v[TibetanMachineWeb.TMW]);
}
return vowels;
return;
}
//second, the vowels i, e, and o
@ -609,14 +610,14 @@ public class TibTextUtils implements THDLWylieConstants {
}
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
if (null != dc_v)
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
if (vowel.equals(e_VOWEL)) {
@ -628,14 +629,14 @@ public class TibTextUtils implements THDLWylieConstants {
}
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
if (null != dc_v)
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
if (vowel.equals(o_VOWEL)) {
@ -647,14 +648,14 @@ public class TibTextUtils implements THDLWylieConstants {
}
if (context_1 != null)
vowels.add(context_1);
l.add(context_1);
vowels.add(context_2);
l.add(context_2);
if (null != dc_v)
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
//next come the vowels u, A, and U
@ -669,17 +670,17 @@ public class TibTextUtils implements THDLWylieConstants {
DuffCode dc_v = TibetanMachineWeb.getVowel(hashKey_context, TibetanMachineWeb.VOWEL_u);
if (null != context_1)
vowels.add(context_1);
l.add(context_1);
if (null == halfHeight)
vowels.add(context_2);
l.add(context_2);
else
vowels.add(halfHeight);
l.add(halfHeight);
if (null != dc_v)
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
if (vowel.equals(A_VOWEL)) {
@ -688,18 +689,18 @@ public class TibTextUtils implements THDLWylieConstants {
DuffCode dc_v = TibetanMachineWeb.getVowel(hashKey_context, TibetanMachineWeb.VOWEL_A);
if (null != context_1)
vowels.add(context_1);
l.add(context_1);
if (null == halfHeight)
vowels.add(context_2);
l.add(context_2);
else
vowels.add(halfHeight);
l.add(halfHeight);
if (null != dc_v)
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
if (vowel.equals(U_VOWEL)) {
@ -708,17 +709,17 @@ public class TibTextUtils implements THDLWylieConstants {
DuffCode dc_v = TibetanMachineWeb.getVowel(hashKey_context, TibetanMachineWeb.VOWEL_U);
if (null != context_1)
vowels.add(context_1);
l.add(context_1);
if (null == halfHeight)
vowels.add(context_2);
l.add(context_2);
else
vowels.add(halfHeight);
l.add(halfHeight);
if (null != dc_v && !TibetanMachineWeb.isTopVowel(context_2))
vowels.add(dc_v);
l.add(dc_v);
return vowels;
return;
}
//finally, the vowels I and <I
@ -733,19 +734,19 @@ public class TibTextUtils implements THDLWylieConstants {
DuffCode dc_v_sup = TibetanMachineWeb.getVowel(hashKey_context, TibetanMachineWeb.VOWEL_i);
if (null != context_1)
vowels.add(context_1);
l.add(context_1);
if (null == halfHeight)
vowels.add(context_2);
l.add(context_2);
else
vowels.add(halfHeight);
l.add(halfHeight);
if (null != dc_v_sub && null != dc_v_sup) {
vowels.add(dc_v_sub);
vowels.add(dc_v_sup);
l.add(dc_v_sub);
l.add(dc_v_sup);
}
return vowels;
return;
}
if (vowel.equals(reverse_I_VOWEL)) {
@ -756,22 +757,22 @@ public class TibTextUtils implements THDLWylieConstants {
DuffCode dc_v_sup = tv_array[TibetanMachineWeb.TMW];
if (null != context_1)
vowels.add(context_1);
l.add(context_1);
if (null == halfHeight)
vowels.add(context_2);
l.add(context_2);
else
vowels.add(halfHeight);
l.add(halfHeight);
if (null != dc_v_sub && null != dc_v_sup) {
vowels.add(dc_v_sub);
vowels.add(dc_v_sup);
l.add(dc_v_sub);
l.add(dc_v_sup);
}
return vowels;
return;
}
return null;
throw new Error("DLC can this happen? " + vowel);
}
/**

View file

@ -1161,8 +1161,9 @@ public static String getWylieForVowel(String s) {
}
/**
* Gets the DuffCode required for a vowel, if
* affixed to the given hashKey.
* Gets the DuffCode required for a vowel, if affixed to the given
* hashKey. Not as pretty as {@link
* TibTextUtils#getVowel(DuffCode,DuffCode,String)}.
* @param hashKey the key for the character the vowel is to be affixed
* to; see {@link #getGlyph(String)} to learn about hash keys.
* @param vowel the vowel you want the DuffCode for
@ -1170,7 +1171,7 @@ public static String getWylieForVowel(String s) {
* context, or null if there is no such vowel in
* the context
* @see DuffCode
*/
* @see TibTextUtils#getVowel(DuffCode,DuffCode,String) */
public static DuffCode getVowel(String hashKey, int vowel) {
DuffCode[] dc = (DuffCode[])tibHash.get(hashKey);

View file

@ -132,7 +132,10 @@ public class ACIPConverter {
throws IOException
{
TibetanDocument tdoc = new TibetanDocument();
tdoc.setRomanAttributeSet("Courier", 20); // DLC make me configurable.
tdoc.setRomanAttributeSet(ThdlOptions.getStringOption("thdl.acip.to.x.latin.font",
"Courier New"),
ThdlOptions.getIntegerOption("thdl.acip.to.x.latin.font.size",
20));
boolean rv
= convertToTMW(scan, tdoc, errors, warnings,
writeWarningsToResult, warningLevel);
@ -357,7 +360,7 @@ public class ACIPConverter {
} else if (stype == ACIPString.END_SLASH) {
if (null != writer) unicode = "\u0F3D";
if (null != tdoc) duff = new DuffCode[] { TibetanMachineWeb.getGlyph(")") };
} else {
} else if (stype == ACIPString.TIBETAN_PUNCTUATION) {
// For ACIP, tshegs are used as both
// tshegs and whitespace. We treat a
// space as a tsheg if and only if it
@ -368,8 +371,8 @@ public class ACIPConverter {
// typesetting.
boolean done = false;
// DLC what about after numbers? marks?
if (s.getText().equals(" ")) {
TPairList lpl = null;
if (s.getText().equals(" ")) {
if (!lastGuyWasNonPunct
|| (null != lastGuy
&& (lpl = lastGuy.get(lastGuy.size() - 1)).size() == 1
@ -389,7 +392,16 @@ public class ACIPConverter {
continue;
}
}
} else if (s.getText().equals(",")
&& lastGuyWasNonPunct
&& null != lastGuy
&& (lpl = lastGuy.get(lastGuy.size() - 1)).size() == 1
&& lpl.get(0).getLeft().equals("NG")) {
DuffCode tshegDuff = TibetanMachineWeb.getGlyph(" ");
if (null == tshegDuff) throw new Error("tsheg duff");
tdoc.appendDuffCodes(new DuffCode[] { tshegDuff });
}
if (!done) {
if (null != writer) unicode = ACIPRules.getUnicodeFor(s.getText(), false);
if (null != tdoc) {
@ -406,6 +418,8 @@ public class ACIPConverter {
}
}
}
} else {
throw new Error("forgot a case");
}
if (null != writer && null == unicode)
throw new Error("FIXME: make this an assertion 1");

View file

@ -21,9 +21,12 @@ package org.thdl.tib.text.ttt;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.thdl.tib.text.DuffCode;
import org.thdl.tib.text.THDLWylieConstants;
import org.thdl.tib.text.TibetanMachineWeb;
import org.thdl.tib.text.TibTextUtils;
/** Canonizes some facts regarding the ACIP transcription system.
* @author David Chandler */
@ -460,38 +463,41 @@ class ACIPRules {
/** DLC DOC: Gets the duffcodes for vowel, such that they look good with hashKey, and appends them to r. */
static void getDuffForACIPVowel(ArrayList r, String hashKey, String vowel) {
/** Gets the duffcodes for vowel, such that they look good with
* the stack with hash key hashKey, and appends them to r. */
static void getDuffForACIPVowel(ArrayList r, DuffCode preceding, String vowel) {
if (null == vowel) return;
if (null == getWylieForACIPVowel(vowel)) // FIXME: expensive assertion! Use assert.
throw new IllegalArgumentException("Vowel " + vowel + " isn't in the small set of vowels we handle correctly.");
if (!TibetanMachineWeb.isKnownHashKey(hashKey)) // FIXME: expensive assertion! Use assert.
throw new IllegalArgumentException("bad hashKey");
// Order matters here.
if (vowel.indexOf("'U") >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_U));
else {
if (vowel.startsWith("A")) {
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.WYLIE_aVOWEL);
} else if (vowel.indexOf("'U") >= 0) {
TibTextUtils.getVowel(r, preceding, "U");
} else {
if (vowel.indexOf('\'') >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_A));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.A_VOWEL);
if (vowel.indexOf("EE") >= 0)
r.add(TibetanMachineWeb.getGlyph("ai"));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.ai_VOWEL);
else if (vowel.indexOf('E') >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_e));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.e_VOWEL);
if (vowel.indexOf("OO") >= 0)
r.add(TibetanMachineWeb.getGlyph("au"));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.au_VOWEL);
else if (vowel.indexOf('O') >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_o));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.o_VOWEL);
if (vowel.indexOf('I') >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_i));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.i_VOWEL);
if (vowel.indexOf('U') >= 0)
r.add(TibetanMachineWeb.getVowel(hashKey, TibetanMachineWeb.VOWEL_u));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.u_VOWEL);
if (vowel.indexOf('i') >= 0)
r.add(TibetanMachineWeb.getGlyph("-i"));
TibTextUtils.getVowel(r, preceding, THDLWylieConstants.reverse_i_VOWEL);
}
if (vowel.indexOf('m') >= 0)
r.add(TibetanMachineWeb.getGlyph("M"));
if (vowel.indexOf(':') >= 0)
r.add(TibetanMachineWeb.getGlyph("H"));
}
}

View file

@ -778,11 +778,22 @@ public class ACIPTshegBarScanner {
// careful, so "KA\r\n" and "GA\n" appear where "KA
// \r\n" and "GA \n" should appear.
if (('\r' == ch
|| '\n' == ch)
|| ('\n' == ch && i > 0 && s.charAt(i - 1) != '\r'))
&& !al.isEmpty()
&& ((ACIPString)al.get(al.size() - 1)).getType() == ACIPString.TIBETAN_NON_PUNCTUATION) {
al.add(new ACIPString(" ",
ACIPString.TIBETAN_PUNCTUATION));
al.add(new ACIPString(" ", ACIPString.TIBETAN_PUNCTUATION));
}
// "DANG,\nLHAG" is really "DANG, LHAG". But always? Not if you have "MDO,\n\nKA...".
if (('\r' == ch
|| ('\n' == ch && i > 0 && s.charAt(i - 1) != '\r'))
&& !al.isEmpty()
&& ((ACIPString)al.get(al.size() - 1)).getType() == ACIPString.TIBETAN_PUNCTUATION
&& ((ACIPString)al.get(al.size() - 1)).getText().equals(",")
&& s.charAt(i-1) == ','
&& (i + (('\r' == ch) ? 2 : 1) < sl
&& (s.charAt(i+(('\r' == ch) ? 2 : 1)) != ch))) {
al.add(new ACIPString(" ", ACIPString.TIBETAN_PUNCTUATION));
}
// Don't add in a "\r\n" or "\n" unless there's a

View file

@ -19,6 +19,7 @@ Contributor(s): ______________________________________.
package org.thdl.tib.text.ttt;
import org.thdl.tib.text.TibetanMachineWeb;
import org.thdl.tib.text.DuffCode;
import org.thdl.tib.text.TGCPair;
import org.thdl.util.ThdlDebug;
@ -612,6 +613,7 @@ class TPairList {
/** Appends the DuffCodes that correspond to this grapheme cluster
* to duff. Assumes this is one grapheme cluster. */
void getDuff(ArrayList duff) {
int previousSize = duff.size();
StringBuffer wylieForConsonant = new StringBuffer();
for (int x = 0; x + 1 < size(); x++) {
wylieForConsonant.append(get(x).getWylie(false));
@ -625,8 +627,15 @@ class TPairList {
throw new Error("How did this happen?");
}
}
if (lastPair.getRight() == null || lastPair.equals("-")) {
duff.add(TibetanMachineWeb.getGlyph(hashKey));
ACIPRules.getDuffForACIPVowel(duff, hashKey, lastPair.getRight());
} else {
ACIPRules.getDuffForACIPVowel(duff,
TibetanMachineWeb.getGlyph(hashKey),
lastPair.getRight());
}
if (previousSize == duff.size())
throw new Error("TPairList with no duffs? " + toString()); // DLC FIXME: change to assertion.
}
}
// DLC FIXME: handle 'o' and 'x', e.g. KAo and NYAx.

View file

@ -217,7 +217,7 @@ class TStackList {
}
return u.toString();
}
/** DLC DOC */
/** Returns the DuffCodes corresponding to this stack list. */
DuffCode[] getDuff() {
ArrayList al = new ArrayList(size()*2); // rough estimate
int count = 0;