2002-10-03 19:28:09 +00:00
|
|
|
/*
|
|
|
|
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.*;
|
2003-04-01 13:08:38 +00:00
|
|
|
import org.thdl.util.SimplifiedLinkedList;
|
|
|
|
import org.thdl.util.SimplifiedListIterator;
|
|
|
|
import org.thdl.util.Link;
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
/** Converts Tibetan dictionaries stored in text files
|
|
|
|
into a binary file tree structure format, to be used
|
|
|
|
by some implementations of the SyllableListTree.
|
|
|
|
|
2002-11-28 06:54:46 +00:00
|
|
|
<p>Syntax (Dictionary files are assumed to be .txt. Don't include extensions!):<ul>
|
|
|
|
<li><b>For one dictionary</b>, to read the definitions stored in <i>
|
|
|
|
dic-name.txt</i> and organize them into <i>dic-name.wrd</i> and <i>
|
|
|
|
dic-name.def</i>:<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator [-delimiter] dict-name</pre>
|
|
|
|
</li>
|
|
|
|
<li><b>For multiple dictionaries</b>, to read the definitions stored in <i>
|
|
|
|
dict-name1.txt</i>, <i>dict-name2.txt</i>, etc.and organize them into <i>
|
|
|
|
dest-file-name.wrd</i> and <i>dest-file-name.def</i>:<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator dest-file-name [-delimiter1] dict-name1 [[-delimiter2] dict-name2 ...]</pre>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p>-delimiter<ul>
|
|
|
|
<li><b>If this option is omitted</b>, it is assumed that each line is an entry
|
|
|
|
(no multiple-line entries) and the definition and definiendum are separated
|
|
|
|
by '-' (a dash). Even though it is not
|
|
|
|
required, it is highly recommended to include a space before and afterwards
|
|
|
|
(to eliminate any possible ambiguity with regards to the transliteration of
|
|
|
|
reverse vowels in <a href="http://iris.lib.virginia.edu/tibet/tools/ewts.pdf" target="_blank">
|
|
|
|
Extended Wylie</a>). A sample entry for the dictionary is:
|
|
|
|
<hr>
|
|
|
|
<pre>bkra shis - 1) auspiciousness, good luck, good fortune, goodness, prosperity, happiness. 2) auspicious, favorable, fortunate, successful, felicitous, lucky. 3) verse of auspiciousness; benediction, blessing. 4) a personal name.
|
|
|
|
bde legs - 1) goodness, happiness, well-being, wellfare, auspiciousness, good fortune. 2) well, fine.</pre>
|
|
|
|
<hr>
|
|
|
|
<p>If this were the content of a file called "<i>my-glossary.txt</i>" the
|
|
|
|
binary tree file would be generated with the command:</p>
|
|
|
|
<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator my-glossary</pre>
|
|
|
|
</li>
|
|
|
|
<li>-<b>tab</b>: it is assumed that each line is an entry (no multiple-line
|
|
|
|
entries) and the definition and definiendum are separated by '\t' (horizontal tabulation).
|
|
|
|
One tabulation is enough; don't feel the need to "align" the definitions in your
|
|
|
|
word-processor. A sample entry for the dictionary is:<hr>
|
|
|
|
<pre>bkra shis 1) auspiciousness, good luck, good fortune, goodness, prosperity, happiness. 2) auspicious, favorable, fortunate, successful, felicitous, lucky. 3) verse of auspiciousness; benediction, blessing. 4) a personal name.
|
|
|
|
bde legs 1) goodness, happiness, well-being, wellfare, auspiciousness, good fortune. 2) well, fine.</pre>
|
|
|
|
<hr>
|
|
|
|
<p>Here, the
|
|
|
|
binary tree file would be generated with the command:</p>
|
|
|
|
<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator -tab my-glossary</pre>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<b>-<i>string</i></b>: it is assumed that each line is an entry (no multiple-line
|
|
|
|
entries) and the definition and definiendum are separated by the character or
|
|
|
|
string of characters specified by the user. A sample entry for the dictionary
|
|
|
|
is:<hr>
|
|
|
|
<pre>bkra shis ** 1) auspiciousness, good luck, good fortune, goodness, prosperity, happiness. 2) auspicious, favorable, fortunate, successful, felicitous, lucky. 3) verse of auspiciousness; benediction, blessing. 4) a personal name.
|
|
|
|
bde legs ** 1) goodness, happiness, well-being, wellfare, auspiciousness, good fortune. 2) well, fine.</pre>
|
|
|
|
<hr>
|
|
|
|
<p>Here, the
|
|
|
|
binary tree file would be generated with the command:</p>
|
|
|
|
<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator -** my-glossary</pre>
|
|
|
|
</li>
|
|
|
|
<li>-<b>acip</b>: it is assumed that the electronic file is a transliteration of
|
|
|
|
a Tibetan dictionary. It is called "acip" because it accepts Acip's comment
|
|
|
|
codes ('@' to mark page numbers, brackets to mark comments, etc). Nevertheless,
|
|
|
|
it still requires the files to be in <a href="http://iris.lib.virginia.edu/tibet/tools/ewts.pdf" target="_blank">
|
|
|
|
Extended Wylie</a>, so if your file is in Acip's transliteration scheme make
|
|
|
|
sure to run <i><a href="#org.thdl.tib.scanner.AcipToWylie">org.thdl.tib.scanner.AcipToWylie</a></i> first. Definitions here can
|
|
|
|
be of multiple lines, but with no blank lines in between. It is assumed that the
|
|
|
|
definiendum starts after a blank line (except at the beginning of a new page
|
|
|
|
where it could start with the last part of the previous definition) up to the <i>
|
|
|
|
shad</i> (except when the <i>shad</i> is omitted because of grammar rules as for
|
|
|
|
instance no shad after a "ga" suffix without a secondary suffix). Each
|
|
|
|
time a new letter starts, it should be clearly marked in brackets ('[', ']'),
|
|
|
|
parenthesis ('(', ')') or llaves ('{','}'). A sample entry for the dictionary is:
|
|
|
|
<hr>
|
2003-02-03 01:36:08 +00:00
|
|
|
<pre>@1
|
2002-11-28 06:54:46 +00:00
|
|
|
|
|
|
|
(ka)
|
|
|
|
|
|
|
|
ka ba/ gdung 'degs don byed nus pa/
|
|
|
|
|
|
|
|
rkyen/ grogs byed
|
|
|
|
|
2003-02-03 01:36:08 +00:00
|
|
|
@2
|
2002-11-28 06:54:46 +00:00
|
|
|
|
|
|
|
(kha)
|
|
|
|
|
|
|
|
khyod dngos po dang de byung 'brel/ khyod dngos po las byung
|
|
|
|
zhing/ dngos po ldog stops kyis khyod ldog pa/
|
|
|
|
|
|
|
|
khyod dngos po dang bdag gcig 'brel/ khyod ngos po dang bdag
|
|
|
|
nyid gcig pa'i sgo nas tha dad gang zhig/ dngos po ldog
|
|
|
|
stops kyis khyod ldog pa/
|
|
|
|
|
|
|
|
khyod dngos po dang 'brel pa/ khyod dngos po dang tha dad gang
|
|
|
|
|
2003-02-03 01:36:08 +00:00
|
|
|
@3
|
2002-11-28 06:54:46 +00:00
|
|
|
|
|
|
|
zhig/ ngos po ldog stobs kyis khyod ldog pa/
|
|
|
|
|
|
|
|
kha dog mdog du rung ba'am/ sngo ser dkar dmar sogs mdog tu
|
|
|
|
rung ba'i gzugs/</pre>
|
|
|
|
<hr>
|
|
|
|
<p>Here the
|
|
|
|
binary tree file would be generated with the command:</p>
|
|
|
|
<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator -acip my-glossary</pre>
|
|
|
|
<p><i>Comments:</i> Notice in the sample text that at the beginning of page 2, "<i>zhig</i>" is not a
|
|
|
|
new definiendum, but still is part of the definition of "<i>khyod dngos po dang 'brel
|
|
|
|
pa</i>". Also the definiendum of the last entry is "<i>kha dog</i>"
|
|
|
|
(the <i>shad</i> was omitted after "<i>ga</i>" suffix) and not "<i>kha dog mdog du rung ba'am</i>".
|
|
|
|
Nevertheless the definiendum of the second term is not "<i>khyod dngos po dang bdag</i>"
|
|
|
|
since there is no omitted <i>shad</i> after that "<i>ga</i>" suffix; the
|
|
|
|
definiedum is "<i>khyod dngos po dang bdag gcig 'brel</i>". As is clear from the
|
|
|
|
sample text, the tool has to make a series of "smart guesses" to try to figure
|
|
|
|
out where each definiendum end and it's definition start. Such process is
|
|
|
|
not 100% full-proof, so expect some mistakes.<br>
|
|
|
|
</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<p>Dictionaries in different formats can be processed together. For instance the
|
|
|
|
command:
|
|
|
|
<pre>java -cp DictionarySearchStandalone.jar org.thdl.tib.scanner.BinaryFileGenerator alldicts ry-dic99 -acip myglossary_uma -tab myglossary_rdzogs-chen</pre>
|
|
|
|
<p>would generate <i>alldicts.def</i> and <i>alldicts.wrd</i> processing <i>ry-dic99.txt</i>
|
|
|
|
as dash-separated, <i>myglossary_rdzogs-chen.txt</i> as tab-separated and <i>
|
|
|
|
myglossary_uma.txt</i> in the transliteration format explained above.<br>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
@author Andrés Montano Pellegrini
|
|
|
|
@see SyllableListTree
|
|
|
|
@see FileSyllableListTree
|
|
|
|
@see CachedSyllableListTree
|
|
|
|
*/
|
2003-04-01 13:08:38 +00:00
|
|
|
public class BinaryFileGenerator extends SimplifiedLinkedList
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
private static final int versionNumber = 3;
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
private long posHijos;
|
|
|
|
private String sil, def[];
|
2003-08-03 06:27:30 +00:00
|
|
|
public final static int delimiterGeneric=0;
|
|
|
|
public final static int delimiterAcip=1;
|
|
|
|
public final static int delimiterDash=2;
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
/** Number of dictionary. If 0, partial word (no definition).
|
|
|
|
*/
|
2004-08-13 04:47:35 +00:00
|
|
|
private ByteDictionarySource sourceDef;
|
2002-10-03 19:28:09 +00:00
|
|
|
public static RandomAccessFile wordRaf;
|
|
|
|
private static RandomAccessFile defRaf;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
wordRaf = null;
|
|
|
|
defRaf = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinaryFileGenerator()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
sil = null;
|
|
|
|
def = null;
|
|
|
|
posHijos=-1;
|
|
|
|
sourceDef = null;
|
|
|
|
}
|
|
|
|
|
2003-08-03 06:27:30 +00:00
|
|
|
private BinaryFileGenerator(String sil, String def, int numDef)
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
|
|
|
super();
|
2005-02-21 05:10:00 +00:00
|
|
|
int marker;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
marker = Manipulate.indexOfExtendedEndOfSyllableMark(sil);
|
|
|
|
if (marker==0) sil = sil.substring(1);
|
|
|
|
else if (marker==sil.length()-1) sil = sil.substring(0,sil.length()-1);
|
|
|
|
else break;
|
|
|
|
}
|
2004-08-13 04:47:35 +00:00
|
|
|
|
|
|
|
// fix for updates
|
|
|
|
this.sourceDef = new ByteDictionarySource();
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
if (marker<0)
|
|
|
|
{
|
|
|
|
this.sil = sil;
|
|
|
|
this.def = new String[1];
|
|
|
|
this.def[0] = def;
|
2004-08-13 04:47:35 +00:00
|
|
|
this.sourceDef.addNewDef(numDef);
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2003-08-03 06:27:30 +00:00
|
|
|
|
|
|
|
public void addFile(String archivo, int delimiterType, String delimiter, int defNum) throws Exception
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
final short newDefiniendum=1, halfDefiniendum=2, definition=3;
|
|
|
|
short status=newDefiniendum;
|
2004-08-13 04:47:35 +00:00
|
|
|
int marker, len, marker2, currentPage=0, currentLine=1;
|
2002-10-09 00:13:27 +00:00
|
|
|
char ch;
|
2002-10-03 19:28:09 +00:00
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo)));
|
2003-09-14 05:56:20 +00:00
|
|
|
String entrada="", s1="", s2="", currentLetter="", temp="", lastWeirdDefiniendum="", alternateWords[];
|
2002-10-09 00:13:27 +00:00
|
|
|
boolean markerNotFound;
|
2002-10-06 16:17:56 +00:00
|
|
|
|
2002-10-09 00:13:27 +00:00
|
|
|
// used for acip dict
|
2002-11-27 23:30:44 +00:00
|
|
|
switch(delimiterType)
|
2002-10-06 16:17:56 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
case delimiterAcip:
|
|
|
|
outAHere:
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
entrada=br.readLine();
|
|
|
|
if (entrada==null) break;
|
|
|
|
currentLine++;
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
entrada = entrada.trim();
|
|
|
|
len = entrada.length();
|
|
|
|
if (len<=0) continue;
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
// get page number
|
|
|
|
if (entrada.charAt(0)=='@')
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
marker = 1;
|
|
|
|
while(marker<len && Character.isDigit(entrada.charAt(marker)))
|
|
|
|
marker++;
|
|
|
|
temp = entrada.substring(1, marker);
|
|
|
|
if (temp.length()>0)
|
|
|
|
currentPage=Integer.parseInt(temp);
|
|
|
|
if (marker<len)
|
|
|
|
{
|
|
|
|
entrada = entrada.substring(marker).trim();
|
|
|
|
len = entrada.length();
|
|
|
|
}
|
|
|
|
else continue;
|
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
// get current letter
|
|
|
|
if (entrada.charAt(0)=='(' || entrada.charAt(0)=='{' || entrada.charAt(0)=='?')
|
|
|
|
{
|
|
|
|
currentLetter = entrada.substring(1, entrada.length()-2);
|
|
|
|
/*out.println(currentPage + ": " + currentLetter);
|
|
|
|
n++;*/
|
|
|
|
continue;
|
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
if (entrada.charAt(0)=='[')
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
marker=1;
|
|
|
|
markerNotFound=true;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while (marker<len && markerNotFound)
|
|
|
|
{
|
|
|
|
if (entrada.charAt(marker)==']') markerNotFound=false;
|
|
|
|
else marker++;
|
|
|
|
}
|
|
|
|
if (markerNotFound)
|
|
|
|
{
|
|
|
|
entrada=br.readLine();
|
|
|
|
if (entrada==null) break outAHere;
|
|
|
|
currentLine++;
|
|
|
|
len = entrada.length();
|
|
|
|
marker=0;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
} while (true);
|
|
|
|
if (marker<len)
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
entrada = entrada.substring(marker+1).trim();
|
|
|
|
len = entrada.length();
|
|
|
|
if (len<=0) continue;
|
|
|
|
}
|
|
|
|
else continue;
|
2002-10-09 00:13:27 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
// skip stuff. Add to previous definition.
|
|
|
|
if (entrada.startsWith("..."))
|
|
|
|
{
|
|
|
|
entrada=entrada.substring(3);
|
|
|
|
len = entrada.length();
|
|
|
|
if (len<=0) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find definiendum
|
|
|
|
ch = entrada.charAt(0);
|
|
|
|
if (Character.isLetter(ch) || ch=='\'')
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
/* first criteria: if it is not the root letter of section it is part of the
|
|
|
|
previous definition, probably a page change, else go for it with following
|
|
|
|
code: */
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
// get first syllable to check base letter
|
|
|
|
marker=1;
|
|
|
|
while (marker<len)
|
|
|
|
{
|
|
|
|
ch = entrada.charAt(marker);
|
2005-02-21 05:10:00 +00:00
|
|
|
if (Manipulate.isEndOfSyllableMark(ch) || Manipulate.isEndOfParagraphMark(ch)) break;
|
2002-11-27 23:30:44 +00:00
|
|
|
marker++;
|
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
if (status!=halfDefiniendum) temp = Manipulate.getBaseLetter(entrada.substring(0, marker));
|
|
|
|
|
|
|
|
// if line begins with current letter, probably it is a definiendum
|
|
|
|
if (status==halfDefiniendum || currentLetter.equals(temp))
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
/* Since new definiendum was found, update last and collect new. No need to update
|
|
|
|
status because it will be updated below. */
|
|
|
|
if (status==definition)
|
|
|
|
{
|
|
|
|
add(s1, s2, defNum);
|
|
|
|
s1=""; s2="";
|
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
marker=marker2=1;
|
|
|
|
markerNotFound=true;
|
|
|
|
|
|
|
|
while (marker < len)
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
ch = entrada.charAt(marker);
|
2005-02-21 05:10:00 +00:00
|
|
|
|
|
|
|
if (Manipulate.isEndOfParagraphMark(ch))
|
|
|
|
{
|
|
|
|
markerNotFound=false;
|
|
|
|
marker2=marker+1;
|
|
|
|
}
|
|
|
|
else if (Manipulate.isEndOfSyllableMark(ch))
|
|
|
|
{
|
|
|
|
if (marker+1<len && Manipulate.isEndOfSyllableMark(entrada.charAt(marker+1))) // verify " "
|
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
markerNotFound=false;
|
2005-02-21 05:10:00 +00:00
|
|
|
marker2=++marker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(ch)
|
|
|
|
{
|
|
|
|
case '(': case '<':
|
2002-10-14 21:08:19 +00:00
|
|
|
markerNotFound=false;
|
2005-02-21 05:10:00 +00:00
|
|
|
marker2=marker;
|
|
|
|
break;
|
|
|
|
case 'g': // verify "g "
|
|
|
|
if (marker+1<len && Manipulate.isVowel(entrada.charAt(marker-1)) && Manipulate.isEndOfSyllableMark(entrada.charAt(marker+1)))
|
|
|
|
{
|
|
|
|
temp = entrada.substring(0, marker+1);
|
|
|
|
if (!lastWeirdDefiniendum.startsWith(temp))
|
|
|
|
{
|
|
|
|
markerNotFound=false;
|
|
|
|
marker2=++marker;
|
|
|
|
lastWeirdDefiniendum=temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
if (marker+2<len && entrada.charAt(marker+1)=='.' && entrada.charAt(marker+2)=='.')
|
|
|
|
{
|
|
|
|
markerNotFound=false;
|
|
|
|
marker2=marker;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (Character.isDigit(ch))
|
|
|
|
{
|
|
|
|
markerNotFound=false;
|
|
|
|
marker2=marker;
|
|
|
|
}
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
|
|
|
if (markerNotFound) marker++;
|
|
|
|
else break;
|
2002-10-09 00:13:27 +00:00
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
|
|
|
|
/* either this is a definiendum that consists of several lines or
|
|
|
|
it is part of the last definition. */
|
|
|
|
if (markerNotFound)
|
|
|
|
{
|
|
|
|
/* assume that the definiendum goes on to the next line. */
|
|
|
|
s1 = s1 + entrada + " ";
|
|
|
|
status=halfDefiniendum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s1 = s1 + entrada.substring(0,marker).trim();
|
|
|
|
s2 = "[" + currentPage + "] " + entrada.substring(marker2).trim();
|
|
|
|
status=definition;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
entrada=br.readLine();
|
|
|
|
|
|
|
|
if (entrada==null)
|
|
|
|
{
|
|
|
|
add(s1, s2, defNum);
|
|
|
|
break outAHere;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLine++;
|
|
|
|
entrada = entrada.trim();
|
|
|
|
|
|
|
|
if (entrada.equals("")) break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s2 = s2 + " " + entrada;
|
|
|
|
}
|
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // last line did not start with the current letter, it must still be part of the definition
|
|
|
|
{
|
|
|
|
s2 = s2 + " " + entrada;
|
2002-10-09 00:13:27 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
entrada=br.readLine();
|
2002-11-27 23:30:44 +00:00
|
|
|
|
|
|
|
if (entrada==null)
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
add(s1, s2, defNum);
|
|
|
|
break outAHere;
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
|
2002-10-09 00:13:27 +00:00
|
|
|
currentLine++;
|
|
|
|
entrada = entrada.trim();
|
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
if (entrada.equals("")) break;
|
|
|
|
else
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
s2 = s2 + " " + entrada;
|
|
|
|
}
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
2002-10-09 00:13:27 +00:00
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
else // if first character was not a letter, it must still be part of definition
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
s2 = s2 + " " + entrada;
|
|
|
|
while (true)
|
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
entrada=br.readLine();
|
|
|
|
|
2002-10-09 00:13:27 +00:00
|
|
|
if (entrada==null)
|
2002-11-27 23:30:44 +00:00
|
|
|
{
|
|
|
|
add(s1, s2, defNum);
|
2002-10-09 00:13:27 +00:00
|
|
|
break outAHere;
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
|
2002-10-09 00:13:27 +00:00
|
|
|
currentLine++;
|
|
|
|
entrada = entrada.trim();
|
|
|
|
|
2002-11-27 23:30:44 +00:00
|
|
|
if (entrada.equals("")) break;
|
|
|
|
else
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
s2 = s2 + " " + entrada;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while ((entrada = br.readLine())!=null)
|
|
|
|
{
|
|
|
|
entrada = entrada.trim();
|
|
|
|
if (!entrada.equals(""))
|
|
|
|
{
|
|
|
|
switch(delimiterType)
|
|
|
|
{
|
|
|
|
/* this is needed to make sure that the dash used in reverse vowels with extended
|
|
|
|
wylie is not confused with the dash that separates definiendum and definition. */
|
|
|
|
case delimiterDash:
|
|
|
|
marker=entrada.indexOf('-');
|
|
|
|
len = entrada.length();
|
|
|
|
while (marker>=0 && marker<len-1 && Manipulate.isVowel(entrada.charAt(marker+1)) && !Character.isWhitespace(entrada.charAt(marker-1)))
|
|
|
|
{
|
|
|
|
marker = entrada.indexOf('-', marker+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
marker = entrada.indexOf(delimiter);
|
|
|
|
}
|
2005-02-21 05:10:00 +00:00
|
|
|
if (marker<=0)
|
2002-10-09 00:13:27 +00:00
|
|
|
{
|
2002-11-27 23:30:44 +00:00
|
|
|
System.out.println("Error loading line " + currentLine + ", in file " + archivo + ":");
|
|
|
|
System.out.println(entrada);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-21 05:10:00 +00:00
|
|
|
marker2 = Manipulate.indexOfBracketMarks(entrada.substring(0,marker));
|
|
|
|
if (marker2>0) marker = marker2;
|
|
|
|
|
2004-07-05 03:56:20 +00:00
|
|
|
s1 = Manipulate.deleteQuotes(entrada.substring(0,marker).trim());
|
2005-02-21 05:10:00 +00:00
|
|
|
s2 = Manipulate.deleteQuotes(entrada.substring(marker+delimiter.length())).trim();
|
|
|
|
|
|
|
|
if (Manipulate.isMeaningful(s2))
|
2003-09-23 19:05:23 +00:00
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
if (currentLine%5000==0)
|
|
|
|
{
|
|
|
|
System.out.println("Adding " + s1 + "...");
|
|
|
|
System.out.flush();
|
|
|
|
}
|
2003-09-23 19:05:23 +00:00
|
|
|
marker2 = s1.indexOf(';');
|
|
|
|
if (marker2>0)
|
|
|
|
{
|
2004-07-05 03:56:20 +00:00
|
|
|
alternateWords = s1.split(";");
|
2003-09-23 19:05:23 +00:00
|
|
|
for (marker2=0; marker2<alternateWords.length; marker2++)
|
|
|
|
{
|
|
|
|
add(alternateWords[marker2],s2, defNum);
|
|
|
|
}
|
|
|
|
|
2003-09-14 05:56:20 +00:00
|
|
|
}
|
2003-09-23 19:05:23 +00:00
|
|
|
else add(s1, s2 , defNum);
|
2003-09-14 05:56:20 +00:00
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-09 08:00:58 +00:00
|
|
|
currentLine++;
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
2002-10-06 16:17:56 +00:00
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void add(String word, String def, int defNum)
|
|
|
|
{
|
|
|
|
Link link, newLink;
|
|
|
|
BinaryFileGenerator ultimo;
|
|
|
|
String firstSillable;
|
2005-02-21 05:10:00 +00:00
|
|
|
int marker, comp;
|
2003-09-23 19:05:23 +00:00
|
|
|
|
2005-02-21 05:10:00 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
marker = Manipulate.indexOfExtendedEndOfSyllableMark(word);
|
|
|
|
if (marker==0) word = word.substring(1);
|
|
|
|
else if (marker==word.length()-1) word = word.substring(0,word.length()-1);
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-13 04:47:35 +00:00
|
|
|
|
|
|
|
private void reGroup (int n)
|
|
|
|
{
|
|
|
|
int i, pos, posEnd;
|
|
|
|
|
|
|
|
for (i=0; i<def.length; i++)
|
|
|
|
{
|
|
|
|
if (i!=n)
|
|
|
|
{
|
|
|
|
// deal with repetitions of definitions
|
|
|
|
if (def[i].length()>=def[n].length())
|
|
|
|
{
|
|
|
|
pos = def[i].indexOf(def[n]);
|
|
|
|
|
|
|
|
// if it is the same String exactly
|
|
|
|
if (pos==0 && def[i].length()==def[n].length())
|
|
|
|
{
|
|
|
|
if (i<n)
|
|
|
|
{
|
|
|
|
sourceDef.addDictToDef(sourceDef.getDef(n), i);
|
|
|
|
def = Manipulate.deleteString(def, n);
|
|
|
|
sourceDef.deleteDef(n);
|
|
|
|
n = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sourceDef.addDictToDef(sourceDef.getDef(i), n);
|
|
|
|
def = Manipulate.deleteString(def, i);
|
|
|
|
sourceDef.deleteDef(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
posEnd = pos + def[n].length();
|
|
|
|
|
|
|
|
if ((pos==0 || (pos>0 && !Character.isLetter(def[i].charAt(pos-1)))) && (posEnd==def[i].length() || !Character.isLetter(def[i].charAt(posEnd))))
|
|
|
|
{
|
|
|
|
if(sourceDef.getDef(i).contains(sourceDef.getDef(n)))
|
|
|
|
{
|
|
|
|
def = Manipulate.deleteString(def, n);
|
|
|
|
sourceDef.deleteDef(n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// else
|
|
|
|
sourceDef.addDictToDef(sourceDef.getDef(i), n);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
def[i] = Manipulate.replace(def[i], pos, posEnd, "*");
|
|
|
|
pos = def[i].indexOf(def[n]);
|
|
|
|
posEnd = pos + def[n].length();
|
|
|
|
} while ((pos==0 || (pos>0 && !Character.isLetter(def[i].charAt(pos-1)))) && (posEnd==def[i].length() || !Character.isLetter(def[i].charAt(posEnd))));
|
|
|
|
|
|
|
|
if (i<n)
|
|
|
|
{
|
|
|
|
def = Manipulate.addString(def, def[n], i);
|
|
|
|
def = Manipulate.deleteString(def, n+1);
|
|
|
|
sourceDef.insertDef(sourceDef.getDef(n), i);
|
|
|
|
sourceDef.deleteDef(n+1);
|
|
|
|
n = i;
|
|
|
|
reGroup(i+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reGroup(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = def[n].indexOf(def[i]);
|
|
|
|
posEnd = pos + def[i].length();
|
|
|
|
|
|
|
|
if ((pos==0 || (pos>0 && !Character.isLetter(def[n].charAt(pos-1)))) && (posEnd==def[n].length() || !Character.isLetter(def[n].charAt(posEnd))))
|
|
|
|
{
|
|
|
|
if (sourceDef.getDef(n).contains(sourceDef.getDef(i)))
|
|
|
|
{
|
|
|
|
def = Manipulate.deleteString(def, i);
|
|
|
|
sourceDef.deleteDef(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceDef.addDictToDef(sourceDef.getDef(n), i);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
def[n] = Manipulate.replace(def[n], pos, posEnd, "*");
|
|
|
|
pos = def[n].indexOf(def[i]);
|
|
|
|
posEnd = pos + def[i].length();
|
|
|
|
} while ((pos==0 || (pos>0 && !Character.isLetter(def[n].charAt(pos-1)))) && (posEnd==def[n].length() || !Character.isLetter(def[n].charAt(posEnd))));
|
|
|
|
|
|
|
|
i=-1; // start over
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// deal with repetition of dictionaries
|
|
|
|
|
|
|
|
if (sourceDef.getDef(i).equals(sourceDef.getDef(n)))
|
|
|
|
{
|
|
|
|
if (i<n)
|
|
|
|
{
|
|
|
|
def[i] = def[i] + ". " + def[n];
|
|
|
|
def = Manipulate.deleteString(def, n);
|
|
|
|
sourceDef.deleteDef(n);
|
|
|
|
n = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
def[n] = def[n] + ". " + def[i];
|
|
|
|
def = Manipulate.deleteString(def, i);
|
|
|
|
sourceDef.deleteDef(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
private void addMoreDef(String def, int numDef)
|
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
String temp;
|
|
|
|
boolean notAlreadyThere, changed;
|
|
|
|
int i, pos, posEnd;
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
if (this.def==null)
|
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
// add a new definition for this dictionary
|
2002-10-03 19:28:09 +00:00
|
|
|
this.def = new String[1];
|
|
|
|
this.def[0] = def;
|
2004-08-13 04:47:35 +00:00
|
|
|
//sourceDef.add(numDef);
|
|
|
|
sourceDef.addNewDef(numDef);
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
notAlreadyThere = true;
|
|
|
|
do
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
i=0;
|
|
|
|
changed = false;
|
|
|
|
|
|
|
|
while (notAlreadyThere && i<this.def.length)
|
|
|
|
{
|
|
|
|
if (this.def[i].length()>=def.length())
|
|
|
|
{
|
|
|
|
pos = this.def[i].indexOf(def);
|
|
|
|
posEnd = pos + def.length();
|
|
|
|
if ((pos==0 || (pos>0 && !Character.isLetter(this.def[i].charAt(pos-1)))) && (posEnd==this.def[i].length() || !Character.isLetter(this.def[i].charAt(posEnd))))
|
|
|
|
{
|
|
|
|
if (!sourceDef.isDictInDef(numDef, i))
|
|
|
|
{
|
|
|
|
if (this.def[i].length()>def.length())
|
|
|
|
{
|
|
|
|
//temp = Manipulate.deleteSubstring(this.def[i], pos, posEnd);
|
|
|
|
temp = this.def[i];
|
|
|
|
do
|
|
|
|
{
|
|
|
|
temp = Manipulate.replace(temp, pos, posEnd, "*");
|
|
|
|
pos = temp.indexOf(def);
|
|
|
|
posEnd = pos + def.length();
|
|
|
|
} while ((pos==0 || (pos>0 && !Character.isLetter(temp.charAt(pos-1)))) && (posEnd==temp.length() || !Character.isLetter(temp.charAt(posEnd))));
|
|
|
|
|
|
|
|
this.def[i] = def;
|
|
|
|
this.def = Manipulate.addString(this.def, temp, i+1);
|
|
|
|
sourceDef.dubDef(i);
|
|
|
|
sourceDef.addDictToDef(numDef, i);
|
|
|
|
|
|
|
|
reGroup(i);
|
|
|
|
if (i+1<this.def.length) reGroup(i+1);
|
|
|
|
else reGroup(this.def.length-1);
|
|
|
|
}
|
|
|
|
else sourceDef.addDictToDef(numDef, i);
|
|
|
|
}
|
|
|
|
notAlreadyThere = false;
|
|
|
|
changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = def.indexOf(this.def[i]);
|
|
|
|
posEnd = pos + this.def[i].length();
|
|
|
|
|
|
|
|
if ((pos==0 || (pos>0 && !Character.isLetter(def.charAt(pos-1)))) && (posEnd==def.length() || !Character.isLetter(def.charAt(posEnd))))
|
|
|
|
{
|
|
|
|
if (sourceDef.isDictInDefAlone(numDef, i))
|
|
|
|
{
|
|
|
|
this.def[i] = def;
|
|
|
|
reGroup(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sourceDef.addDictToDef(numDef, i);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//def = Manipulate.deleteSubstring(def, pos, posEnd);
|
|
|
|
def = Manipulate.replace(def, pos, posEnd, "*");
|
|
|
|
pos = def.indexOf(this.def[i]);
|
|
|
|
posEnd = pos + this.def[i].length();
|
|
|
|
} while ((pos==0 || (pos>0 && !Character.isLetter(def.charAt(pos-1)))) && (posEnd==def.length() || !Character.isLetter(def.charAt(posEnd))));
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} while (changed);
|
|
|
|
|
|
|
|
if (notAlreadyThere)
|
|
|
|
{
|
|
|
|
// check if it is a duplicate for the same dictionary.
|
|
|
|
i = sourceDef.containsAlone(numDef);
|
|
|
|
if (i>-1)
|
|
|
|
{
|
|
|
|
this.def[i] = this.def[i] + ". " + def;
|
|
|
|
reGroup(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.def = Manipulate.addString(this.def, def, this.def.length);
|
|
|
|
sourceDef.addNewDef(numDef);
|
|
|
|
reGroup(this.def.length-1);
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
try
|
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
wordRaf.writeInt((int)defRaf.getFilePointer());
|
|
|
|
defRaf.writeUTF(def[i]);
|
2002-10-09 00:13:27 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
System.out.println(def[i]);
|
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void print() throws Exception
|
|
|
|
{
|
|
|
|
long pos;
|
2003-04-01 13:08:38 +00:00
|
|
|
SimplifiedListIterator i = listIterator();
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-09 00:13:27 +00:00
|
|
|
private static void printSintax()
|
|
|
|
{
|
2002-10-03 19:28:09 +00:00
|
|
|
System.out.println("Stores multiple dictionaries into a binary tree file.");
|
2002-10-09 00:13:27 +00:00
|
|
|
System.out.println("Sintaxis:");
|
2002-10-03 19:28:09 +00:00
|
|
|
System.out.println("-For multiple dictionary sources:");
|
2002-10-14 21:08:19 +00:00
|
|
|
System.out.println(" java BinaryFileGenerator arch-dest [-delimiter1] arch-dict1");
|
|
|
|
System.out.println(" [[-delimiter2] arch-dict2 ...]");
|
2002-10-03 19:28:09 +00:00
|
|
|
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.");
|
2002-10-14 21:08:19 +00:00
|
|
|
System.out.println(" -acip: use this to process dictionaries entered using the ACIP standard");
|
|
|
|
System.out.println(" to mark page numbers, comments, etc. Make sure to convert it to");
|
|
|
|
System.out.println(" THDL's extended Wylie scheme first using the AcipToWylie class.");
|
2003-08-03 06:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void generateDatabase(String name) throws Exception
|
|
|
|
{
|
|
|
|
File wordF = new File(name + ".wrd"), defF = new File(name + ".def");
|
|
|
|
wordF.delete();
|
|
|
|
defF.delete();
|
|
|
|
wordRaf = new RandomAccessFile(wordF,"rw");
|
|
|
|
defRaf = new RandomAccessFile(defF,"rw");
|
|
|
|
print();
|
|
|
|
wordRaf.writeInt((int)posHijos);
|
|
|
|
|
2004-08-13 04:47:35 +00:00
|
|
|
// write version marker
|
|
|
|
wordRaf.writeShort(-1);
|
|
|
|
wordRaf.writeByte(-1);
|
|
|
|
|
|
|
|
// write version number
|
|
|
|
wordRaf.writeByte(versionNumber);
|
2002-10-09 00:13:27 +00:00
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
public static void main(String args[]) throws Exception
|
|
|
|
{
|
2003-08-03 06:27:30 +00:00
|
|
|
int delimiterType;
|
|
|
|
String delimiter;
|
|
|
|
|
|
|
|
int i, n=0, a;
|
|
|
|
|
2004-07-05 03:56:20 +00:00
|
|
|
delimiter = "-";
|
2003-08-03 06:27:30 +00:00
|
|
|
delimiterType=delimiterDash;
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
if (args.length==0)
|
|
|
|
{
|
2002-10-09 00:13:27 +00:00
|
|
|
printSintax();
|
|
|
|
return;
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
BinaryFileGenerator sl = new BinaryFileGenerator();
|
2002-11-19 18:46:14 +00:00
|
|
|
if (args[0].charAt(0)=='-')
|
|
|
|
{
|
|
|
|
if (args[0].equals("-tab"))
|
2002-11-27 23:30:44 +00:00
|
|
|
{
|
|
|
|
delimiterType = delimiterGeneric;
|
2002-11-19 18:46:14 +00:00
|
|
|
delimiter="\t";
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
2002-11-19 18:46:14 +00:00
|
|
|
else if (args[0].equals("-acip"))
|
2002-11-27 23:30:44 +00:00
|
|
|
delimiterType=delimiterAcip;
|
2002-11-19 18:46:14 +00:00
|
|
|
else
|
2002-11-27 23:30:44 +00:00
|
|
|
{
|
|
|
|
delimiterType=delimiterGeneric;
|
2002-11-19 18:46:14 +00:00
|
|
|
delimiter=args[0].substring(1);
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
2002-11-19 18:46:14 +00:00
|
|
|
if (args.length>2)
|
|
|
|
{
|
|
|
|
printSintax();
|
|
|
|
return;
|
|
|
|
}
|
2003-08-03 06:27:30 +00:00
|
|
|
sl.addFile(args[1] + ".txt",delimiterType, delimiter, 0);
|
2002-11-19 18:46:14 +00:00
|
|
|
a=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a=0;
|
|
|
|
if (args.length==1)
|
|
|
|
{
|
2003-08-03 06:27:30 +00:00
|
|
|
sl.addFile(args[0] + ".txt", delimiterType, delimiter, 0);
|
2002-11-19 18:46:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i=1;
|
2002-10-03 19:28:09 +00:00
|
|
|
|
2002-11-19 18:46:14 +00:00
|
|
|
while(i< args.length)
|
|
|
|
{
|
|
|
|
if (args[i].charAt(0)=='-')
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
|
|
|
if (args[i].equals("-tab"))
|
2002-11-27 23:30:44 +00:00
|
|
|
{
|
|
|
|
delimiterType=delimiterGeneric;
|
|
|
|
delimiter="\t";
|
|
|
|
}
|
2002-10-12 01:53:17 +00:00
|
|
|
else if (args[i].equals("-acip"))
|
2002-11-27 23:30:44 +00:00
|
|
|
delimiterType=delimiterAcip;
|
2002-10-03 19:28:09 +00:00
|
|
|
else
|
2002-11-27 23:30:44 +00:00
|
|
|
{
|
|
|
|
delimiterType=delimiterGeneric;
|
2002-11-19 18:46:14 +00:00
|
|
|
delimiter=args[i].substring(1);
|
2002-11-27 23:30:44 +00:00
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
i++;
|
|
|
|
}
|
2002-11-27 23:30:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delimiterType=delimiterDash;
|
|
|
|
}
|
2004-08-13 04:47:35 +00:00
|
|
|
System.out.println("\nProcessing " + args[i] + "...");
|
2003-08-03 06:27:30 +00:00
|
|
|
sl.addFile(args[i] + ".txt", delimiterType, delimiter, n);
|
2002-11-19 18:46:14 +00:00
|
|
|
n++; i++;
|
|
|
|
}
|
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
2004-08-13 04:47:35 +00:00
|
|
|
System.out.println("Writing to file " + args[a] + "...");
|
|
|
|
System.out.flush();
|
2003-08-03 06:27:30 +00:00
|
|
|
sl.generateDatabase(args[a]);
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
2003-02-03 01:36:08 +00:00
|
|
|
}
|