Updated methods to help with the dictionary clean up.
This commit is contained in:
parent
96d0d0d9d0
commit
a82afad92c
6 changed files with 128 additions and 54 deletions
|
@ -49,7 +49,7 @@ public class BitDictionarySource extends DictionarySource
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an instance of DictionarySource with all dictionaries selected */
|
/** Returns an instance of DictionarySource with all dictionaries selected */
|
||||||
public BitDictionarySource getAllDictionaries()
|
public static BitDictionarySource getAllDictionaries()
|
||||||
{
|
{
|
||||||
BitDictionarySource ds = new BitDictionarySource();
|
BitDictionarySource ds = new BitDictionarySource();
|
||||||
ds.setDicts(allDicts);
|
ds.setDicts(allDicts);
|
||||||
|
|
|
@ -113,6 +113,19 @@ public class ByteDictionarySource extends DictionarySource
|
||||||
return dicts[i];
|
return dicts[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDicts()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
BitDictionarySource availableDicts = new BitDictionarySource();
|
||||||
|
|
||||||
|
if (dicts == null) return 0;
|
||||||
|
|
||||||
|
for (i=0; i< dicts.length; i++)
|
||||||
|
availableDicts.add(dicts[i]);
|
||||||
|
|
||||||
|
return availableDicts.getDicts();
|
||||||
|
}
|
||||||
|
|
||||||
public void dubDef(int n)
|
public void dubDef(int n)
|
||||||
{
|
{
|
||||||
BitDictionarySource newDicts[] = new BitDictionarySource[dicts.length+1];
|
BitDictionarySource newDicts[] = new BitDictionarySource[dicts.length+1];
|
||||||
|
|
|
@ -65,4 +65,7 @@ public abstract class DictionarySource
|
||||||
|
|
||||||
/** Returns true if dict is a selected dictionary. */
|
/** Returns true if dict is a selected dictionary. */
|
||||||
public abstract boolean contains(int dict);
|
public abstract boolean contains(int dict);
|
||||||
|
|
||||||
|
/** Returns an array of bits representing the selected dictionaries. */
|
||||||
|
public abstract int getDicts();
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@ Contributor(s): ______________________________________.
|
||||||
package org.thdl.tib.scanner;
|
package org.thdl.tib.scanner;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import org.thdl.util.*;
|
||||||
|
|
||||||
/** Searches the words directly in a file; not the preferred
|
/** Searches the words directly in a file; not the preferred
|
||||||
implementation. The search is too slow!
|
implementation. The search is too slow!
|
||||||
|
@ -34,17 +35,17 @@ import java.io.*;
|
||||||
|
|
||||||
public class FileSyllableListTree implements SyllableListTree
|
public class FileSyllableListTree implements SyllableListTree
|
||||||
{
|
{
|
||||||
private String sil;
|
protected String sil;
|
||||||
private long def[];
|
private long def[];
|
||||||
private long posLista;
|
protected long posLista;
|
||||||
private DictionarySource defSource;
|
protected DictionarySource defSource;
|
||||||
public static BitDictionarySource defSourcesWanted;
|
public static BitDictionarySource defSourcesWanted;
|
||||||
public static RandomAccessFile wordRaf=null;
|
public static RandomAccessFile wordRaf=null;
|
||||||
private static RandomAccessFile defRaf=null;
|
private static RandomAccessFile defRaf=null;
|
||||||
public static int versionNumber;
|
public static int versionNumber;
|
||||||
|
|
||||||
/** Creates the root */
|
/** Creates the root. */
|
||||||
public FileSyllableListTree(String archivo, int defSourcesWanted) throws Exception
|
public FileSyllableListTree(String archivo) throws Exception
|
||||||
{
|
{
|
||||||
sil = null;
|
sil = null;
|
||||||
def = null;
|
def = null;
|
||||||
|
@ -52,15 +53,11 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
|
|
||||||
this.openFiles(archivo);
|
this.openFiles(archivo);
|
||||||
posLista = this.wordRaf.getFilePointer();
|
posLista = this.wordRaf.getFilePointer();
|
||||||
|
|
||||||
/* if versionNumber is 2 use BitDictionarySource
|
|
||||||
else use ByteDictionarySource. */
|
|
||||||
this.defSourcesWanted.setDicts(defSourcesWanted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to create each node (except the root)
|
/** Used to create each node (except the root)
|
||||||
*/
|
*/
|
||||||
public FileSyllableListTree(String sil, long []def, DictionarySource defSource, long posLista)
|
protected FileSyllableListTree(String sil, long []def, DictionarySource defSource, long posLista)
|
||||||
{
|
{
|
||||||
this.sil=sil;
|
this.sil=sil;
|
||||||
this.def=def;
|
this.def=def;
|
||||||
|
@ -101,6 +98,11 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Initiates all static variables, it is called by the constructor of the root
|
||||||
|
FileSyllableListTree (in the case of a pure file tree) or by the
|
||||||
|
constructor of CachedSyllableListTree in the case of the root being loaded
|
||||||
|
into memory.
|
||||||
|
*/
|
||||||
public static void openFiles(String archivo, boolean backwardCompatible) throws Exception
|
public static void openFiles(String archivo, boolean backwardCompatible) throws Exception
|
||||||
{
|
{
|
||||||
long fileSize;
|
long fileSize;
|
||||||
|
@ -162,13 +164,42 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if versionNumber is 2 use BitDictionarySource else use
|
defSourcesWanted = BitDictionarySource.getAllDictionaries();
|
||||||
ByteDictionarySource. */
|
|
||||||
defSourcesWanted = new BitDictionarySource();
|
|
||||||
|
|
||||||
wordRaf.seek(pos);
|
wordRaf.seek(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] getDictionaryDescriptions(String archivo)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo + ".dic")));
|
||||||
|
SimplifiedLinkedList ll1 = new SimplifiedLinkedList(), ll2 = new SimplifiedLinkedList();
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DictionarySource.setTags(ll2.toStringArray());
|
||||||
|
return ll1.toStringArray();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getDef()
|
public String getDef()
|
||||||
{
|
{
|
||||||
return getDefs().toString();
|
return getDefs().toString();
|
||||||
|
@ -242,7 +273,7 @@ public class FileSyllableListTree implements SyllableListTree
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (silStr==null) return null;
|
if (silStr==null || posLista==-1) return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wordRaf.seek(posLista);
|
wordRaf.seek(posLista);
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class LocalTibetanScanner extends TibetanScanner
|
||||||
private void scanSyllable(String sil)
|
private void scanSyllable(String sil)
|
||||||
{
|
{
|
||||||
SyllableListTree resultado=null;
|
SyllableListTree resultado=null;
|
||||||
Enumeration enum;
|
Enumeration enumeration;
|
||||||
Word w;
|
Word w;
|
||||||
String silSinDec;
|
String silSinDec;
|
||||||
boolean aadded;
|
boolean aadded;
|
||||||
|
@ -171,10 +171,10 @@ public class LocalTibetanScanner extends TibetanScanner
|
||||||
wordList.addLast(w);
|
wordList.addLast(w);
|
||||||
this.resetAll();
|
this.resetAll();
|
||||||
|
|
||||||
enum = floatingSil.elements();
|
enumeration = floatingSil.elements();
|
||||||
floatingSil = new Vector();
|
floatingSil = new Vector();
|
||||||
while (enum.hasMoreElements())
|
while (enumeration.hasMoreElements())
|
||||||
scanSyllable((String)enum.nextElement());
|
scanSyllable((String)enumeration.nextElement());
|
||||||
|
|
||||||
scanSyllable(sil);
|
scanSyllable(sil);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ public class LocalTibetanScanner extends TibetanScanner
|
||||||
|
|
||||||
public void finishUp()
|
public void finishUp()
|
||||||
{
|
{
|
||||||
Enumeration enum;
|
Enumeration enumeration;
|
||||||
Word w;
|
Word w;
|
||||||
|
|
||||||
while (lastCompSil!=null)
|
while (lastCompSil!=null)
|
||||||
|
@ -208,10 +208,10 @@ public class LocalTibetanScanner extends TibetanScanner
|
||||||
wordList.addLast(w);
|
wordList.addLast(w);
|
||||||
this.resetAll();
|
this.resetAll();
|
||||||
|
|
||||||
enum = floatingSil.elements();
|
enumeration = floatingSil.elements();
|
||||||
floatingSil = new Vector();
|
floatingSil = new Vector();
|
||||||
while (enum.hasMoreElements())
|
while (enumeration.hasMoreElements())
|
||||||
scanSyllable((String)enum.nextElement());
|
scanSyllable((String)enumeration.nextElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (silActual!=null)
|
if (silActual!=null)
|
||||||
|
@ -379,40 +379,14 @@ outAHere:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Looks for .dic file, and returns the dictionary descriptions.
|
/** Looks for .dic file, and returns the dictionary descriptions.
|
||||||
Also updates the definitionTags in the Definitions class.
|
Also updates the definitionTags in the Definitions class.
|
||||||
*/
|
*/
|
||||||
public String[] getDictionaryDescriptions()
|
public String[] getDictionaryDescriptions()
|
||||||
{
|
{
|
||||||
int n;
|
return FileSyllableListTree.getDictionaryDescriptions(archivo);
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(archivo + ".dic")));
|
|
||||||
SimplifiedLinkedList ll1 = new SimplifiedLinkedList(), ll2 = new SimplifiedLinkedList();
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DictionarySource.setTags(ll2.toStringArray());
|
|
||||||
return ll1.toStringArray();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy()
|
public void destroy()
|
||||||
{
|
{
|
||||||
FileSyllableListTree.closeFiles();
|
FileSyllableListTree.closeFiles();
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.*;
|
||||||
public class SimplifiedLinkedList
|
public class SimplifiedLinkedList
|
||||||
{
|
{
|
||||||
protected Link cabeza;
|
protected Link cabeza;
|
||||||
|
|
||||||
public SimplifiedLinkedList()
|
public SimplifiedLinkedList()
|
||||||
{
|
{
|
||||||
cabeza=null;
|
cabeza=null;
|
||||||
|
@ -70,6 +71,58 @@ public class SimplifiedLinkedList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** If the object is already in the list return. It is more efficient since it
|
||||||
|
assumes that the list is sorted. */
|
||||||
|
public Object getSorted(Comparable o)
|
||||||
|
{
|
||||||
|
Link currentLink = cabeza;
|
||||||
|
Object currentObject;
|
||||||
|
int comparison;
|
||||||
|
|
||||||
|
while(currentLink != null)
|
||||||
|
{
|
||||||
|
currentObject = currentLink.get();
|
||||||
|
comparison = ((Comparable) currentObject).compareTo(o);
|
||||||
|
if (comparison==0) return currentObject;
|
||||||
|
else if(comparison>0) return null;
|
||||||
|
currentLink = currentLink.next();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Does not add repetitions. */
|
||||||
|
public void addSortedUnique (Comparable o)
|
||||||
|
{
|
||||||
|
Link previous, currentLink, temp;
|
||||||
|
int comp;
|
||||||
|
|
||||||
|
if (cabeza==null || o.compareTo(cabeza.get())<0)
|
||||||
|
{
|
||||||
|
addLast(o);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (o.compareTo(cabeza.get())==0) return;
|
||||||
|
currentLink = cabeza;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
previous = currentLink;
|
||||||
|
currentLink = currentLink.next();
|
||||||
|
if (currentLink != null)
|
||||||
|
{
|
||||||
|
comp = o.compareTo(currentLink.get());
|
||||||
|
if (comp==0) return;
|
||||||
|
else if (comp<0) break;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = new Link (o);
|
||||||
|
previous.siguiente = temp;
|
||||||
|
temp.siguiente = currentLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Object getLast()
|
public Object getLast()
|
||||||
{
|
{
|
||||||
if (cabeza==null) return null;
|
if (cabeza==null) return null;
|
||||||
|
|
Loading…
Reference in a new issue