Files for Programmers in Spanish

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 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); }
}