Fixed indentation.

This commit is contained in:
micha3lp 2010-07-05 03:35:17 +00:00
parent aed2e307ba
commit d5d65693f4
14 changed files with 815 additions and 815 deletions

View file

@ -5,8 +5,8 @@ import org.thdl.tib.dictionary.DictionaryEntryDefinitions ;
public interface DictionaryEntry
{
public TextBody getKeyword () ;
public String getPhonetic () ;
public DictionaryEntryDefinitions getDefinitions () ;
public TextBody getKeyword () ;
public String getPhonetic () ;
public DictionaryEntryDefinitions getDefinitions () ;
}

View file

@ -2,5 +2,5 @@ package org.thdl.tib.dictionary ;
public interface DictionaryEntryDefinition
{
public String toString () ;
public String toString () ;
};

View file

@ -2,6 +2,6 @@ package org.thdl.tib.dictionary ;
public interface DictionaryEntryDescription
{
Collection getItems () ;
Collection getItems () ;
};

View file

@ -5,6 +5,6 @@ import org.thdl.tib.dictionary.DictionaryEntries ;
public interface DictionaryInterface
{
DictionaryEntries lookup ( TextBody in ) ;
DictionaryEntries lookup ( TextBody in ) ;
}

View file

@ -4,106 +4,106 @@ import org.thdl.tib.dictionary.StandardPronounciationEngine ;
public class Phonetics
{
public static final String THDL_ENGLISH = "THDL_ENGLISH" ;
public static boolean valid = false ;
public static final String THDL_ENGLISH = "THDL_ENGLISH" ;
public static boolean valid = false ;
static StandardPronounciationEngine pronounciationEngine = null ;
static StandardPronounciationEngine pronounciationEngine = null ;
static
{
try
{
pronounciationEngine = new StandardPronounciationEngine () ;
valid = true ;
}
catch ( Exception e )
{
valid = false ;
}
}
static
{
try
{
pronounciationEngine = new StandardPronounciationEngine () ;
valid = true ;
}
catch ( Exception e )
{
valid = false ;
}
}
public static boolean isValid ()
{
return valid ;
}
public static boolean isValid ()
{
return valid ;
}
public static String standardToLocalized ( String locale, String in )
{
if ( locale.equals ( THDL_ENGLISH ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "K", "kh" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p" ) ;
in = in.replaceAll ( "S", "sh" ) ;
in = in.replaceAll ( "T", "t" ) ;
in = in.replaceAll ( "X", "ts" ) ;
in = in.replaceAll ( "Q", "ts" ) ;
in = in.replaceAll ( "Z", "sh" ) ;
in = in.replaceAll ( "c", "ch" ) ;
in = in.replaceAll ( "C", "ch" ) ;
}
else if ( locale.equals ( "POLISH" ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "ny", "ni" ) ;
in = in.replaceAll ( "w", "\u0142" ) ;
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "C", "cz'" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "j", "dzi" ) ;
in = in.replaceAll ( "K", "k'" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p'" ) ;
in = in.replaceAll ( "S", "sz" ) ;
in = in.replaceAll ( "T", "t'" ) ;
in = in.replaceAll ( "X", "c" ) ;
in = in.replaceAll ( "Q", "ts'" ) ;
in = in.replaceAll ( "y", "j" ) ;
in = in.replaceAll ( "Z", "sz" ) ;
in = in.replaceAll ( "c", "cz" ) ;
}
else if ( locale.equals ( "CZECH" ) || locale.equals ( "SLOVAK" ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "ny", "\u0148" ) ;
in = in.replaceAll ( "w", "v" ) ;
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "C", "\u010d'" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "j", "d\u017e" ) ;
in = in.replaceAll ( "K", "k'" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p'" ) ;
in = in.replaceAll ( "S", "\u0161" ) ;
in = in.replaceAll ( "T", "t'" ) ;
in = in.replaceAll ( "X", "c" ) ;
in = in.replaceAll ( "Q", "ts'" ) ;
in = in.replaceAll ( "y", "j" ) ;
in = in.replaceAll ( "Z", "\u0161" ) ;
in = in.replaceAll ( "c", "\u010d'" ) ;
}
public static String standardToLocalized ( String locale, String in )
{
if ( locale.equals ( THDL_ENGLISH ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "K", "kh" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p" ) ;
in = in.replaceAll ( "S", "sh" ) ;
in = in.replaceAll ( "T", "t" ) ;
in = in.replaceAll ( "X", "ts" ) ;
in = in.replaceAll ( "Q", "ts" ) ;
in = in.replaceAll ( "Z", "sh" ) ;
in = in.replaceAll ( "c", "ch" ) ;
in = in.replaceAll ( "C", "ch" ) ;
}
else if ( locale.equals ( "POLISH" ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "ny", "ni" ) ;
in = in.replaceAll ( "w", "\u0142" ) ;
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "C", "cz'" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "j", "dzi" ) ;
in = in.replaceAll ( "K", "k'" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p'" ) ;
in = in.replaceAll ( "S", "sz" ) ;
in = in.replaceAll ( "T", "t'" ) ;
in = in.replaceAll ( "X", "c" ) ;
in = in.replaceAll ( "Q", "ts'" ) ;
in = in.replaceAll ( "y", "j" ) ;
in = in.replaceAll ( "Z", "sz" ) ;
in = in.replaceAll ( "c", "cz" ) ;
}
else if ( locale.equals ( "CZECH" ) || locale.equals ( "SLOVAK" ) )
{
//
// put back the roman digraphs
//
in = in.replaceAll ( "ny", "\u0148" ) ;
in = in.replaceAll ( "w", "v" ) ;
in = in.replaceAll ( "B", "bh" ) ;
in = in.replaceAll ( "C", "\u010d'" ) ;
in = in.replaceAll ( "D", "dz" ) ;
in = in.replaceAll ( "j", "d\u017e" ) ;
in = in.replaceAll ( "K", "k'" ) ;
in = in.replaceAll ( "N", "ng" ) ;
in = in.replaceAll ( "P", "p'" ) ;
in = in.replaceAll ( "S", "\u0161" ) ;
in = in.replaceAll ( "T", "t'" ) ;
in = in.replaceAll ( "X", "c" ) ;
in = in.replaceAll ( "Q", "ts'" ) ;
in = in.replaceAll ( "y", "j" ) ;
in = in.replaceAll ( "Z", "\u0161" ) ;
in = in.replaceAll ( "c", "\u010d'" ) ;
}
return in ;
}
return in ;
}
public static String wylieToStandardPhonetic ( String wylie )
{
try
{
return pronounciationEngine.processWylie ( wylie ) ;
}
catch ( Exception e )
{
return "<INVALID>" ;
}
}
public static String wylieToStandardPhonetic ( String wylie )
{
try
{
return pronounciationEngine.processWylie ( wylie ) ;
}
catch ( Exception e )
{
return "<INVALID>" ;
}
}
}

View file

@ -11,32 +11,32 @@ import org.thdl.tib.dictionary.SimpleDictionaryEntries ;
public class ScannerBasedDictionary implements DictionaryInterface
{
TibetanScanner scanner ;
TibetanScanner scanner ;
public ScannerBasedDictionary ( TibetanScanner ts )
public ScannerBasedDictionary ( TibetanScanner ts )
{
scanner = ts ;
}
public DictionaryEntries lookup ( TextBody tb )
{
DictionaryEntries entries = new SimpleDictionaryEntries () ;
//
// TibetanScanner expects romanized wylie for lookup
//
String input = tb.getRomanizedWylie () ;
scanner.scanBody ( input ) ;
scanner.finishUp () ;
Word [] words = scanner.getWordArray () ;
for ( int i = 0; i < words.length; i++ )
{
scanner = ts ;
SimpleDictionaryEntry entry = SimpleDictionaryEntry.fromWord ( words [i] ) ;
entries.add ( entry ) ;
}
public DictionaryEntries lookup ( TextBody tb )
{
DictionaryEntries entries = new SimpleDictionaryEntries () ;
//
// TibetanScanner expects romanized wylie for lookup
//
String input = tb.getRomanizedWylie () ;
scanner.clearTokens () ;
scanner.scanBody ( input ) ;
scanner.finishUp () ;
Word [] words = scanner.getWordArray () ;
for ( int i = 0; i < words.length; i++ )
{
SimpleDictionaryEntry entry = SimpleDictionaryEntry.fromWord ( words [i] ) ;
entries.add ( entry ) ;
}
scanner.clearTokens () ;
return entries ;
}
return entries ;
}
}

View file

@ -5,9 +5,9 @@ import java.util.LinkedList ;
public class SimpleDictionaryEntries extends LinkedList implements DictionaryEntries
{
public SimpleDictionaryEntries ()
{
super () ;
}
public SimpleDictionaryEntries ()
{
super () ;
}
}

View file

@ -7,70 +7,70 @@ import org.thdl.tib.scanner.Word ;
public class SimpleDictionaryEntry implements DictionaryEntry
{
TextBody keyWord ;
DictionaryEntryDefinitions definitions ;
TextBody keyWord ;
DictionaryEntryDefinitions definitions ;
static boolean useDashes = true ;
static boolean useDashes = true ;
public static SimpleDictionaryEntry fromWord ( Word word )
public static SimpleDictionaryEntry fromWord ( Word word )
{
SimpleDictionaryEntry sde = new SimpleDictionaryEntry () ;
sde.definitions = SimpleDictionaryEntryDefinitions.fromDefinitions ( word.getDefs () ) ;
sde.keyWord = SimpleTextBody.fromWylie ( word.getWylie () ) ;
//sde.spaceInfo = word.getSpaceInfo or something like that
return sde ;
}
boolean hasSpaceBeforeSyllable ( int syllableIndex )
{
//
// TODO
//
return false ;
}
String joinSyllables ( String text )
{
String [] syllables = text.split ( " " ) ;
String out = "" ;
for ( int i = 0; i < syllables.length; i++ )
{
SimpleDictionaryEntry sde = new SimpleDictionaryEntry () ;
if ( i > 0 )
{
if ( hasSpaceBeforeSyllable ( i ) )
out += " " ;
else if ( useDashes )
out += "-" ;
}
sde.definitions = SimpleDictionaryEntryDefinitions.fromDefinitions ( word.getDefs () ) ;
sde.keyWord = SimpleTextBody.fromWylie ( word.getWylie () ) ;
//sde.spaceInfo = word.getSpaceInfo or something like that
return sde ;
out += syllables [i] ;
}
boolean hasSpaceBeforeSyllable ( int syllableIndex )
{
//
// TODO
//
return false ;
}
return out ;
}
String joinSyllables ( String text )
{
String [] syllables = text.split ( " " ) ;
public TextBody getKeyword ()
{
return SimpleTextBody.fromWylie ( joinSyllables ( keyWord.getWylie () ) ) ;
}
String out = "" ;
for ( int i = 0; i < syllables.length; i++ )
{
if ( i > 0 )
{
if ( hasSpaceBeforeSyllable ( i ) )
out += " " ;
else if ( useDashes )
out += "-" ;
}
public String getPhonetic ()
{
//
// if phonetics specified in the dictionary - use it
//
// otherwise, generate one (currently the only option)
return joinSyllables ( Phonetics.wylieToStandardPhonetic ( keyWord.getWylie () ) ) ;
}
out += syllables [i] ;
}
return out ;
}
public TextBody getKeyword ()
{
return SimpleTextBody.fromWylie ( joinSyllables ( keyWord.getWylie () ) ) ;
}
public String getPhonetic ()
{
//
// if phonetics specified in the dictionary - use it
//
// otherwise, generate one (currently the only option)
return joinSyllables ( Phonetics.wylieToStandardPhonetic ( keyWord.getWylie () ) ) ;
}
public DictionaryEntryDefinitions getDefinitions ()
{
return definitions ;
}
public DictionaryEntryDefinitions getDefinitions ()
{
return definitions ;
}
}

View file

@ -4,15 +4,15 @@ import org.thdl.tib.dictionary.DictionaryEntryDefinition ;
class SimpleDictionaryEntryDefinition implements DictionaryEntryDefinition
{
String body ;
String body ;
public SimpleDictionaryEntryDefinition ( String theBody )
{
body = theBody ;
}
public SimpleDictionaryEntryDefinition ( String theBody )
{
body = theBody ;
}
public String toString ()
{
return body ;
}
public String toString ()
{
return body ;
}
}

View file

@ -9,41 +9,41 @@ import org.thdl.tib.dictionary.SimpleDictionaryEntryDefinition ;
class SimpleDictionaryEntryDefinitions extends Vector implements DictionaryEntryDefinitions
{
public static SimpleDictionaryEntryDefinitions fromDefinitions ( Definitions defs )
public static SimpleDictionaryEntryDefinitions fromDefinitions ( Definitions defs )
{
SimpleDictionaryEntryDefinitions sded = new SimpleDictionaryEntryDefinitions () ;
sded.populate ( defs ) ;
return sded ;
}
protected void populate ( Definitions defs )
{
DictionarySource source = defs.getDictionarySource () ;
String [] defArr = defs.def ;
int i,j;
if (FileSyllableListTree.versionNumber==2)
{
SimpleDictionaryEntryDefinitions sded = new SimpleDictionaryEntryDefinitions () ;
sded.populate ( defs ) ;
return sded ;
this.add ( new SimpleDictionaryEntryDefinition ( "(" + source.getTag(0) + ") " + defArr[0] ) ) ;
for (i=1; i<defArr.length; i++)
this.add ( new SimpleDictionaryEntryDefinition ( "(" + source.getTag(i) + ") " + defArr[i] ) ) ;
}
else
{
ByteDictionarySource sourceb = (ByteDictionarySource) source;
j=0;
while (sourceb.isEmpty(j)) j++;
protected void populate ( Definitions defs )
{
DictionarySource source = defs.getDictionarySource () ;
String [] defArr = defs.def ;
this.add ( new SimpleDictionaryEntryDefinition ( "(" + sourceb.getTag(j) + ") " + defArr[0] ) ) ;
for (i=1; i<defArr.length; i++)
{
j++;
while (sourceb.isEmpty(j)) j++;
int i,j;
if (FileSyllableListTree.versionNumber==2)
{
this.add ( new SimpleDictionaryEntryDefinition ( "(" + source.getTag(0) + ") " + defArr[0] ) ) ;
for (i=1; i<defArr.length; i++)
this.add ( new SimpleDictionaryEntryDefinition ( "(" + source.getTag(i) + ") " + defArr[i] ) ) ;
}
else
{
ByteDictionarySource sourceb = (ByteDictionarySource) source;
j=0;
while (sourceb.isEmpty(j)) j++;
this.add ( new SimpleDictionaryEntryDefinition ( "(" + sourceb.getTag(j) + ") " + defArr[0] ) ) ;
for (i=1; i<defArr.length; i++)
{
j++;
while (sourceb.isEmpty(j)) j++;
this.add ( new SimpleDictionaryEntryDefinition ( "(" + sourceb.getTag(j) + ") " + defArr[i] ) ) ;
}
}
}
this.add ( new SimpleDictionaryEntryDefinition ( "(" + sourceb.getTag(j) + ") " + defArr[i] ) ) ;
}
}
}
}

View file

@ -4,99 +4,99 @@ import org.thdl.tib.dictionary.TextBody ;
public class SimpleTextBody implements TextBody
{
static final int UNDEFINED_TYPE = 0 ;
static final int WYLIE_TYPE = 1 ;
static final int UNICODE_TYPE = 2 ;
static final int UNDEFINED_TYPE = 0 ;
static final int WYLIE_TYPE = 1 ;
static final int UNICODE_TYPE = 2 ;
protected int basicType = UNDEFINED_TYPE ;
protected int basicType = UNDEFINED_TYPE ;
String unicode ;
String wylie ;
String unicode ;
String wylie ;
SimpleTextBody ()
SimpleTextBody ()
{
unicode = "" ;
wylie = "" ;
}
public static TextBody fromWylie ( String in )
{
SimpleTextBody stb = new SimpleTextBody () ;
stb.setWylie ( in ) ;
return stb ;
}
public static TextBody fromUnicode ( String in )
{
SimpleTextBody stb = new SimpleTextBody () ;
stb.setUnicode ( in ) ;
return stb ;
}
public void setWylie ( String in )
{
wylie = in ;
basicType = WYLIE_TYPE ;
}
public void setUnicode ( String in )
{
unicode = in ;
basicType = UNICODE_TYPE ;
}
public String getRomanizedWylie ()
{
String ret = getWylie () ;
ret = ret.replaceAll ( "[\\/\\_\\*]", " " ) ;
return ret ;
}
public String getUnicode ()
{
if ( UNICODE_TYPE == basicType )
{
unicode = "" ;
wylie = "" ;
return unicode ;
}
public static TextBody fromWylie ( String in )
else if ( WYLIE_TYPE == basicType )
{
SimpleTextBody stb = new SimpleTextBody () ;
stb.setWylie ( in ) ;
return stb ;
return wylieToUnicode ( unicode ) ;
}
public static TextBody fromUnicode ( String in )
else
{
SimpleTextBody stb = new SimpleTextBody () ;
stb.setUnicode ( in ) ;
return stb ;
return "" ;
}
}
public void setWylie ( String in )
public String getWylie ()
{
if ( WYLIE_TYPE == basicType )
{
wylie = in ;
basicType = WYLIE_TYPE ;
return wylie ;
}
public void setUnicode ( String in )
else if ( UNICODE_TYPE == basicType )
{
unicode = in ;
basicType = UNICODE_TYPE ;
return unicodeToWylie ( unicode ) ;
}
else
{
return "" ;
}
}
public String getRomanizedWylie ()
{
String ret = getWylie () ;
protected static String unicodeToWylie ( String in )
{
return "<INVALID>" ;
}
ret = ret.replaceAll ( "[\\/\\_\\*]", " " ) ;
return ret ;
}
public String getUnicode ()
{
if ( UNICODE_TYPE == basicType )
{
return unicode ;
}
else if ( WYLIE_TYPE == basicType )
{
return wylieToUnicode ( unicode ) ;
}
else
{
return "" ;
}
}
public String getWylie ()
{
if ( WYLIE_TYPE == basicType )
{
return wylie ;
}
else if ( UNICODE_TYPE == basicType )
{
return unicodeToWylie ( unicode ) ;
}
else
{
return "" ;
}
}
protected static String unicodeToWylie ( String in )
{
return "<INVALID>" ;
}
protected static String wylieToUnicode ( String in )
{
return "<INVALID>" ;
}
protected static String wylieToUnicode ( String in )
{
return "<INVALID>" ;
}
};

View file

@ -4,39 +4,39 @@ import java.lang.String ;
public interface TextBody
{
/**
* setWylie
*
* populate TextBody based on romanized Wylie input string
*/
void setWylie ( String in ) ;
/**
* setWylie
*
* populate TextBody based on romanized Wylie input string
*/
void setWylie ( String in ) ;
/**
* setUnicode
*
* populate TextBody based on Unicode input string
*/
void setUnicode ( String in ) ;
/**
* setUnicode
*
* populate TextBody based on Unicode input string
*/
void setUnicode ( String in ) ;
/**
* getRomanizedWylie
*
* populate TextBody based on romanized Wylie input string
*/
public String getRomanizedWylie () ;
/**
* getRomanizedWylie
*
* populate TextBody based on romanized Wylie input string
*/
public String getRomanizedWylie () ;
/**
* getWylie
*
* populate TextBody based on Wylie input string
*/
public String getWylie () ;
/**
* getWylie
*
* populate TextBody based on Wylie input string
*/
public String getWylie () ;
/**
* getUnicode
*
* populate TextBody based on Unicode input string
*/
public String getUnicode () ;
/**
* getUnicode
*
* populate TextBody based on Unicode input string
*/
public String getUnicode () ;
}