Andres Montano's Translation Tool code

This commit is contained in:
eg3p 2002-10-03 19:28:09 +00:00
parent 63316fecf4
commit f968d42b55
30 changed files with 4393 additions and 0 deletions

View file

@ -0,0 +1,119 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
class AboutDialog extends Dialog implements ActionListener, WindowListener
{
public AboutDialog(Frame parent)
{
super(parent, "About...", true);
Button close = new Button("Close this window");
add(close, BorderLayout.NORTH);
close.addActionListener(this);
TextArea ta = new TextArea(TibetanScanner.aboutUnicode,0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
ta.setEditable(false);
addWindowListener(this);
add(ta, BorderLayout.CENTER);
setSize(240,300); // the size ipaq's window.
}
public void actionPerformed(ActionEvent e)
{
hide();
}
/**
* Cierra la ventana. Invocado unicamente cuando el programa corre
* como aplicacion, para que el programa pare su ejecucion cuando
* el usuario cierre la ventana principal.
*/
public void windowClosing(WindowEvent e)
{
hide();
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowActivated(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowClosed(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowDeactivated(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowDeiconified(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowIconified(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowOpened(WindowEvent e)
{
}
}

View file

@ -0,0 +1,149 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import javax.swing.table.TableCellRenderer;
import javax.swing.border.*;
import javax.swing.*;
import java.io.Serializable;
/** Used by DictionaryTable to display multiple lines of
text (in Roman script) in a single cell.
@author Andr&eacute;s Montano Pellegrini
@see DictionaryTable
*/
public class AlmostDefaultTableCellRenderer extends JTextArea
implements TableCellRenderer, Serializable
{
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
// We need a place to store the color the JTextArea should be returned
// to after its foreground and background colors have been set
// to the selection background color.
// These ivars will be made protected when their names are finalized.
private Color unselectedForeground;
private Color unselectedBackground;
public AlmostDefaultTableCellRenderer()
{
super();
setLineWrap(true);
setWrapStyleWord(true);
setOpaque(true);
setBorder(noFocusBorder);
}
/**
* Overrides <code>JComponent.setForeground</code> to assign
* the unselected-foreground color to the specified color.
*
* @param c set the foreground color to this value
*/
public void setForeground(Color c) {
super.setForeground(c);
unselectedForeground = c;
}
/**
* Overrides <code>JComponent.setForeground</code> to assign
* the unselected-background color to the specified color.
*
* @param c set the background color to this value
*/
public void setBackground(Color c) {
super.setBackground(c);
unselectedBackground = c;
}
/**
* Notification from the <code>UIManager</code> that the look and feel
* [L&F] has changed.
* Replaces the current UI object with the latest version from the
* <code>UIManager</code>.
*
* @see JComponent#updateUI
*/
public void updateUI() {
super.updateUI();
setForeground(null);
setBackground(null);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected)
{
super.setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
}
else
{
super.setForeground((unselectedForeground != null) ? unselectedForeground : table.getForeground());
super.setBackground((unselectedBackground != null) ? unselectedBackground : table.getBackground());
}
if (hasFocus) {
setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
if (table.isCellEditable(row, column)) {
super.setForeground( UIManager.getColor("Table.focusCellForeground") );
super.setBackground( UIManager.getColor("Table.focusCellBackground") );
}
} else {
setBorder(noFocusBorder);
}
setValue(value);
// ---- begin optimization to avoid painting background ----
Color back = getBackground();
boolean colorMatch = (back != null) && ( back.equals(table.getBackground()) ) && table.isOpaque();
setOpaque(!colorMatch);
// ---- end optimization to aviod painting background ----
return this;
}
/**
Este metodo no funciona, pero es llamado.
que hago para devolver el valor correcto!
*/
public int getLineCount(Object value, int width)
{
setValue(value);
setSize(width, Integer.MAX_VALUE);
return getLineCount();
}
protected void setValue(Object value)
{
setText((value==null)? "" : value.toString());
}
}

View file

@ -0,0 +1,264 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.applet.Applet;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.event.*;
import java.awt.datatransfer.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** Inputs a Tibetan text and displays the words with
their definitions through through a graphical interfase using a
Browser over the Internet. The graphical interfase is provided
by implementations of the ScannerPanel.
<p>Parameter URL should contain the URL of the
servlet which is going to handle to the
looking up of the words in the server.</p>
<p>Since the applet uses Swing for the THDL inputting
system, run the HTML file through Sun's Java Plug-in
HTML Converter to ensure that the browser will
use a JVM to run the applet.</p>
@author Andr&eacute;s Montano Pellegrini
@see RemoteScannerFilter
@see ScannerPannel
*/
public class AppletScannerFilter extends JApplet implements ActionListener, FocusListener, ItemListener
{
private JMenuItem mnuSelectAll, aboutItem, mnuClear; // mnuCut, mnuCopy, mnuPaste, mnuDelete
private JCheckBoxMenuItem tibScript;
// private JMenu mnuEdit;
private Object objModified;
private Dialog diagAbout;
ScannerPanel sp;
public void init()
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
}
String url = getParameter("url");
if (url.indexOf("http://")<0)
{
url = getCodeBase() + url;
}
// panel = new SimpleScannerPanel(url);
sp = new DuffScannerPanel(url);
sp.addFocusListener(this);
setContentPane(sp);
// setup the menu. Almost identical to WindowScannerFilter, but using swing.
JMenuBar mb = new JMenuBar();
// mnuEdit
JMenu m = new JMenu ("Edit");
/* mnuCut = new JMenuItem("Cut");
mnuEdit.add(mnuCut);
mnuCut.addActionListener(this);
mnuCopy = new JMenuItem("Copy");
mnuEdit.add(mnuCopy);
mnuCopy.addActionListener(this);
mnuPaste = new JMenuItem("Paste");
mnuEdit.add(mnuPaste);
mnuPaste.addActionListener(this);
mnuDelete = new JMenuItem("Delete");
mnuEdit.add(mnuDelete);
mnuDelete.addActionListener(this);
mnuEdit.addSeparator();*/
mnuSelectAll = new JMenuItem("Select all");
m.add(mnuSelectAll);
mnuSelectAll.addActionListener(this);
mnuClear = new JMenuItem("Clear all");
m.add(mnuClear);
mnuClear.addActionListener(this);
mb.add(m);
m = new JMenu("View");
tibScript = new JCheckBoxMenuItem("Tibetan Script", true);
m.add(tibScript);
tibScript.addItemListener(this);
mb.add(m);
//JMenuItem
aboutItem = new JMenuItem("About...");
aboutItem.addActionListener(this);
m = new JMenu("Help");
m.add(aboutItem);
mb.add(m);
setJMenuBar(mb);
//mnuEdit.setEnabled(false);
}
/** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at.
*/
public void focusGained(FocusEvent e)
{
objModified = e.getSource();
/* boolean isEditable=false;
if (objModified instanceof TextComponent)
{
TextComponent t = (TextComponent) objModified;
isEditable = t.isEditable();
}
else if (objModified instanceof JTextComponent)
{
JTextComponent j = (JTextComponent) objModified;
isEditable = j.isEditable();
}
//mnuEdit.setEnabled(true);
mnuCut.setEnabled(isEditable);
if (isEditable)
{
if (Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)!=null)
mnuPaste.setEnabled(true);
}
else mnuPaste.setEnabled(false);
mnuDelete.setEnabled(isEditable);*/
}
/** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at.
*/
public void focusLost(FocusEvent e)
{
/* mnuEdit.setEnabled(false);
objModified=null;*/
}
public void actionPerformed(ActionEvent e)
{
Object clicked = e.getSource();
/* StringSelection ss;
String s = null;
int start, end;*/
if (clicked==aboutItem)
{
JOptionPane.showMessageDialog(AppletScannerFilter.this, TibetanScanner.aboutUnicode, "About", JOptionPane.PLAIN_MESSAGE);
}
else if (clicked == mnuClear)
{
sp.clear();
}
else
{
if (objModified==null) return;
if (objModified instanceof TextArea)
{
TextArea t = (TextArea) objModified;
/*if (clicked == mnuCut)
{
ss = new StringSelection(t.getSelectedText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd());
}
else if (clicked == mnuCopy)
{
ss = new StringSelection(t.getSelectedText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
}
else if (clicked == mnuPaste)
{
Transferable data = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
try
{
s = (String)(data.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception ex)
{
s = data.toString();
}
JOptionPane.showMessageDialog(AppletScannerFilter.this, s, "About", JOptionPane.PLAIN_MESSAGE);
t.insert(s, t.getCaretPosition());
}
else if (clicked == mnuDelete)
{
t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd());
}
else*/ if (clicked == mnuSelectAll)
{
t.selectAll();
}
}
else if (objModified instanceof DuffPane)
{
DuffPane t = (DuffPane) objModified;
/*if (clicked == mnuCut)
{
t.copy(t.getSelectionStart(), t.getSelectionEnd(), true);
}
else if (clicked == mnuCopy)
{
t.copy(t.getSelectionStart(), t.getSelectionEnd(), false);
}
else if (clicked == mnuPaste)
{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable data = clipboard.getContents(this);
s = null;
try {
s = (String)(data.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception ex) {
s = data.toString();
}
JOptionPane.showMessageDialog(AppletScannerFilter.this, s, "About", JOptionPane.PLAIN_MESSAGE);
t.paste(t.getCaret().getDot());
}
else if (clicked == mnuDelete)
{
try
{
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else*/ if (clicked == mnuSelectAll)
{
t.selectAll();
}
}
}
}
public void itemStateChanged(ItemEvent e)
{
sp.setEnableTibetanScript(e.getStateChange()==ItemEvent.SELECTED);
}
}

View file

@ -0,0 +1,332 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
/** Converts Tibetan dictionaries stored in text files
into a binary file tree structure format, to be used
by some implementations of the SyllableListTree.
<p>The text files must be in the format used by the
The Rangjung Yeshe Tibetan-English Dictionary of Buddhist Culture.</p>
@author Andr&eacute;s Montano Pellegrini
@see SyllableListTree
@see FileSyllableListTree
@see CachedSyllableListTree
*/
public class BinaryFileGenerator extends LinkedList
{
private long posHijos;
private String sil, def[];
private static char delimiter;
/** Number of dictionary. If 0, partial word (no definition).
*/
private DictionarySource sourceDef;
public static RandomAccessFile wordRaf;
private static RandomAccessFile defRaf;
static
{
wordRaf = null;
defRaf = null;
delimiter = '-';
}
public BinaryFileGenerator()
{
super();
sil = null;
def = null;
posHijos=-1;
sourceDef = null;
}
public BinaryFileGenerator(String sil, String def, int numDef)
{
super();
int marker = sil.indexOf(" ");
this.sourceDef = new DictionarySource();
if (marker<0)
{
this.sil = sil;
this.def = new String[1];
this.def[0] = def;
this.sourceDef.add(numDef);
}
else
{
this.sil = sil.substring(0, marker);
this.def = null;
addLast(new BinaryFileGenerator(sil.substring(marker+1).trim(), def, numDef));
}
posHijos=-1;
}
public String toString()
{
return sil;
}
private static String deleteQuotes(String s)
{
int length = s.length();
if (length>2)
{
if ((s.charAt(0)=='\"') && (s.charAt(length-1)=='\"'))
return s.substring(1,length-2);
}
return s;
}
public void addFile(String archivo, int defNum) throws Exception
{
int marker, linea;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo)));
String entrada, s1, s2;
linea=1;
while ((entrada = br.readLine())!=null)
{
entrada = entrada.trim();
if (!entrada.equals(""))
{
marker = entrada.indexOf(delimiter);
if (marker<0)
{
System.out.println("Error loading line " + linea + ", in file " + archivo + ":");
System.out.println(entrada);
}
else
{
s1 = deleteQuotes(entrada.substring(0,marker).trim());
s2 = deleteQuotes(entrada.substring(marker+1).trim());
add(s1, s2 , defNum);
}
}
linea++;
}
}
private void add(String word, String def, int defNum)
{
Link link, newLink;
BinaryFileGenerator ultimo;
String firstSillable;
int pos, marker = word.indexOf(" "), comp;
if (marker<0)
firstSillable = word;
else firstSillable = word.substring(0,marker);
/* usa orden alfabetico */
if (isEmpty() || ((comp = firstSillable.compareTo((ultimo = (BinaryFileGenerator) getLast()).toString()))<0))
{
super.addLast(new BinaryFileGenerator(word, def, defNum));
}
else
{
if (comp==0)
if (marker<0) ultimo.addMoreDef(def, defNum);
else ultimo.add(word.substring(marker+1).trim(), def, defNum);
else
{
link = cabeza;
while(link.siguiente!=null)
{
comp = firstSillable.compareTo(link.siguiente.toString());
if (comp<0)
{
newLink = new Link(new BinaryFileGenerator(word, def, defNum));
newLink.siguiente = link.siguiente;
link.siguiente = newLink;
return;
}
else
if (comp==0)
{
ultimo = (BinaryFileGenerator) link.siguiente.get();
if (marker<0) ultimo.addMoreDef(def, defNum);
else ultimo.add(word.substring(marker+1).trim(), def, defNum);
return;
}
link = link.siguiente;
}
newLink = new Link(new BinaryFileGenerator(word, def, defNum));
link.siguiente = newLink;
}
}
}
private void addMoreDef(String def, int numDef)
{
if (this.def==null)
{
this.def = new String[1];
this.def[0] = def;
sourceDef.add(numDef);
}
else
{
// if the word is repeated in the same dictionary
if (sourceDef.contains(numDef))
this.def[this.def.length-1] = this.def[this.def.length-1] + ". " + def;
else
{
int i=0;
String newDef[] = new String[this.def.length+1];
while(i<this.def.length)
{
newDef[i] = this.def[i];
i++;
}
newDef[i] = def;
this.def = newDef;
sourceDef.add(numDef);
}
}
}
public boolean equals (Object o)
{
if (o instanceof String)
{
return sil.equals((String)o);
}
else return false;
}
private void printMe(boolean hasNext) throws Exception
{
int i;
wordRaf.writeInt((int) posHijos);
wordRaf.writeUTF(sil);
sourceDef.print(hasNext, wordRaf);
if (def!=null)
for (i=0; i<def.length; i++)
{
wordRaf.writeInt((int)defRaf.getFilePointer());
defRaf.writeUTF(def[i]);
}
}
private void print() throws Exception
{
long pos;
ListIterator i = listIterator();
BinaryFileGenerator silHijos;
boolean hasNext;
while (i.hasNext())
{
silHijos = (BinaryFileGenerator) i.next();
if (!silHijos.isEmpty()) silHijos.print();
}
pos = wordRaf.getFilePointer();
if (!isEmpty())
{
posHijos=pos;
i = listIterator();
hasNext = true;
while (hasNext)
{
silHijos = (BinaryFileGenerator) i.next();
hasNext=i.hasNext();
silHijos.printMe(hasNext);
}
}
}
private static void printSintax()
{
System.out.println("Stores multiple dictionaries into a binary tree file.");
System.out.println("Sintaxis:");
System.out.println("-For multiple dictionary sources:");
System.out.println(" java BinaryFileGenerator arch-dest [-delimiter1] arch-dict1 [[-delimiter2] arch-dict2 ...]");
System.out.println("-For one dictionary");
System.out.println(" java BinaryFileGenerator [-delimiter] arch-dict");
System.out.println("Dictionary files are assumed to be .txt. Don't include extensions!");
System.out.println(" -delimiter: default value is \'-\'. -tab takes \'\\t\' as delimiter.");
}
public static void main(String args[]) throws Exception
{
int i, n=0, a;
if (args.length==0)
{
printSintax();
return;
}
BinaryFileGenerator sl = new BinaryFileGenerator();
if (args[0].charAt(0)=='-')
{
if (args[0].equals("-tab"))
delimiter='\t';
else
delimiter=args[0].charAt(1);
if (args.length>2)
{
printSintax();
return;
}
sl.addFile(args[1] + ".txt",0);
a=1;
}
else
{
a=0;
if (args.length==1)
{
sl.addFile(args[0] + ".txt",0);
}
else
{
i=1;
while(i< args.length)
{
if (args[i].charAt(0)=='-')
{
if (args[i].equals("-tab"))
delimiter='\t';
else
delimiter=args[i].charAt(1);
i++;
}
else delimiter='-';
sl.addFile(args[i] + ".txt", n);
n++; i++;
}
}
}
File wordF = new File(args[a] + ".wrd"), defF = new File(args[a] + ".def");
wordF.delete();
defF.delete();
wordRaf = new RandomAccessFile(wordF,"rw");
defRaf = new RandomAccessFile(defF,"rw");
sl.print();
wordRaf.writeInt((int)sl.posHijos);
}
}

View file

@ -0,0 +1,114 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
/** Provides recommended implementation of the SyllableListTree
(currently most efficient memory-speed combination) loading
into memory only the &quot;trunk&quot; of the tree, and
searching the rest of the tree directly in the file.
<p>The words must be stored in a binary file tree structure format.
This can be done using the BinaryFileGenerator.</p>
@author Andr&eacute;s Montano Pellegrini
@see TibetanScanner
@see BinaryFileGenerator
*/
public class CachedSyllableListTree implements SyllableListTree
{
SyllableListTree syllables[];
public CachedSyllableListTree(String archivo) throws Exception
{
String sil;
long pos, defSources[];
DictionarySource sourceDef;
int i;
FileSyllableListTree.openFiles(archivo);
long posLista = FileSyllableListTree.wordRaf.length() - 4;
LinkedList syllables = new LinkedList();
FileSyllableListTree.wordRaf.seek(posLista);
posLista = (long) FileSyllableListTree.wordRaf.readInt();
FileSyllableListTree.wordRaf.seek(posLista);
do
{
pos = (long) FileSyllableListTree.wordRaf.readInt();
sil = FileSyllableListTree.wordRaf.readUTF();
sourceDef = DictionarySource.read(FileSyllableListTree.wordRaf);
if (sourceDef.isEmpty()) defSources = null;
else
{
defSources = new long[sourceDef.countDefs()];
for (i=0; i<defSources.length; i++)
{
defSources[i] = (long) FileSyllableListTree.wordRaf.readInt();
}
}
syllables.addLast(new FileSyllableListTree(sil, defSources, sourceDef, pos));
}while(sourceDef.hasBrothers());
int n = syllables.size();
this.syllables = new SyllableListTree[n];
ListIterator li = syllables.listIterator();
while (li.hasNext())
{
n--;
this.syllables[n] = (SyllableListTree) li.next();
}
}
public String getDef()
{
return null;
}
public Definitions getDefs()
{
return null;
}
public DictionarySource getDictionarySource()
{
return FileSyllableListTree.defSourcesWanted;
}
public boolean hasDef()
{
return false;
}
public SyllableListTree lookUp(String silStr)
{
int principio=0, medio, fin=syllables.length-1, comp;
if (silStr==null) return null;
while (principio<=fin)
{
medio = (principio+fin)/2;
comp = syllables[medio].toString().compareTo(silStr);
if (comp==0) return syllables[medio];
else
if (comp<0) principio = medio+1;
else fin = medio-1;
}
return null;
}
}

View file

@ -0,0 +1,122 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
import java.net.*;
import java.util.*;
/** Inputs a Tibetan text and displays the words with
their definitions through the console over a shell.
@author Andr&eacute;s Montano Pellegrini
*/
class ConsoleScannerFilter
{
private BufferedReader in;
private PrintWriter out;
private TibetanScanner scanner;
public ConsoleScannerFilter(String archivo, BufferedReader in, PrintWriter out) throws Exception
{
this.in = in;
this.out = out;
scanner = new LocalTibetanScanner(archivo);
scanner.getDictionaryDescriptions();
}
public static void main (String[] args) throws Exception
{
PrintWriter out;
BufferedReader in=null;
boolean file=false;
if (args.length==0)
{
System.out.println("Sintaxis: java ConsoleScannerFilter arch-dict [orig] [dest]");
System.out.println(TibetanScanner.copyrightASCII);
return;
}
switch (args.length)
{
case 1: out = new PrintWriter(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
break;
case 2: out = new PrintWriter(System.out);
file = true;
break;
default: out = new PrintWriter(new FileOutputStream(args[2]));
file = true;
}
if (file)
{
if (args[1].indexOf("http://") >= 0)
in = new BufferedReader(new InputStreamReader(new BufferedInputStream((new URL(args[1])).openStream())));
else
in = new BufferedReader(new InputStreamReader(new FileInputStream(args[1])));
}
new ConsoleScannerFilter(args[0], in, out).run();
}
public void printIfSomething(String s)
{
if (s!=null && !s.equals(""))
{
out.println(s);
out.flush();
}
}
public void printWords()
{
LinkedList words = scanner.getTokenLinkedList();
ListIterator i = words.listIterator();
Token token;
while (i.hasNext())
{
token = (Token)i.next();
if (token instanceof Word)
out.println(token);
}
out.flush();
}
public void run() throws Exception
{
String inStr, outStr;
while ((inStr=in.readLine())!=null)
{
if (inStr.equals(""))
scanner.finishUp();
else
scanner.scanBody(inStr);
printWords();
scanner.clearTokens();
}
scanner.finishUp();
printWords();
scanner.clearTokens();
}
}

View file

@ -0,0 +1,75 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
/** Stores the multiple definitions (corresponding to
various dictionaries) for a single Tibetan word.
@author Andr&eacute;s Montano Pellegrini
*/
package org.thdl.tib.scanner;
public class Definitions
{
public String[] def;
public int[] source;
public static String[] defTags;
static
{
defTags=null;
}
public static void setTags(String tags[])
{
defTags = tags;
}
public Definitions(String[] def, int[] source)
{
this.def = def;
this.source = source;
}
public Definitions(String def)
{
source = null;
this.def = new String[1];
this.def[0] = def;
}
public String getTag(int i)
{
if (source==null) return null;
if (defTags==null) return Integer.toString(source[i]+1);
return defTags[source[i]];
}
public String toString()
{
int i;
String s;
if (def==null) return null;
if (source==null) return def[0];
s = "(" + getTag(0) + ") " + def[0];
for (i=1; i<def.length; i++)
s += "\n" + "(" + getTag(i) + ") " + def[i];
return s;
}
}

View file

@ -0,0 +1,53 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import javax.swing.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
/** Used by the DictionaryTable to display the full definition
of Tibetan word displaed in a table when its row is clicked.
@author Andr&eacute;s Montano Pellegrini
@see DictionaryTable
*/
class DictionaryListSelectionListener implements ListSelectionListener
{
private TableModel table;
private TextArea fullDef;
public DictionaryListSelectionListener(TableModel table, TextArea fullDef)
{
this.table = table;
this.fullDef = fullDef;
}
public void valueChanged(ListSelectionEvent e)
{
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
fullDef.setText(table.getValueAt(selectedRow, 1).toString());
}
}
}

View file

@ -0,0 +1,137 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
/** Specifies a subset of dictionaries among a set of
dictionaries. Supports a maximum of 15 dictionaries.
@author Andr&eacute;s Montano Pellegrini
*/
public class DictionarySource
{
private int dicts;
/** Last bit of word. 1 if there are more brothers.*/
private static final int lastBit=32768;
private static final int allDicts=lastBit-1;
public DictionarySource()
{
dicts = 0;
}
public static DictionarySource getAllDictionaries()
{
DictionarySource ds = new DictionarySource();
ds.setDicts(allDicts);
return ds;
}
public void setAllDictionaries()
{
dicts = allDicts;
}
public void setDicts(int dicts)
{
this.dicts = dicts;
}
public int getDicts()
{
return dicts;
}
private int getBits(int n)
{
return 1 << n;
}
public boolean contains(int dict)
{
return (dicts & getBits(dict))>0;
}
public void add(int dict)
{
dicts|= getBits(dict);
}
/** Write to file using BinaryFileGenerator */
public void print(boolean hasNext, DataOutput raf) throws IOException
{
int numDict;
if (hasNext) numDict = lastBit | dicts;
else numDict = dicts;
raf.writeShort(numDict);
}
public static DictionarySource read(DataInput raf) throws IOException
{
DictionarySource ds = new DictionarySource();
ds.setDicts(raf.readShort());
return ds;
}
public boolean hasBrothers()
{
return (dicts & lastBit)>0;
}
public int countDefs()
{
int n, source;
for (n=0, source = dicts & allDicts; source>0; source>>=1)
if (source%2==1) n++;
return n;
}
public DictionarySource intersection(DictionarySource dsO)
{
DictionarySource ds = new DictionarySource();
ds.setDicts(this.dicts & dsO.dicts);
return ds;
}
public int[] untangleDefs(int n)
{
int arr[], i, pos, source;
arr = new int[n];
for (i=0, pos=0, source=dicts & allDicts; pos<n; i++, source>>=1)
if (source%2==1)
arr[pos++]=i;
return arr;
}
public int[] untangleDefs()
{
return untangleDefs(countDefs());
}
public boolean isEmpty()
{
return (dicts & allDicts)<=0;
}
public void reset()
{
dicts = 0;
}
}

View file

@ -0,0 +1,106 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.*;
/** Table of two columns that displays a Tibetan word or
phrase (in either Tibetan or Roman script) and the
first couple of lines of its definitions. Clicking on
a word displays full definition on a separate text box.
@author Andr&eacute;s Montano Pellegrini
*/
public class DictionaryTable extends JTable
{
private DuffScannerPanel padre;
private int tibetanHeight, normalHeight;
private TableCellRenderer duffRenderer, normalRenderer;
public DictionaryTable(DictionaryTableModel td, TextArea fullDef)
{
this.setModel(td);
this.setRowHeight(40);
this.setColumnSelectionAllowed(false);
this.setRowSelectionAllowed(true);
//tableHeader = null;
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = getSelectionModel();
rowSM.addListSelectionListener(new DictionaryListSelectionListener(td, fullDef));
TableColumnModel tcm = this.getColumnModel();
normalRenderer = new AlmostDefaultTableCellRenderer();
duffRenderer = new DuffCellRenderer();
TableColumn tc = tcm.getColumn(0);
tc.setPreferredWidth(10);
tc.setCellRenderer(normalRenderer);
tc.setHeaderValue("Word");
tc = tcm.getColumn(1);
tc.setCellRenderer(normalRenderer);
tc.setHeaderValue("Definition");
tibetanHeight = normalHeight = -1;
}
public void resizeRows()
{
int i, n = getRowCount(), visibleHeight, width;
JLabel jl;
AlmostDefaultTableCellRenderer ja;
FontMetrics fm;
if (n>0)
{
ja = (AlmostDefaultTableCellRenderer) normalRenderer;
if (tibetanHeight<0)
{
jl = (JLabel) duffRenderer;
fm = jl.getFontMetrics(jl.getFont());
tibetanHeight = fm.getHeight();
fm = ja.getFontMetrics(ja.getFont());
normalHeight = fm.getHeight();
}
width = getColumnModel().getColumn(1).getWidth();
for (i=0; i<n; i++)
{
visibleHeight = normalHeight * ja.getLineCount(getValueAt(i,1), width);
if (visibleHeight > tibetanHeight)
setRowHeight(i, visibleHeight);
}
}
}
public void activateTibetan(boolean activate)
{
TableColumnModel tcm = this.getColumnModel();
TableColumn tc = tcm.getColumn(0);
if (activate)
tc.setCellRenderer(duffRenderer);
else
tc.setCellRenderer(normalRenderer);
DictionaryTableModel dtm = (DictionaryTableModel) getModel();
dtm.activateTibetan(activate);
}
}

View file

@ -0,0 +1,125 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import javax.swing.*;
import javax.swing.table.*;
import org.thdl.tib.text.TibetanDocument;
import org.thdl.tib.text.TibetanDocument.DuffData;
/** Stores the words being displayed in a DictionaryTable.
@author Andr&eacute;s Montano Pellegrini
@see DictionaryTable
*/
public class DictionaryTableModel extends AbstractTableModel
{
private Word []array;
private DuffData arrayTibetan[][];
private boolean tibetanActivated;
public DictionaryTableModel(Word[] array)
{
this.newSearch(array);
tibetanActivated=false;
}
public int getRowCount()
{
if (array!=null)
return array.length;
else return 0;
}
public int getColumnCount()
{
return 2;
}
public void activateTibetan(boolean activate)
{
tibetanActivated = activate;
}
public Object getValueAt(int row, int column)
{
if (column==0)
{
if (tibetanActivated)
return arrayTibetan[row];
else
return array[row].getWylie();
}
else
return array[row].getDef();
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
public void newSearch(Token[] token)
{
int i, n=0;
if (token==null)
array = null;
else
{
for (i=0; i<token.length; i++)
{
if (token[i] instanceof Word)
n++;
}
if (n==0)
{
array=null;
}
else
{
array = new Word[n];
n=0;
for (i=0; i<token.length; i++)
{
if (token[i] instanceof Word)
{
array[n] = (Word) token[i];
n++;
}
}
}
}
if (array==null)
arrayTibetan = null;
else
{
arrayTibetan = new DuffData[this.array.length][];
try
{
for (i=0; i<array.length; i++)
arrayTibetan[i]=TibetanDocument.getTibetanMachineWeb(array[i].getWylie());
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}

View file

@ -0,0 +1,139 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import javax.swing.border.*;
import javax.swing.text.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.*;
import org.thdl.tib.text.TibetanDocument.DuffData;
import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase
(in either Roman or Tibetan script) in a single cell.
@author Andr&eacute;s Montano Pellegrini
@see DictionaryTable
*/
public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Serializable
{
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
// We need a place to store the color the DuffPane should be returned
// to after its foreground and background colors have been set
// to the selection background color.
// These ivars will be made protected when their names are finalized.
private Color unselectedForeground;
private Color unselectedBackground;
public DuffCellRenderer()
{
super();
setOpaque(true);
setBorder(noFocusBorder);
}
/**
* Overrides <code>JComponent.setForeground</code> to assign
* the unselected-foreground color to the specified color.
*
* @param c set the foreground color to this value
*/
public void setForeground(Color c) {
super.setForeground(c);
unselectedForeground = c;
}
/**
* Overrides <code>JComponent.setForeground</code> to assign
* the unselected-background color to the specified color.
*
* @param c set the background color to this value
*/
public void setBackground(Color c) {
super.setBackground(c);
unselectedBackground = c;
}
/**
* Notification from the <code>UIManager</code> that the look and feel
* [L&F] has changed.
* Replaces the current UI object with the latest version from the
* <code>UIManager</code>.
*
* @see JComponent#updateUI
*/
public void updateUI() {
super.updateUI();
setForeground(null);
setBackground(null);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected)
{
super.setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
}
else
{
super.setForeground((unselectedForeground != null) ? unselectedForeground : table.getForeground());
super.setBackground((unselectedBackground != null) ? unselectedBackground : table.getBackground());
}
if (hasFocus) {
setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
if (table.isCellEditable(row, column)) {
super.setForeground( UIManager.getColor("Table.focusCellForeground") );
super.setBackground( UIManager.getColor("Table.focusCellBackground") );
}
} else {
setBorder(noFocusBorder);
}
setValue(value);
// ---- begin optimization to avoid painting background ----
Color back = getBackground();
boolean colorMatch = (back != null) && ( back.equals(table.getBackground()) ) && table.isOpaque();
setOpaque(!colorMatch);
// ---- end optimization to aviod painting background ----
return this;
}
public void setValue(Object value)
{
TibetanDocument doc = (TibetanDocument) getDocument();
try
{
doc.remove(0, doc.getLength());
}
catch (Exception e)
{
System.out.println(e);
}
doc.insertDuff(0, (DuffData []) value);
}
}

View file

@ -0,0 +1,203 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
/** Graphical interfase to be used by applications and applets
to input a Tibetan text (in Roman or Tibetan script) and
displays the words (in Roman or Tibetan script) with their
definitions (in Roman script). Uses the THDL inputting system.
@author Andr&eacute;s Montano Pellegrini
*/
public class DuffScannerPanel extends ScannerPanel
{
private TextArea fullDef, txtInput;
private DuffPane duffInput;
private JPanel inputPanel;
private JScrollPane listDef;
// private Font tibetanFont;
private DictionaryTable table;
private DictionaryTableModel model;
boolean showingTibetan;
public DuffScannerPanel(String file)
{
super(file);
Panel panel1;
panel1 = new Panel(new GridLayout(3,1));
/* Looks up tibcodes in directory of applet. In order
to work through a proxy store all the applet classes toghether
with tibcodes.ini in a jar file. */
duffInput = new DuffPane();
duffInput.disableRoman();
JPanel jpanel = new JPanel(new GridLayout(1,1));
JScrollPane jsp = new JScrollPane(duffInput, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jpanel.add(jsp);
inputPanel = new JPanel(new CardLayout());
inputPanel.add(jpanel, "1");
txtInput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
inputPanel.add(txtInput, "2");
panel1.add(inputPanel);
fullDef = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
fullDef.setEditable(false);
model = new DictionaryTableModel(null);
table = new DictionaryTable(model, fullDef);
table.activateTibetan(true);
listDef = new JScrollPane(table);
panel1.add(listDef);
panel1.add(fullDef);
add(panel1, BorderLayout.CENTER);
showingTibetan = true;
// tibetanFont = new Font("TibetanMachine",Font.PLAIN,36);
}
public void addFocusListener(FocusListener fl)
{
txtInput.addFocusListener(fl);
duffInput.addFocusListener(fl);
fullDef.addFocusListener(fl);
}
/* public void printAllDefs()
{
Word word;
int i;
GridBagConstraints gb1 = new GridBagConstraints(), gb2 = new GridBagConstraints();
JTextArea jtext;
TextArea text;
GridBagLayout grid = new GridBagLayout();
if (panelOutput!=null)
defPane.remove(panelOutput);
panelOutput = new Panel(grid);
gb1.weightx = 1;
gb2.weightx = 4;
gb1.gridwidth = GridBagConstraints.RELATIVE;
gb2.gridwidth = GridBagConstraints.REMAINDER;
for (i=0; i<array.length; i++)
{
word = (Word) array[i];
jtext = new JTextArea(wd.getDuff(new TibetanString(word.getWylie())));
jtext.setFont(tibetanFont);
grid.setConstraints(jtext, gb1);
panelOutput.add(jtext);
text = new TextArea(word.getDef());
text.
grid.setConstraints(text, gb2);
panelOutput.add(text);
}
defPane.add(panelOutput);
}*/
public void clear()
{
txtInput.setText("");
duffInput.setText("");
fullDef.setText("");
model.newSearch(null);
table.tableChanged(new TableModelEvent(model));
table.repaint();
}
public void translate()
{
String in;
setDicts(scanner.getDictionarySource());
in = "";
if (showingTibetan)
in = ((TibetanDocument)duffInput.getDocument()).getWylie();
else
in = txtInput.getText();
if (!in.equals(""))
{
doingStatus("Translating...");
scanner.scanBody(in);
scanner.finishUp();
model.newSearch(scanner.getTokenArray());
// printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
fullDef.setText("");
/* ListSelectionModel lsm = (ListSelectionModel)table.getSelectionModel();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
if (selectedRow<model.getRowCount())
fullDef.setText(model.getValueAt(selectedRow, 1).toString());
}*/
}
else
{
model.newSearch(null);
fullDef.setText("");
}
table.tableChanged(new TableModelEvent(model));
table.repaint();
}
public void setEnableTibetanScript(boolean enabled)
{
CardLayout cl = (CardLayout) inputPanel.getLayout();
if (enabled && !showingTibetan)
{
String s = txtInput.getText();
/* int posEnter = s.indexOf('\n');
if (posEnter > 0)
s = s.substring(0,posEnter);*/
duffInput.newDocument();
if (!s.equals(""))
duffInput.toTibetanMachineWeb(s, 0);
table.activateTibetan(true);
cl.first(inputPanel);
showingTibetan = true;
}
if (!enabled && showingTibetan)
{
txtInput.setText(((TibetanDocument)duffInput.getDocument()).getWylie());
table.activateTibetan(false);
cl.last(inputPanel);
showingTibetan = false;
}
table.repaint();
}
}

View file

@ -0,0 +1,161 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
/** Searches the words directly in a file; not the prefered
implementation. The search is too slow!
The prefered implementation is the CachedSyllableList.
<p>The words must be stored in a binary file tree structure format.
This can be done using the BinaryFileGenerator.</p>
@author Andr&eacute;s Montano Pellegrini
@see TibetanScanner
@see CachedSyllableList
@see BinaryFileGenerator
*/
public class FileSyllableListTree implements SyllableListTree
{
private String sil;
private long def[];
private long posLista;
private DictionarySource defSource;
public static DictionarySource defSourcesWanted;
public static RandomAccessFile wordRaf=null;
private static RandomAccessFile defRaf=null;
/** Creates the root */
public FileSyllableListTree(String archivo, int defSourcesWanted) throws Exception
{
sil = null;
def = null;
this.defSource = new DictionarySource();
openFiles(archivo);
posLista = wordRaf.length() - 4;
wordRaf.seek(posLista);
posLista = (long)wordRaf.readInt();
}
/** Used to create each node (except the root)
*/
public FileSyllableListTree(String sil, long []def, DictionarySource defSource, long posLista)
{
this.sil=sil;
this.def=def;
this.defSource = defSource;
this.posLista=posLista;
}
public String toString()
{
return sil;
}
public DictionarySource getDictionarySource()
{
return defSource;
}
public static void openFiles(String archivo) throws Exception
{
wordRaf = new RandomAccessFile(archivo + ".wrd", "r");
defRaf = new RandomAccessFile(archivo + ".def", "r");
defSourcesWanted = DictionarySource.getAllDictionaries();
}
public String getDef()
{
return getDefs().toString();
}
public Definitions getDefs()
{
if (def==null) return null;
DictionarySource defSourceAvail = defSource.intersection(defSourcesWanted);
int defsAvail[] = defSourceAvail.untangleDefs(), defsFound[] = defSource.untangleDefs(def.length);
String defs[] = new String[defsAvail.length];
int i, n=0;
try
{
for (i=0; i<defsAvail.length; i++)
{
while(defsAvail[i]!=defsFound[n]) n++;
defRaf.seek(def[n]);
defs[i] = defRaf.readUTF();
}
}
catch (Exception e)
{
System.out.println(e);
return null;
}
return new Definitions(defs, defsAvail);
}
public boolean hasDef()
{
if (def==null) return false;
DictionarySource defSourceAvail = defSource.intersection(defSourcesWanted);
return !defSourceAvail.isEmpty();
}
public SyllableListTree lookUp(String silStr)
{
String sil;
long pos, defSource[];
DictionarySource sourceDef;
int i;
if (silStr==null) return null;
try
{
wordRaf.seek(posLista);
do
{
pos = (long) wordRaf.readInt();
sil = wordRaf.readUTF();
sourceDef = DictionarySource.read(wordRaf);
if (sourceDef.isEmpty()) defSource = null;
else
{
defSource = new long[sourceDef.countDefs()];
for (i=0; i<defSource.length; i++)
{
defSource[i] = (long) wordRaf.readInt();
}
}
if (sil.compareTo(silStr)>0)
return null;
if (sil.equals(silStr))
return new FileSyllableListTree(sil, defSource, sourceDef, pos);
}while(sourceDef.hasBrothers());
}
catch (Exception e)
{
}
return null;
}
}

View file

@ -0,0 +1,105 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.io.*;
class Link
{
private Object obj;
public Link siguiente;
public Link(Object obj)
{
this.obj = obj;
siguiente = null;
}
public String toString()
{
return obj.toString();
}
public Link createNext(Object obj)
{
return siguiente = new Link(obj);
}
public Link createPrevious(Object obj)
{
Link l = new Link(obj);
l.siguiente=this;
return l;
}
public Object get()
{
return obj;
}
public Link next()
{
return this.siguiente;
}
public int size()
{
int n=0;
Link actual = this;
while (actual != null)
{
n++;
actual = actual.next();
}
return n;
}
public Object clone()
{
return new Link(obj);
}
public void insertSorted(Link link)
{
if (siguiente==null)
siguiente = link;
else
if (link.toString().compareTo(siguiente.toString())<=0)
{
link.siguiente = siguiente;
siguiente = link;
}
else siguiente.insertSorted(link);
}
public Link sort()
{
Link newCabeza = (Link) clone(), next = next(), newLink;
while (next!=null)
{
newLink = (Link) next.clone();
if (newLink.toString().compareTo(newCabeza.toString())<=0)
{
newLink.siguiente = newCabeza;
newCabeza = newLink;
}
else newCabeza.insertSorted(newLink);
next = next.next();
}
return newCabeza;
}
}

View file

@ -0,0 +1,117 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
public class LinkedList
{
protected Link cabeza;
public LinkedList()
{
cabeza=null;
}
private LinkedList(Link cabeza)
{
this.cabeza = cabeza;
}
public void addLast(Object o)
{
if (cabeza==null)
{
cabeza = new Link(o);
}
else cabeza = cabeza.createPrevious(o);
}
public Object getLast()
{
if (cabeza==null) return null;
else return cabeza.get();
}
public ListIterator listIterator()
{
return new ListIterator(cabeza);
}
public ListIterator listIterator(int n)
{
return new ListIterator(cabeza, n);
}
public boolean isEmpty()
{
return cabeza==null;
}
public boolean contains(Object o)
{
Link current=cabeza;
while (current!=null)
{
if (current.get().equals(o)) return true;
current = current.next();
}
return false;
}
public int size()
{
if (cabeza==null) return 0;
return cabeza.size();
}
public LinkedList sort()
{
return new LinkedList(cabeza.sort());
}
public Object[] toArray()
{
int n = size();
if (n==0) return null;
Object array[] = new Object[n];
ListIterator li = listIterator();
while (li.hasNext())
{
n--;
array[n] = li.next();
}
return array;
}
public String[] toStringArray()
{
int n = size();
if (n==0) return null;
Object o;
String array[] = new String[n];
ListIterator li = listIterator();
while (li.hasNext())
{
n--;
o = li.next();
if (o==null) array[n]=null;
else array[n] = o.toString();
}
return array;
}
}

View file

@ -0,0 +1,49 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
public class ListIterator
{
Link current;
public ListIterator(Link current)
{
this.current=current;
}
public ListIterator(Link current, int n)
{
this(current);
int i;
for (i=0; i<n; i++) current=current.next();
}
public boolean hasNext()
{
return current!=null;
}
public Object next()
{
Object o = current.get();
current = current.next();
return o;
}
}

View file

@ -0,0 +1,398 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
import java.io.*;
class LocalTibetanScanner implements TibetanScanner
{
public static String archivo;
private SyllableListTree raiz, silActual, lastCompSil, silAnterior;
private String wordActual, lastCompWord;
private Vector floatingSil;
private LinkedList wordList;
private static String endOfParagraphMarks = "/;|!:[]^@#$%=<>(){}";
private static String endOfSyllableMarks = " _\t";
static
{
archivo = null;
}
public void clearTokens()
{
wordList = new LinkedList();
}
public DictionarySource getDictionarySource()
{
return raiz.getDictionarySource();
}
public LocalTibetanScanner(String arch) throws Exception
{
archivo = arch;
// raiz = new MemorySyllableListTree(archivo);
// raiz = new FileSyllableListTree(archivo);
raiz = new CachedSyllableListTree(archivo);
floatingSil = new Vector();
wordList = new LinkedList();
resetAll();
}
private void resetAll()
{
silAnterior = silActual = lastCompSil = null;
wordActual = lastCompWord = null;
}
private void scanSyllable(String sil)
{
SyllableListTree resultado=null;
Enumeration enum;
Word w;
String silSinDec;
if (silActual==null)
silActual = raiz;
silAnterior = silActual;
silActual = silActual.lookUp(sil);
if (silActual != null)
{
if (silActual.hasDef())
{
lastCompWord = concatWithSpace(wordActual, sil);
lastCompSil = silActual;
floatingSil.removeAllElements();
}
else
{
silSinDec = withOutDec(sil);
if (silSinDec!=null)
{
resultado = silAnterior.lookUp(silSinDec);
if (resultado == null)
{
silSinDec += "\'";
resultado = silAnterior.lookUp(silSinDec);
}
if (resultado!=null && resultado.hasDef())
{
lastCompWord = concatWithSpace(wordActual, silSinDec);
lastCompSil = resultado;
wordActual = concatWithSpace(wordActual, sil);
}
else resultado = null;
}
if (resultado!=null) return;
if (lastCompSil!=null)
floatingSil.addElement(sil);
}
wordActual = concatWithSpace(wordActual, sil);
}
else
{
silSinDec = withOutDec(sil);
if (silSinDec!=null)
{
resultado = silAnterior.lookUp(silSinDec);
if (resultado == null)
{
silSinDec += "\'";
resultado = silAnterior.lookUp(silSinDec);
}
// si funciona sin declension arreglado problema
if (resultado!=null && resultado.hasDef())
{
wordList.addLast(new Word(concatWithSpace(wordActual, silSinDec), concatWithSpace(wordActual,sil), resultado.getDefs()));
resetAll();
floatingSil.removeAllElements();
}
else resultado = null;
}
if (resultado!=null) return;
if (lastCompSil!=null)
{
w = new Word(lastCompWord, lastCompSil.getDefs());
wordList.addLast(w);
this.resetAll();
enum = floatingSil.elements();
floatingSil = new Vector();
while (enum.hasMoreElements())
scanSyllable((String)enum.nextElement());
scanSyllable(sil);
}
else
{
if (silAnterior!=raiz)
{
w = new Word(wordActual, "[incomplete word]");
wordList.addLast(w);
this.resetAll();
scanSyllable(sil);
}
else
{
w = new Word(sil, "[not found]");
wordList.addLast(w);
this.resetAll();
}
}
}
}
public void finishUp()
{
Enumeration enum;
Word w;
while (lastCompSil!=null)
{
w = new Word(lastCompWord, lastCompSil.getDefs());
wordList.addLast(w);
this.resetAll();
enum = floatingSil.elements();
floatingSil = new Vector();
while (enum.hasMoreElements())
scanSyllable((String)enum.nextElement());
}
if (silActual!=null)
{
wordList.addLast(new Word(wordActual, "[incomplete word]"));
this.resetAll();
}
}
private static String concatWithSpace(String s1, String s2)
{
if (s1==null || s1.equals(""))
return s2;
else
return s1 + ' ' + s2;
}
private static String withOutDec(String sil)
{
boolean isDeclined =false;
int len = sil.length();
String dev;
if (len<3) return null;
char lastCar = sil.charAt(len-1);
if ((lastCar == 's' || lastCar == 'r') && isVowel(sil.charAt(len-2)))
{
isDeclined=true;
sil = sil.substring(0, len-1);
}
else if ((lastCar == 'i' || lastCar == 'o') && sil.charAt(len-2)=='\'')
{
isDeclined=true;
sil = sil.substring(0, len-2);
}
if (!isDeclined) return null;
return sil;
}
public void scanBody(String in)
{
Word word;
boolean hayMasLineas=true;
if (in.equals("")) finishUp();
else
{
int init = 0, fin;
String linea;
while (hayMasLineas)
{
fin = in.indexOf("\n",init);
if (fin<0)
{
linea = in.substring(init).trim();
hayMasLineas=false;
}
else
linea = in.substring(init, fin).trim();
if (linea.equals(""))
{
finishUp();
wordList.addLast(new PunctuationMark('\n'));
}
else
scanLine(linea);
init = fin+1;
}
}
}
private boolean isEndOfSyllable(int ch)
{
return (endOfSyllableMarks.indexOf(ch)>-1);
}
public void scanLine(String linea)
{
int init = 0, fin, i;
char ch;
String sil;
boolean doNotFinishUp;
if (linea.equals(""))
{
finishUp();
wordList.addLast(new PunctuationMark('\n'));
return;
}
outAHere:
while(true)
{
doNotFinishUp=true;
// Make init skip all punctuation marks
while (true)
{
if (init>=linea.length())
break outAHere;
ch = linea.charAt(init);
if (endOfParagraphMarks.indexOf(ch)>=0)
{
if (doNotFinishUp)
{
finishUp();
doNotFinishUp=false;
}
wordList.addLast(new PunctuationMark(ch));
}
else if (endOfSyllableMarks.indexOf(ch)<0)
break;
init++;
}
doNotFinishUp = true;
/* move fin to the end of the next syllable. If finishing
up is necessary it is done after scanSyllable
*/
fin = init+1;
while (true)
{
ch = linea.charAt(fin);
if (endOfParagraphMarks.indexOf(ch)>=0)
{
doNotFinishUp = false;
break;
}
else if (endOfSyllableMarks.indexOf(ch)>=0)
{
break;
}
else
{
fin++;
if (fin>=linea.length())
break;
}
}
sil = linea.substring(init, fin);
scanSyllable(sil);
if (!doNotFinishUp)
{
finishUp();
wordList.addLast(new PunctuationMark(ch));
}
init = fin+1;
}
}
public LinkedList getTokenLinkedList()
{
return wordList;
}
public Token[] getTokenArray()
{
int i=wordList.size();
Token token[] = new Token[i];
Object obj;
ListIterator li = wordList.listIterator();
while(li.hasNext())
token[--i] = (Token)li.next();
return token;
}
private static boolean isVowel(char ch)
{
return (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');
}
/** Looks for .dic file, and returns the dictionary descriptions.
Also updates the definitionTags in the Definitions class.
*/
public String[] getDictionaryDescriptions()
{
int n;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo + ".dic")));
LinkedList ll1 = new LinkedList(), ll2 = new LinkedList();
int i;
String s;
while ((s=br.readLine())!=null)
{
n = s.indexOf(",");
if (n < 0)
{
ll1.addLast(null);
ll2.addLast(s);
}
else
{
ll1.addLast(s.substring(0,n).trim());
ll2.addLast(s.substring(n+1).trim());
}
}
Definitions.defTags = ll2.toStringArray();
return ll1.toStringArray();
}
catch (Exception e)
{
return null;
}
}
}

View file

@ -0,0 +1,192 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
import java.io.*;
public class MemorySyllableListTree extends LinkedList implements SyllableListTree
{
protected String sil, def;
public String toString()
{
return sil;
}
/** Null because it does not support multiple dictionaries.
*/
public DictionarySource getDictionarySource()
{
return null;
}
public MemorySyllableListTree(String sil, String def)
{
super();
int marker = sil.indexOf(" ");
if (marker<0)
{
this.sil = sil;
this.def = def;
}
else
{
this.sil = sil.substring(0, marker);
this.def = null;
addLast(new MemorySyllableListTree(sil.substring(marker+1).trim(), def));
}
}
public MemorySyllableListTree(String archivo) throws Exception
{
super();
sil = null;
def = null;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo)));
String entrada;
while ((entrada = br.readLine())!=null)
{
entrada = entrada.trim();
if (!entrada.equals(""))
add(entrada);
}
}
private void add(String entrada)
{
int marker = entrada.indexOf("-");
if (marker<0)
throw new RuntimeException("Error de sintaxis; diccionario no pudo ser cargado!");
add(entrada.substring(0,marker).trim(), entrada.substring(marker+1).trim());
}
private void add(String word, String def)
{
MemorySyllableListTree prefijo;
String firstSillable;
int pos, marker = word.indexOf(" ");
if (marker<0)
firstSillable = word;
else firstSillable = word.substring(0,marker);
/*
Para orden "normal" con sanscrito transliterado traslapado
entre el tibetano
if (isEmpty() || (prefijo = lookUp(firstSillable))==null) */
// Para orden modificado de silabas
if (isEmpty() || !(prefijo = (MemorySyllableListTree)getLast()).equals(firstSillable))
super.addLast(new MemorySyllableListTree(word, def));
else
if (marker<0) // ya estaba en el diccionario!
prefijo.addMoreDef(def);
else
prefijo.add(word.substring(marker+1).trim(), def);
}
private void addMoreDef(String def)
{
if (this.def==null || this.def.equals(""))
this.def=def;
else this.def = this.def + ". " + def;
}
public boolean equals (Object o)
{
if (o instanceof String)
{
return sil.equals((String)o);
}
else return false;
}
public String getDef()
{
return def;
}
public Definitions getDefs()
{
return new Definitions(def);
}
public boolean hasDef()
{
return def!=null;
}
private void println(PrintStream ps)
{
println(ps, "");
}
private void println(PrintStream ps, String prefijo)
{
if (sil!=null)
{
if (prefijo.equals(""))
prefijo = sil;
else
prefijo = prefijo + " " + sil;
if (def!=null)
ps.println(prefijo + " - " + def);
}
MemorySyllableListTree silHijos;
ListIterator i = listIterator();
while (i.hasNext())
{
silHijos = (MemorySyllableListTree) i.next();
silHijos.println(ps, prefijo);
}
}
public SyllableListTree lookUp(String silStr)
{
MemorySyllableListTree sil;
ListIterator i = listIterator();
while (i.hasNext())
{
sil = (MemorySyllableListTree) i.next();
if (sil.equals(silStr))
return sil;
}
return null;
}
public static void main(String args[]) throws Exception
{
if (args.length!=1)
{
System.out.println("Programa de prueba para verificar almacenamiento de diccionario.");
System.out.println("Sintaxis: java MemorySyllableListTree arch-dict");
return;
}
MemorySyllableListTree sl = new MemorySyllableListTree(args[0]);
sl.println(System.out);
}
}

