Files for Programmers in Spanish
- The Java Programming Languages' "Serialized Objects" interfaces are how data-files are stored.
- Files ending with ".tmdat" are data-files created using the Object Serialization of Java Data-Set objects.
- They have been compressed using Java's ZIP/Compressed output stream class in java.io.Serializable & java.util.zip
- ".tmdat" is short for "TreeMap<String, String> data file"
- ".tsdat" is short for TreeSet<String> data file
- They can be directly loaded from disk using simple java commands into memory.
- Each .tmdat file contains a single TreeMap<Key, Value> Object (from java.util.TreeMap).
- Each .tsdat file contains a single TreeSet<Value> Object (also from java.util.*)
- They key is usually a vocabulary word, and the value is a definition or conjugation. Meaning these are dictionary data files!
- Each compressed, serialized, java.util.Tree* data-file has also been saved as a simple text-file (included here, too)
CONJUGATION_WITH_IRREG_HILITE.tmdat
CONJUGATION_WITH_IRREG_HILITE.txt
CONJUGATIONS.tmdat
CONJUGATIONS.txt
[See Sample Code 1 or Sample Code 2]
definitions.js
DEFINITIONS.tmdat
DEFINITIONS.txt
[See Sample Code]
INFINITIVES.tsdat
INFINITIVES.txt
[See Sample Code]
IRREGULAR_INFINITIVES.tsdat
IRREGULAR_INFINITIVES.txt
[See Sample Code]
MINIMALIZED_CONJUGATIONS.tmdat
MINIMALIZED_CONJUGATIONS.txt
[See Sample Code]
QUICKDEF.tmdat
QUICKDEF.txt
[Defintions from SpanishDict.com "QUICKDEF" field, but it is not a complete datafile!]
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.TreeMap;
public class Example
{
private static TreeMap<String, String> verbDefinitionsDictionary = null;
public static void initDictionary() throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream("DEFINITIONS.tmdat");
GZIPInputStream gzip = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gzip);
Object o = ois.readObject();
// NOTE: You may still need the "SupressWarnings("unchecked")" line here...
if (o instanceof TreeMap)
verbDefinitionsDictionary = (TreeMap<String, String>) o;
else
throw new IllegalStateException("Data-File has been corrupted");
fis.close();
}
public static String getDefinition(String spanishVerbInfinitiveForm)
{ return verbDefinitionsDictionary.get(spanishVerbInfinitiveForm); }
}
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.TreeMap;
// ************** NOTE:
// This Data-File / Data-Structure is not so useful.
// The "text-file" version of this data-set is the one which facilitates "reverse-conjugating" Spanish Verbs.
// THINK: If I have a word in a Spanish - and I want to identify if it is a conjugated-Spanish-Verb, one needs
// to search through the entire list of "conjugations" (of *all* Spanish verbs) to find out whether that verb
// has been conjugated.
//
// The following code would not be very useful in "reverse conjugating" (dictionary lookup) Spanish Verbs...
// AGAIN: Use the ".txt" file version instead (load to a string, and search the entire file)
public class Example
{
private static TreeMap<String, String> conjugationsDictionary = null;
public static void initChart() throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream("CONJUGATIONS.tmdat");
GZIPInputStream gzip = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gzip);
Object o = ois.readObject();
// NOTE: You may still need the "SupressWarnings("unchecked")" line here...
if (o instanceof TreeMap)
conjugationsDictionary = (TreeMap<String, String>) o;
else
throw new IllegalStateException("Data-File has been corrupted");
fis.close();
}
public static String getConjugationsChart(String spanishInfinitive)
{ return conjugationsDictionary.get(spanishInfinitive); }
}
import Torello.Java.FileRW;
import java.io.*;
public class Example
{
private static final String conjugations; static {
String temp = null;
// Torello.Java.FileRW simply loads the contents of a "text-file" (in entirety) to a String.
try { temp = FileRW.loadFileToString("CONJUGATIONS.txt"); }
catch (IOException e) { System.exit(0); } // Unrecoverable error (datafile corrupted!)
conjugations = temp;
}
/**
* Will return the infinitive form of a conujugated Spanish Verb,
* or NULL if it isn't a properly conjugated-form of a Spanish-Verb
*/
public static String getInfinitive(String word)
{
// Convert the word to lower case in Spanish
String wtlc = Torello.Spanish.Helper.toLowerCaseSpanish(word);
// GREP through the conjugations data file (stored in String: conjugations)
int pos = conjugations.indexOf(" " + wtlc + ",");
if (pos == -1) if (wtlc.charAt(wtlc.length() - 1) == 'r') pos = conjugations.indexOf("\n" + wtlc + ":");
// the post-increment (++) is for the infinitive case match.
// Specifically, the first character, in this (the infinitive) case, would be a newlinhe '\n'...
// and a '\n' character is exactly what the loop which follows is grep'ing for...
if (pos == -1) return null; else pos++;
// There *WAS* a match in the conjugations data file. - get infinitive and return
while ((conjugations.charAt(--pos) != '\n') && (pos > 0));
return conjugations.substring(pos + 1, conjugations.indexOf(':', pos + 1));
}
}
// ************** NOTE:
// This Data-File / Data-Structure ought to be used to transmit "irregular verb patterns"
// REMEMBER: Regular Verbs can be "conjugated by automatic" (SEE: NOTE about "derivable languages")
// HOWEVER: Irregular verbs need to have a "irregular notes" dictionary to fully conjugate them.
// The MINIMUM AMOUNT OF INFORMATION NEEDED TO CONJUGATE AN IRREGULAR SPANISH VERB INCLUDES:
- All 6 person-forms of the Indicative Present Tense
- All 6 person-forms of the Subjunctive Present Tense
- All 6 person-forms of the Indicative Preterite Tense
- The Stem/Root for the Future & Conditional Tenses
- The Present Participle
- The Past Participle
- The Tu (Informal) Command
- The Vos (Informal) Command
All other conjugation-forms of the remaining tenses can be derived from this information
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.TreeMap;
public class Example
{
private static TreeMap<String, String> minConjugationsDictionary = null;
public static void initChart() throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream("MINIMALIZED_CONJUGATIONS.tmdat");
GZIPInputStream gzip = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gzip);
Object o = ois.readObject();
// NOTE: You may still need the "SupressWarnings("unchecked")" line here...
if (o instanceof TreeMap)
minConjugationsDictionary = (TreeMap<String, String>) o;
else
throw new IllegalStateException("Data-File has been corrupted");
fis.close();
}
/**
* Only Irregular Spanish Verbs even need conjugation charts.
* Verb Forms for Regular Spanish Verbs can be 100% derived (by computer, javascript, etc...)
*/
public static String getParedDownConjugationsChart(String spanishInfinitive)
{ return minConjugationsDictionary.get(spanishInfinitive); }
}
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.TreeSet;
public class Example
{
private static TreeSet<String> infinitivesList = null;
public static void initList() throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream("IRREGULAR_INFINITIVES.tsdat");
GZIPInputStream gzip = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gzip);
Object o = ois.readObject();
// NOTE: You may still need the "SupressWarnings("unchecked")" line here...
if (o instanceof TreeSet)
infinitivesList = (TreeSet<String>) o;
else
throw new IllegalStateException("Data-File has been corrupted");
fis.close();
}
public static boolean isValidSpanishVerbInfinitive(String spanishWord)
{ return infinitivesList.contains(spanishWord); }
}
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.TreeSet;
public class Example
{
private static TreeSet<String> irregularVerbsList = null;
public static void initList() throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream("INFINITIVES.tsdat");
GZIPInputStream gzip = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gzip);
Object o = ois.readObject();
// NOTE: You may still need the "SupressWarnings("unchecked")" line here...
if (o instanceof TreeSet)
irregularVerbsList = (TreeSet<String>) o;
else
throw new IllegalStateException("Data-File has been corrupted");
fis.close();
}
public static boolean isIrregularVerb(String spanishVerbInfinitive)
{ return irregularVerbsList.contains(spanishVerbInfinitive); }
}