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

@ -4,6 +4,6 @@ import org.thdl.tib.dictionary.DictionaryEntry ;
import java.util.Collection ; import java.util.Collection ;
public interface DictionaryEntries extends Collection public interface DictionaryEntries extends Collection
{ {
}; };

View file

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

View file

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

View file

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

View file

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

View file

@ -11,32 +11,32 @@ import org.thdl.tib.dictionary.SimpleDictionaryEntries ;
public class ScannerBasedDictionary implements DictionaryInterface 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 ) scanner.clearTokens () ;
{
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++ )
{
SimpleDictionaryEntry entry = SimpleDictionaryEntry.fromWord ( words [i] ) ;
entries.add ( entry ) ;
}
scanner.clearTokens () ; return entries ;
}
return entries ;
}
} }

View file

@ -3,11 +3,11 @@ package org.thdl.tib.dictionary ;
import org.thdl.tib.dictionary.DictionaryEntries ; import org.thdl.tib.dictionary.DictionaryEntries ;
import java.util.LinkedList ; import java.util.LinkedList ;
public class SimpleDictionaryEntries extends LinkedList implements DictionaryEntries public class SimpleDictionaryEntries extends LinkedList implements DictionaryEntries
{ {
public SimpleDictionaryEntries () public SimpleDictionaryEntries ()
{ {
super () ; super () ;
} }
} }

View file

@ -7,70 +7,70 @@ import org.thdl.tib.scanner.Word ;
public class SimpleDictionaryEntry implements DictionaryEntry public class SimpleDictionaryEntry implements DictionaryEntry
{ {
TextBody keyWord ; TextBody keyWord ;
DictionaryEntryDefinitions definitions ; 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 ) return out ;
{ }
//
// TODO
//
return false ;
}
String joinSyllables ( String text ) public TextBody getKeyword ()
{ {
String [] syllables = text.split ( " " ) ; return SimpleTextBody.fromWylie ( joinSyllables ( keyWord.getWylie () ) ) ;
}
String out = "" ; public String getPhonetic ()
for ( int i = 0; i < syllables.length; i++ ) {
{ //
if ( i > 0 ) // if phonetics specified in the dictionary - use it
{ //
if ( hasSpaceBeforeSyllable ( i ) ) // otherwise, generate one (currently the only option)
out += " " ; return joinSyllables ( Phonetics.wylieToStandardPhonetic ( keyWord.getWylie () ) ) ;
else if ( useDashes ) }
out += "-" ;
}
public DictionaryEntryDefinitions getDefinitions ()
{
out += syllables [i] ; return definitions ;
} }
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 ;
}
} }

View file

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

View file

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

View file

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

View file

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