View file

@ -0,0 +1,300 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.thdl.tib.text.TibetanHTML;
public class OnLineScannerFilter extends HttpServlet {
ResourceBundle rb;
private TibetanScanner scanner;
public OnLineScannerFilter() throws Exception
{
rb = ResourceBundle.getBundle("dictionary");
scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name"));
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String parrafo = request.getParameter("parrafo"), checkboxName, script;
DictionarySource ds=null;
boolean checkedDicts[], allUnchecked, wantsTibetan;
int percent=100;
out.println("<html>");
out.println("<head>");
out.println("<META name=\"keywords\" content=\"tibetan, english, dictionary, jim valby, rangjung yeshe, jeffrey hopkins, tsig mdzod chen mo, online, translation, scanner, parser, buddhism, language, processing, font, dharma, chos, tibet\">");
out.println("<META NAME=\"Description\" CONTENT=\"This Java tool takes Tibetan language passages and divides the passages up into their component phrases and words, and displays corresponding dictionary definitions.\">");
out.println("<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">");
out.println("<title>The Online Tibetan to English Translation/Dictionary Tool</title>");
script = request.getParameter("script");
wantsTibetan = (script==null || script.equals("tibetan"));
if (wantsTibetan)
{
out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
out.println("<style>.tmw {font: 28pt TibetanMachineWeb}");
out.println(".tmw1 {font: 28pt TibetanMachineWeb1}");
out.println(".tmw2 {font: 28pt TibetanMachineWeb2}");
out.println(".tmw3 {font: 28pt TibetanMachineWeb3}");
out.println(".tmw4 {font: 28pt TibetanMachineWeb4}");
out.println(".tmw5 {font: 28pt TibetanMachineWeb5}");
out.println(".tmw6 {font: 28pt TibetanMachineWeb6}");
out.println(".tmw7 {font: 28pt TibetanMachineWeb7}");
out.println(".tmw8 {font: 28pt TibetanMachineWeb8}");
out.println(".tmw9 {font: 28pt TibetanMachineWeb9}");
out.println("</style>");
}
out.println("</head>");
out.println("<body>");
out.println("<h3 align=\"center\">The Online Tibetan to English Translation/Dictionary Tool</h3>");
out.println("<form action=\"org.thdl.tib.scanner.OnLineScannerFilter\" method=POST>");
out.println("<table border=\"0\" width=\"100%\">");
out.println(" <tr>");
out.println(" <td width=\"20%\">");
out.println(" <p>Display results in:</td>");
out.println(" <td width=\"55%\">");
out.println(" <p><input type=\"radio\" value=\"tibetan\" ");
if (wantsTibetan) out.println("checked ");
out.println("name=\"script\">Tibetan script (using <a href=\"http://iris.lib.virginia.edu/tibet/tools/tmw.html\" target=\"_blank\">Tibetan Machine Web font</a>)<br>");
out.println(" <input type=\"radio\" value=\"roman\" ");
if (!wantsTibetan) out.println("checked ");
out.println("name=\"script\">Roman script</td>");
out.println(" <td width=\"25%\">");
out.println(" <p> <input type=submit value=\"Translate\"> <input type=\"reset\" value=\"Clear\"></p>");
out.println(" </td>");
out.println(" </tr>");
out.println("</table>");
String dictionaries[] = scanner.getDictionaryDescriptions();
if (dictionaries!=null)
{
int i;
ds = scanner.getDictionarySource();
ds.reset();
checkedDicts = new boolean[dictionaries.length];
/* out.println(" <tr>");
out.println("<td width=\""+ percent +"%\">Search in dictionaries:</td>");*/
out.println("<p>Search in dictionaries: ");
allUnchecked=true;
for (i=0; i<dictionaries.length; i++)
{
checkboxName = "dict"+ i;
checkedDicts[i] = (request.getParameter(checkboxName)!=null);
}
allUnchecked=true;
for (i=0; i<dictionaries.length; i++)
{
if(checkedDicts[i])
{
allUnchecked=false;
break;
}
}
if (allUnchecked)
{
for (i=0; i<dictionaries.length; i++)
checkedDicts[i] = true;
}
for (i=0; i<dictionaries.length; i++)
{
checkboxName = "dict"+ i;
// out.print(" <td width=\"" + percent + "%\">");
out.print("<input type=\"checkbox\" name=\"" + checkboxName +"\" value=\""+ checkboxName +"\"");
if (checkedDicts[i])
{
out.print(" checked");
ds.add(i);
}
if (dictionaries[i]!=null)
out.print(">" + dictionaries[i] + " (" + Definitions.defTags[i] + ")&nbsp;&nbsp;&nbsp;");
else
out.print(">" + Definitions.defTags[i] + "&nbsp;&nbsp;&nbsp;");
// out.println(" + "</td>");
}
// out.println(" </tr>");
}
else ds = DictionarySource.getAllDictionaries();
// out.println("</table>");
out.println("</p>");
out.println("<p><strong>Input text:</strong></p>");
out.println("<textarea rows=\"12\" name=\"parrafo\" cols=\"60\">");
if (parrafo!=null) out.print(parrafo);
out.println("</textarea>");
out.println("</form>");
if (parrafo != null)
if (ds!=null && !ds.isEmpty())
desglosar(parrafo, out, wantsTibetan);
out.println(TibetanScanner.copyrightHTML);
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
synchronized public void desglosar(String in, PrintWriter pw, boolean tibetan)
{
boolean hayMasLineas=true;
//int init = 0, fin;
//String linea;
Object words[];
if (!in.equals(""))
{
/* while (hayMasLineas)
{
fin = in.indexOf("\n",init);
if (fin<0)
{
linea = in.substring(init).trim();
hayMasLineas=false;
}
else
linea = in.substring(init, fin).trim();
scanner.scanBody(linea);
init = fin+1;
} */
scanner.scanBody(in);
scanner.finishUp();
words = scanner.getTokenArray();
printText(pw, words, tibetan);
printAllDefs(pw, words, tibetan);
scanner.clearTokens();
}
}
public void printText(PrintWriter pw, Object words[], boolean tibetan)
{
Token token;
Word word;
char pm;
int i;
pw.print("<p>");
for (i=0; i < words.length; i++)
{
token = (Token) words[i];
if (token instanceof Word)
{
word = (Word) token;
pw.print(word.getLink());
}
else
{
if (token instanceof PunctuationMark)
{
pm = token.toString().charAt(0);
switch (pm)
{
case '\n':
pw.println("</p>");
pw.print("<p>");
break;
case '<':
pw.print("&lt; ");
break;
case '>':
pw.print("&gt; ");
break;
default:
pw.print(pm + " ");
}
}
}
}
pw.println("</p>");
}
public void printAllDefs(PrintWriter pw, Object words[], boolean tibetan)
{
LinkedList temp = new LinkedList();
int i;
Word word;
Definitions defs;
for (i=words.length-1; i >= 0; i--)
{
if (words[i] instanceof Word)
{
if (!temp.contains(words[i]))
{
temp.addLast(words[i]);
}
}
}
ListIterator li = temp.listIterator();
String tag;
pw.println("<table border=\"1\" width=\"100%\">");
while (li.hasNext())
{
word = (Word)li.next();
defs = word.getDefs();
pw.println(" <tr>");
tag = defs.getTag(0);
if (tag!=null)
{
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ word.getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"5%\">"+ tag +"</td>");
pw.println(" <td width=\"75%\">" + defs.def[0] + "</td>");
}
else
{
pw.println(" <td width=\"20%\" rowspan=\""+ defs.def.length +"\" valign=\"top\">"+ word.getBookmark(tibetan) +"</td>");
pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[0] + "</td>");
}
pw.println(" </tr>");
for (i=1; i<defs.def.length; i++)
{
pw.println(" <tr>");
tag = defs.getTag(i);
if (tag!=null)
{
pw.println(" <td width=\"5%\">"+ tag +"</td>");
pw.println(" <td width=\"75%\">" + defs.def[i] + "</td>");
}
else pw.println(" <td width=\"80%\" colspan=\"2\">" + defs.def[i] + "</td>");
pw.println(" </tr>");
}
}
pw.println("</table>");
}
}

