ch.claudio.trainer
Class Model

java.lang.Object
  extended by ch.claudio.trainer.Model

public abstract class Model
extends java.lang.Object

Contains all the logic of this program. This is the logical data structure:

Sentence
A word or piece of text. It is associated with a language and the user who supplied it.
Connection
Connects two sentences/words defining whether they are the same, similar or that one is broader than the other, e.g fruit is broader than apple.
Media
Picture, sound or video that is associated with a sentence.

Note: This is not yet implemented. I'm yet undecided, if a media can be associated with only one or even several sentence. Probably several and so there is a need for a MediaConnection which performs the association. It is undisputed that a sentence can be associated with many medias e.g. an explaining picture and an audio sample of its pronunciation.

User
User defined by an identity and a trust level.

Not yet implemented.

Skill
Associates to a language the skills and permissions a user has.

Not yet implemented.

Permission
The kind of modification a user is allowed to perform.

Not yet implemented.

Version:
$Id: Model.java 299 2008-10-02 22:26:18Z claudio $
Author:
Claudio Nieder

Copyright (C) 2006-2008 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Constructor Summary
Model()
           
 
Method Summary
static void addMedia(Media media)
          Add some media (e.g.
static void addSentence(java.lang.String language, java.lang.String sentence, User user)
          Add a new sentence to the database.
static void addUsedLanguages(java.lang.String languageCode)
          Add a language to the table of languages to be used.
static void associateSentence(Sentence from, Sentence to, ConnectionType type, User user)
          Create association between sentences.
static java.util.SortedSet<Language> availableLanguages()
          Find all languages which are not yet added to the used languages list.
static boolean canLearn()
          Are there any connections between words of different languages?
static void close()
          Close the access to the database.
static void delSentence(Sentence sentence)
          Add a new sentence to the database.
static java.util.SortedSet<Language> getUsedLanguages()
          Return the languages selected for usage.
static boolean hasConnectableWords()
          Are there at least two words so that connections can be made?
static void initDB()
          Create the connection to the database.
static java.lang.String[] languageNames(java.lang.String[] langCodes)
          Map language codes to display text which contains the name in the current locale as well as in the locale of the given language (if available).
static void main(java.lang.String[] args)
          Print license.
static ConnectedWords randomConnection()
          Find a pair of words where one sentence belongs to a known language, while the other belongs to an unknown language.
 void reassociateMedia(Media media, Sentence sentence)
          Associate a different sentence to a media.
static void removeUsedLanguages(java.lang.String languageCode)
           
static java.util.List<Sentence> searchSentence(java.lang.String language, java.lang.String snippet, boolean headMatch)
          Look which sentences in a given language match the given string.
static void setLanguageKnown(java.lang.String languageCode, boolean known)
          Change the languag flag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model()
Method Detail

initDB

public static void initDB()
Create the connection to the database.


close

public static void close()
Close the access to the database.


availableLanguages

public static java.util.SortedSet<Language> availableLanguages()
Find all languages which are not yet added to the used languages list.

Returns:
languages sorted by name

getUsedLanguages

public static java.util.SortedSet<Language> getUsedLanguages()
Return the languages selected for usage.

Returns:
languages sorted by human readable name

addUsedLanguages

public static void addUsedLanguages(java.lang.String languageCode)
Add a language to the table of languages to be used.

Parameters:
languageCode -

removeUsedLanguages

public static void removeUsedLanguages(java.lang.String languageCode)
Parameters:
languageCode -

setLanguageKnown

public static void setLanguageKnown(java.lang.String languageCode,
                                    boolean known)
Change the languag flag

Parameters:
languageCode - to modify
known - new value

addSentence

public static void addSentence(java.lang.String language,
                               java.lang.String sentence,
                               User user)
Add a new sentence to the database.

Parameters:
language -
sentence -
user -

searchSentence

public static java.util.List<Sentence> searchSentence(java.lang.String language,
                                                      java.lang.String snippet,
                                                      boolean headMatch)
Look which sentences in a given language match the given string.

Parameters:
language -
snippet -
headMatch - true=snippet must match head of sentence, false=snippet must match some part of the sentence
Returns:
up to 10 sentences which match the given sentence

hasConnectableWords

public static boolean hasConnectableWords()
Are there at least two words so that connections can be made?

Returns:
true if sentence count > 1

canLearn

public static boolean canLearn()
Are there any connections between words of different languages?

Note: Currently implemented just as returning if there are any connections.

Returns:
true if there are.

associateSentence

public static void associateSentence(Sentence from,
                                     Sentence to,
                                     ConnectionType type,
                                     User user)
Create association between sentences.

Parameters:
from - "left" side of association
to - "right" side of association
type - kind of association
user - user who created it

randomConnection

public static ConnectedWords randomConnection()
Find a pair of words where one sentence belongs to a known language, while the other belongs to an unknown language.

Returns:
random connection where the first sentence is in the unknown language.

addMedia

public static void addMedia(Media media)
Add some media (e.g. audio of spoken word) to the database.

Parameters:
media -

reassociateMedia

public void reassociateMedia(Media media,
                             Sentence sentence)
Associate a different sentence to a media.

Parameters:
media -
sentence -

delSentence

public static void delSentence(Sentence sentence)
Add a new sentence to the database.

Parameters:
sentence -

languageNames

public static java.lang.String[] languageNames(java.lang.String[] langCodes)
Map language codes to display text which contains the name in the current locale as well as in the locale of the given language (if available).

Parameters:
langCodes - Array of language codes
Returns:
Array of language display names

main

public static void main(java.lang.String[] args)
Print license.

Parameters:
args - ignored