View file

@ -0,0 +1,32 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
class PunctuationMark extends Token
{
public PunctuationMark(char ch)
{
super(String.valueOf(ch));
}
public String toString()
{
return super.token;
}
}

View file

@ -0,0 +1,96 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RemoteScannerFilter extends GenericServlet
{
private TibetanScanner scanner;
private DictionarySource ds;
public RemoteScannerFilter() throws Exception
{
ResourceBundle rb = ResourceBundle.getBundle("dictionary");
scanner = new LocalTibetanScanner(rb.getString("onlinescannerfilter.dict-file-name"));
ds = scanner.getDictionarySource();
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
{
BufferedReader br;
res.setContentType ("text/plain");
LinkedList words;
Word word;
PrintWriter out = res.getWriter();
int i;
String linea, dicts = req.getParameter("dicts"), dicDescrip[];
if (dicts!=null)
{
if (dicts.equals("names"))
{
dicDescrip = scanner.getDictionaryDescriptions();
if (dicDescrip==null)
{
out.close();
return;
}
for (i=0; i<dicDescrip.length; i++)
{
out.println(dicDescrip[i] + "," + Definitions.defTags[i]);
}
out.close();
return;
}
else
{
ds.setDicts(Integer.parseInt(dicts));
}
}
br = new BufferedReader(new InputStreamReader(req.getInputStream()));
while((linea = br.readLine())!= null)
scanner.scanLine(linea);
br.close();
scanner.finishUp();
words = scanner.getTokenLinkedList();
Token token;
ListIterator li = words.listIterator();
while (li.hasNext())
{
token = (Token)li.next();
if (!(token instanceof Word)) continue;
word = (Word) token;
out.println(word.getWylie());
out.println(word.getDef());
out.println();
}
scanner.clearTokens();
out.close();
}
}

View file

@ -0,0 +1,153 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.net.*;
import java.io.*;
public class RemoteTibetanScanner implements TibetanScanner
{
private String url;
private LinkedList wordList;
private DictionarySource defSourcesWanted;
public RemoteTibetanScanner(String url) throws Exception
{
defSourcesWanted = DictionarySource.getAllDictionaries();
this.url = url;
wordList = new LinkedList();
}
/** dont use */
public void scanLine(String linea)
{
scanBody(linea);
}
public void scanBody(String linea)
{
try
{
URLConnection uC = new URL(url + "?dicts=" + Integer.toString(defSourcesWanted.getDicts())).openConnection();
// URLConnection uC = new URL(url).openConnection();
uC.setDoInput(true);
uC.setDoOutput(true);
uC.setUseCaches(false);
uC.setRequestProperty("Content-type", "application/octet-stream");
OutputStream os = uC.getOutputStream();
PrintWriter pw = new PrintWriter(os);
pw.println(linea);
pw.close();
BufferedReader in = new BufferedReader(new InputStreamReader(uC.getInputStream()));
String word, eachDef, def;
outside:
while((word = in.readLine())!=null && (def = in.readLine())!=null)
{
do
{
eachDef = in.readLine();
if (eachDef==null)
{
wordList.addLast(new Word(word, def));
break outside;
}
if (eachDef.equals("")) break;
def+='\n' + eachDef;
}
while(true);
wordList.addLast(new Word(word, def));
}
in.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
public LinkedList getTokenLinkedList()
{
return wordList;
}
public void clearTokens()
{
wordList = new LinkedList();
}
public Token[] getTokenArray()
{
int i=0;
Token token[] = new Token[wordList.size()];
ListIterator li = wordList.listIterator();
while(li.hasNext())
token[i++] = (Token)li.next();
return token;
}
/** does not do anything */
public void finishUp()
{
}
public DictionarySource getDictionarySource()
{
return defSourcesWanted;
}
public String[] getDictionaryDescriptions()
{
int n;
try
{
URLConnection uC = new URL(url+"?dicts=names").openConnection();
uC.setDoInput(true);
uC.setDoOutput(false);
uC.setUseCaches(false);
uC.setRequestProperty("Content-type", "text/plain");
BufferedReader br = new BufferedReader(new InputStreamReader(uC.getInputStream()));
LinkedList ll1 = new LinkedList(), ll2 = new LinkedList();
int i;
String s;
while ((s=br.readLine())!=null)
{
n = s.indexOf(",");
if (n < 0)
{
ll1.addLast(null);
ll2.addLast(s);
}
else
{
ll1.addLast(s.substring(0,n).trim());
ll2.addLast(s.substring(n+1).trim());
}
}
br.close();
Definitions.defTags = ll2.toStringArray();
return ll1.toStringArray();
}
catch (Exception e)
{
return null;
}
}
}

View file

@ -0,0 +1,179 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/** Graphical interfase to be used by applications and
applets to input a Tibetan text and displays the words with
their definitions.
@author Andr&eacute;s Montano Pellegrini
@see AppletScannerFilter
@see WindowScannerFilter
*/
public abstract class ScannerPanel extends Panel implements ActionListener
{
private Label status;
protected Checkbox chkDicts[];
Button cmdTranslate;
protected TibetanScanner scanner;
/** Individual components that are to be shown or
hidden through the menu.
*/
public ScannerPanel(String file, boolean ipaq)
{
this(file, ipaq, 4);
}
public ScannerPanel(String file)
{
this(file, false, 4);
}
public ScannerPanel(String file, int cols)
{
this(file, false, 4);
}
public ScannerPanel(String file, boolean ipaq, int cols)
{
boolean exito=true;
int rows, n;
setLayout(new BorderLayout());
status = new Label();
Panel panel1;
panel1 = new Panel(new BorderLayout());
panel1.add(status, BorderLayout.CENTER);
cmdTranslate = new Button("Translate");
cmdTranslate.addActionListener(this);
panel1.add(cmdTranslate, BorderLayout.EAST);
chkDicts=null;
// Label copyright = new Label(TibetanScanner.copyrightUnicode);
doingStatus("Loading dictionary...");
try
{
if (file==null || file.equals(""))
scanner = null;
else if (file.toLowerCase().startsWith("http://"))
scanner = new RemoteTibetanScanner(file);
else
scanner = new LocalTibetanScanner(file);
String dictionaries[] = scanner.getDictionaryDescriptions();
if (dictionaries!=null)
{
n = dictionaries.length;
chkDicts = new Checkbox[n];
if (n>cols)
{
rows = n/cols;
if (n%cols>0) rows++;
}
else
{
cols = n;
rows = 1;
}
Panel panel2 = new Panel(new GridLayout(rows,cols));
// panel2 = new Panel();
int i;
for (i=0; i<dictionaries.length; i++)
{
if (dictionaries[i]!=null)
chkDicts[i] = new Checkbox(dictionaries[i] + " (" + Definitions.defTags[i] + ")", true);
else
chkDicts[i] = new Checkbox(Definitions.defTags[i], true);
panel2.add(chkDicts[i]);
}
panel1.add(panel2, BorderLayout.SOUTH);
}
}
catch (Exception e)
{
status.setText("Dictionary could no be loaded!");
exito=false;
}
if (ipaq)
{
/* panel2 = new Panel(new BorderLayout());
panel2.add(panel1, BorderLayout.CENTER);
panel2.add(copyright, BorderLayout.SOUTH);
add(panel2, BorderLayout.SOUTH);*/
add(panel1, BorderLayout.SOUTH);
}
else
{
add(panel1, BorderLayout.NORTH);
// add(copyright, BorderLayout.SOUTH);
}
if (exito)
returnStatusToNorm();
}
protected void doingStatus(String s)
{
status.setText(s);
}
protected void returnStatusToNorm()
{
status.setText("Input text:");
}
public void closingRemarks()
{
status.setText("Finishing...");
}
protected void setDicts(DictionarySource ds)
{
if (chkDicts==null)
{
if (ds!=null) ds.setAllDictionaries();
}
else
{
int i;
ds.reset();
for (i=0; i<chkDicts.length; i++)
{
if (chkDicts[i].getState()) ds.add(i);
}
}
}
public void actionPerformed(ActionEvent e)
{
translate();
}
public abstract void translate();
public abstract void clear();
public void setEnableTibetanScript(boolean enabled) {}
public void addFocusListener(FocusListener fl) {}
}

View file

@ -0,0 +1,89 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.awt.event.*;
public class SimpleScannerPanel extends ScannerPanel
{
private TextArea txtInput, txtOutput;
public SimpleScannerPanel(String file)
{
super(file, true);
Panel panel1;
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
panel1 = new Panel(gridbag);
c.weightx=1;
c.weighty=1;
c.gridheight=1;
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
txtInput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput.setEditable(false);
gridbag.setConstraints(txtInput, c);
panel1.add(txtInput);
c.gridheight = GridBagConstraints.REMAINDER;
c.ipady = 70;
gridbag.setConstraints(txtOutput, c);
panel1.add(txtOutput);
add(panel1, BorderLayout.CENTER);
}
public void addFocusListener(FocusListener fl)
{
txtInput.addFocusListener(fl);
txtOutput.addFocusListener(fl);
}
public void printAllDefs()
{
int i;
Object array[] = scanner.getTokenArray();
for(i=0; i<array.length; i++)
if (array[i] instanceof Word)
txtOutput.append("* " + array[i].toString() + "\n\n");
}
public void clear()
{
txtInput.setText("");
txtOutput.setText("");
}
public void translate()
{
String in;
setDicts(scanner.getDictionarySource());
in = txtInput.getText();
doingStatus("Translating...");
if (!in.equals(""))
{
txtOutput.setText("");
scanner.scanBody(in);
scanner.finishUp();
printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
}
}
}

View file

@ -0,0 +1,37 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
/**
Defines interfase that the Tibetan scanners will
use to look up the Tibetan words organized in
a tree structure.
@author Andr&eacute;s Montano Pellegrini
@see TibetanScanner
*/
package org.thdl.tib.scanner;
public interface SyllableListTree
{
public String getDef();
public Definitions getDefs();
public boolean hasDef();
public SyllableListTree lookUp(String silStr);
public DictionarySource getDictionarySource();
}

View file

@ -0,0 +1,43 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.util.*;
public interface TibetanScanner
{
public static final String copyrightUnicode="Copyright " + '\u00A9' + " 2000-2002 by Andr" + '\u00E9' + "s Montano Pellegrini, all rights reserved.";
public static final String copyrightASCII="Copyright 2000-2002 by Andres Montano Pellegrini, all rights reserved.";
public static final String copyrightHTML="<hr><h5>Copyright &copy; 2000-2002 by <a href=\"http://www.people.virginia.edu/~am2zb/\" target=\"_blank\">Andr&eacute;s Montano Pellegrini</a><br>All rights reserved</h5>";
public static final String aboutUnicode=
"The Tibetan to English Translation Tool, version 1.1.0\n" +
"Copyright " + '\u00A9' + " 2000-2002 by Andr" + '\u00E9' + "s Montano Pellegrini, all rights reserved.\n" +
"This software is protected by the terms of the AMP Open Community License,\n" +
"Version 1.0 (available at www.tibet.iteso.mx/Guatemala/). The Tibetan script\n" +
"input facility was built by THDL's Edward Garrett (http://www.thdl.org/).\n" +
"It uses Tibetan Computer Company (http://www.tibet.dk/tcc/)fonts created by\n" +
"Tony Duff and made available by the Trace Foundation (http://trace.org/).";
public void scanLine(String linea);
public void scanBody(String linea);
public void finishUp();
public LinkedList getTokenLinkedList();
public Token[] getTokenArray();
public void clearTokens();
public DictionarySource getDictionarySource();
public String[] getDictionaryDescriptions();
}

View file

@ -0,0 +1,28 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
public class Token
{
protected String token;
public Token (String token)
{
this.token = token;
}
}

View file

@ -0,0 +1,354 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.tib.scanner;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.datatransfer.*;
import javax.swing.text.JTextComponent;
import org.thdl.tib.input.DuffPane;
import org.thdl.tib.text.TibetanDocument;
public class WindowScannerFilter implements WindowListener, FocusListener, ActionListener, ItemListener
{
private ScannerPanel sp;
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear;
private CheckboxMenuItem tibScript;
private Object objModified;
private Frame frame;
private Dialog diagAbout;
public WindowScannerFilter(String file)
{
this (file, false);
}
public WindowScannerFilter(String file, boolean ipaq)
{
frame = new Frame("Tibetan Scanner");
frame.setLayout(new GridLayout(1,1));
frame.setBackground(Color.white);
diagAbout = null;
if (ipaq)
sp = new SimpleScannerPanel(file);
else
sp = new DuffScannerPanel(file);
MenuBar mb = new MenuBar();
Menu m = new Menu ("File");
mnuExit = new MenuItem("Exit");
mnuExit.addActionListener(this);
m.add(mnuExit);
mb.add(m);
m = new Menu ("Edit");
mnuCut = new MenuItem("Cut");
m.add(mnuCut);
mnuCut.addActionListener(this);
mnuCopy = new MenuItem("Copy");
m.add(mnuCopy);
mnuCopy.addActionListener(this);
mnuPaste = new MenuItem("Paste");
m.add(mnuPaste);
mnuPaste.addActionListener(this);
mnuDelete = new MenuItem("Delete");
m.add(mnuDelete);
mnuDelete.addActionListener(this);
m.add("-");
mnuSelectAll = new MenuItem("Select all");
m.add(mnuSelectAll);
mnuSelectAll.addActionListener(this);
mnuClear = new MenuItem("Clear all");
m.add(mnuClear);
mnuClear.addActionListener(this);
mb.add(m);
if (!ipaq)
{
m = new Menu("View");
tibScript = new CheckboxMenuItem("Tibetan Script", true);
m.add(tibScript);
tibScript.addItemListener(this);
mb.add(m);
}
else tibScript=null;
m = new Menu("Help");
mnuAbout = new MenuItem("About...");
m.add(mnuAbout);
mnuAbout.addActionListener(this);
mb.add(m);
// disable menus
focusLost(null);
sp.addFocusListener(this);
frame.setMenuBar(mb);
frame.add(sp);
frame.addWindowListener(this);
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
// frame.setSize(240,320);
//else frame.setSize(500,600);
frame.show();
}
public static void main(String[] args)
{
if (args.length!=1 && args.length!=2)
{
System.out.println("Sintaxis: java SimpleScannerPanel [options] arch-dict");
System.out.println("Options:");
System.out.println(" -simple: runs the non-swing version.");
System.out.println(TibetanScanner.copyrightASCII);
return;
}
new WindowScannerFilter(args[args.length-1], args.length == 2);
}
/**
* Cierra la ventana. Invocado unicamente cuando el programa corre
* como aplicacion, para que el programa pare su ejecucion cuando
* el usuario cierre la ventana principal.
*/
public void windowClosing(WindowEvent e)
{
sp.closingRemarks();
System.exit(0);
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowActivated(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowClosed(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowDeactivated(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowDeiconified(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowIconified(WindowEvent e)
{
}
/**
* Sin cuerpo, no hace nada. Esta incluido solo para satisfacer
* la interfase <code>WindowListener</code>, la cual es implementada
* para tener el metodo <code>windowClosing</code>.
*
* @see #windowClosing
*/
public void windowOpened(WindowEvent e)
{
}
/** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at.
*/
public void focusGained(FocusEvent e)
{
objModified = e.getSource();
boolean isEditable=false;
if (objModified instanceof TextComponent)
{
TextComponent t = (TextComponent) objModified;
isEditable = t.isEditable();
}
else if (objModified instanceof JTextComponent)
{
JTextComponent j = (JTextComponent) objModified;
isEditable = j.isEditable();
}
mnuCut.setEnabled(isEditable);
if (isEditable)
{
if (Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)!=null)
mnuPaste.setEnabled(true);
}
else mnuPaste.setEnabled(false);
mnuDelete.setEnabled(isEditable);
mnuCopy.setEnabled(true);
mnuSelectAll.setEnabled(true);
}
/** Added to update the Edit menu in dependence upon
which textbox the keyboard focus is at.
*/
public void focusLost(FocusEvent e)
{
objModified=null;
mnuCut.setEnabled(false);
mnuCopy.setEnabled(false);
mnuPaste.setEnabled(false);
mnuDelete.setEnabled(false);
mnuSelectAll.setEnabled(false);
}
public void actionPerformed(ActionEvent e)
{
Object clicked = e.getSource();
StringSelection ss;
String s = null;
int start, end;
if (clicked == mnuAbout)
{
if (diagAbout==null)
{
diagAbout = new AboutDialog(frame);
}
diagAbout.show();
}
else if (clicked == mnuClear)
{
sp.clear();
}
else
{
if (objModified==null) return;
if (objModified instanceof TextArea)
{
TextArea t = (TextArea) objModified;
if (clicked == mnuExit)
{
System.exit(0);
}
else if (clicked == mnuCut)
{
ss = new StringSelection(t.getSelectedText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd());
}
else if (clicked == mnuCopy)
{
ss = new StringSelection(t.getSelectedText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
}
else if (clicked == mnuPaste)
{
Transferable data = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
try
{
s = (String)(data.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception ex)
{
s = data.toString();
}
t.replaceRange(s, t.getSelectionStart(), t.getSelectionEnd());
//t.insert(s, t.getCaretPosition());
}
else if (clicked == mnuDelete)
{
t.replaceRange("", t.getSelectionStart(), t.getSelectionEnd());
}
else if (clicked == mnuSelectAll)
{
t.selectAll();
}
}
else if (objModified instanceof DuffPane)
{
DuffPane t = (DuffPane) objModified;
if (clicked == mnuCut)
{
t.copy(t.getSelectionStart(), t.getSelectionEnd(), true);
}
else if (clicked == mnuCopy)
{
t.copy(t.getSelectionStart(), t.getSelectionEnd(), false);
}
else if (clicked == mnuPaste)
{
t.paste(t.getCaret().getDot());
}
else if (clicked == mnuDelete)
{
try
{
((TibetanDocument)t.getDocument()).remove(t.getSelectionStart(), t.getSelectionEnd());
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else if (clicked == mnuSelectAll)
{
t.selectAll();
}
}
}
}
public void itemStateChanged(ItemEvent e)
{
sp.setEnableTibetanScript(e.getStateChange()==ItemEvent.SELECTED);
}
}

View file

@ -0,0 +1,122 @@
/*
The contents of this file are subject to the AMP Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the AMP web site
(http://www.tibet.iteso.mx/Guatemala/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is Andres Montano Pellegrini. Portions
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
Pellegrini. All Rights Reserved.
Contributor(s): ______________________________________.
*/
/** Used to make up the list of words to be displayed, not
to store the dictionary. */
package org.thdl.tib.scanner;
import org.thdl.tib.text.TibetanHTML;
public class Word extends Token
{
/** Used to rebuild the text the user entered. */
private String wordSinDec;
private Definitions def;
public Word (String word, String wordSinDec, String def)
{
super(word);
this.wordSinDec=wordSinDec;
this.def=new Definitions(def);
}
public Word (String word, String wordSinDec, Definitions def)
{
super(word);
this.wordSinDec=wordSinDec;
this.def=def;
}
public Word (String word, String def)
{
this(word, null, def);
}
public Word (String word, Definitions def)
{
this(word, null, def);
}
public boolean equals(Object o)
{
Word wO;
if (o instanceof Word)
{
wO = (Word) o;
return super.token.equals(wO.token);
}
return false;
}
public String getWylie()
{
return super.token;
}
public String getDef()
{
return def.toString();
}
public Definitions getDefs()
{
return def;
}
public String toString()
{
return super.token + " - " + def;
}
public String getBookmark(boolean tibetan)
{
String localWord;
if (tibetan) localWord = TibetanHTML.getHTML(super.token + " ");
else localWord = "<b>" + super.token + "</b>";
return "<a name=\"" + super.token + "\">" + localWord + "</a>";
}
public String getLink()
{
return getLink(false);
}
public String getLink(boolean tibetan)
{
String localWord, result;
if (wordSinDec==null) localWord = super.token;
else localWord = wordSinDec;
if (tibetan) localWord = TibetanHTML.getHTML(localWord + " ");
/* result = "<a href=\"#" + word + "\">" + localWord;
if (tibetan) result+= "</a>";
else result+= "</a> ";
return result;*/
return "<a href=\"#" + super.token + "\">" + localWord + "</a> ";
}
/** Called in order to redisplay the text with links keeping
the returns the user entered.
*/
public void makeEnter()
{
if (wordSinDec==null)
wordSinDec=new String(super.token);
wordSinDec+="</p><p>";
}
}