edu.cs.ai.kreator.control
Class ModelController

java.lang.Object
  extended by edu.cs.ai.kreator.control.ModelController
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class ModelController
extends java.lang.Object
implements java.awt.event.ActionListener

This controller handles operations, which work on models: Query, Learn, script execution.

Author:
Adam Chachaj, Niklas Wulf, Matthias Thimm

Field Summary
static java.lang.String CMD_EXECUTEKREATORSCRIPTFROMFILETABINCURRENTCONSOLE
           
static java.lang.String CMD_EXECUTEKREATORSCRIPTFROMFILETABINNEWCONSOLE
           
static java.lang.String CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINCURRENTCONSOLE
           
static java.lang.String CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINNEWCONSOLE
           
static org.apache.log4j.Logger LOG
           
 
Constructor Summary
ModelController()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 KnowledgebaseFile addKnowledgeBaseAsFile(Knowledgebase toAdd, KnowledgebaseFile outputFile, KnowledgebaseWriter writer, boolean doNotOverwriteExisting, boolean doNotAddToProject, boolean doNotOpenfile)
          Adds a knowledgebase which exist in memory to a file using the specified Writer.
 void executeKreatorScriptInCurrentConsole(KreatorScript file)
          Executes a script in the currently selected console tab.
 void executeKreatorScriptInDefaultConsole(KreatorScript file)
          Executes the given script in the default console tab.
 void executeKreatorScriptInExistingConsole(KreatorScript file, KreatorConsole console)
          Executes the given script in the given console tab.
 void executeKreatorScriptInNewConsole(KreatorScript file)
          Opens a new console tab and executes the given script in it.
 SampleCollection generateData(KnowledgebaseFile inputFile, SampleCollection outputFile, int number, boolean doNotOverwriteExisting, boolean doNotAddToProject, boolean openfile)
           
 ParameterLearner getParameterLearnerById(java.lang.String id)
          Returns the knowledge base paremter-learner with the given id.
 StructureLearner getStructureLearnerById(java.lang.String id)
          Returns the knowledge base structure-learner with the given id.
 KnowledgebaseWriter getWriterById(java.lang.String id)
          Returns the knowledge base writer with the given id.
 void init()
           
 Knowledgebase learnKnowledgebaseParameter(SampleCollection sampleFile, Knowledgebase baseKb, ParameterLearner plearner)
          Learns the parameters of a given knowledge base from a sample collection.
 KnowledgebaseFile learnKnowledgebaseParameter(SampleCollection sampleFile, Knowledgebase baseKb, ParameterLearner plearner, KnowledgebaseFile outputFile, KnowledgebaseWriter writer, boolean doNotOverwriteExisting, boolean doNotAddToProject, boolean doNotOpenfile)
          Takes a given knowledgebase and learns its parameters from a sample collection and writes it to a file.
 Knowledgebase learnKnowledgebaseStructure(SampleCollection sampleFile, StructureLearner slearner)
          Learns a new knowledge base structure from a sample collection.
 KnowledgebaseFile learnKnowledgebaseStructure(SampleCollection sampleFile, StructureLearner slearner, KnowledgebaseFile outputFile, KnowledgebaseWriter writer, boolean doNotOverwriteExisting, boolean doNotAddToProject, boolean doNotOpenfile)
          Learns a new knowledge base from a sample collection and writes it to a file.
 KnowledgebaseFile learnKnowledgebaseStructureAndParameter(SampleCollection sampleFile, StructureLearner slearner, ParameterLearner plearner, KnowledgebaseFile outputFile, KnowledgebaseWriter writer, boolean doNotOverwriteExisting, boolean doNotAddToProject, boolean doNotOpenfile)
          Learns a new knowledge base from a sample collection also learns the parameter of this knowledgebase and writes it to a file.
 double queryKnowledgebase(KnowledgebaseFile kfile, java.lang.String queryStr)
          Queries a knowledge base.
 double queryKnowledgebase(KnowledgebaseFile kfile, java.lang.String queryStr, java.util.List<java.io.File> evidenceFiles)
          Queries a knowledge base.
 boolean shutDown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG

CMD_EXECUTEKREATORSCRIPTFROMFILETABINNEWCONSOLE

public static final java.lang.String CMD_EXECUTEKREATORSCRIPTFROMFILETABINNEWCONSOLE
See Also:
Constant Field Values

CMD_EXECUTEKREATORSCRIPTFROMFILETABINCURRENTCONSOLE

public static final java.lang.String CMD_EXECUTEKREATORSCRIPTFROMFILETABINCURRENTCONSOLE
See Also:
Constant Field Values

CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINNEWCONSOLE

public static final java.lang.String CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINNEWCONSOLE
See Also:
Constant Field Values

CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINCURRENTCONSOLE

public static final java.lang.String CMD_EXECUTEKREATORSCRIPTFROMPROJECTTREEINCURRENTCONSOLE
See Also:
Constant Field Values
Constructor Detail

ModelController

public ModelController()
Method Detail

init

public void init()

shutDown

public boolean shutDown()

queryKnowledgebase

public double queryKnowledgebase(KnowledgebaseFile kfile,
                                 java.lang.String queryStr,
                                 java.util.List<java.io.File> evidenceFiles)
                          throws QueryException,
                                 InvalidLanguageExpressionException,
                                 AbortedQueryException,
                                 java.io.IOException,
                                 FileNotSavedException,
                                 ParsingException
Queries a knowledge base. The knowledge base file will be saved without confirmation. All information will be posted to the console and report belonging to the current thread.

Parameters:
kfile - The knowledge base to be queried
queryStr - The query to be executed
evidenceFiles - additional evidence files
Returns:
the answer to the query
Throws:
QueryException
InvalidLanguageExpressionException
AbortedQueryException
java.io.IOException
FileNotSavedException
ParsingException

queryKnowledgebase

public double queryKnowledgebase(KnowledgebaseFile kfile,
                                 java.lang.String queryStr)
                          throws QueryException,
                                 InvalidLanguageExpressionException,
                                 AbortedQueryException,
                                 java.io.IOException,
                                 FileNotSavedException,
                                 ParsingException
Queries a knowledge base.

Parameters:
kfile - The knowledge base to be queried
queryStr - The query to be executed
Returns:
the answer to the query
Throws:
QueryException
InvalidLanguageExpressionException
AbortedQueryException
java.io.IOException
FileNotSavedException
ParsingException
See Also:
queryKnowledgebase(KnowledgebaseFile, String, List)

learnKnowledgebaseStructure

public Knowledgebase learnKnowledgebaseStructure(SampleCollection sampleFile,
                                                 StructureLearner slearner)
                                          throws ParsingException,
                                                 java.io.IOException,
                                                 AbortedLearningException,
                                                 GeneralLearningException,
                                                 FileNotSavedException
Learns a new knowledge base structure from a sample collection. The sample collection will be saved without confirmation. All information will be posted to the console and report belonging to the current thread.

Parameters:
sampleFile - a sample collection to learn from
slearner - a learner to learn with
Returns:
a knowledge base learned by the given learner from the sample collection
Throws:
GroundAtomParsingException
java.io.IOException
AbortedLearningException
GeneralLearningException
FileNotSavedException
ParsingException

learnKnowledgebaseStructure

public KnowledgebaseFile learnKnowledgebaseStructure(SampleCollection sampleFile,
                                                     StructureLearner slearner,
                                                     KnowledgebaseFile outputFile,
                                                     KnowledgebaseWriter writer,
                                                     boolean doNotOverwriteExisting,
                                                     boolean doNotAddToProject,
                                                     boolean doNotOpenfile)
                                              throws ParsingException,
                                                     AbortedLearningException,
                                                     GeneralLearningException,
                                                     java.io.IOException,
                                                     FileNotSavedException,
                                                     FileExistsException
Learns a new knowledge base from a sample collection and writes it to a file. The output file will be overwritten if overwriteExisting is set to true. Otherwise an FileExistsException will be thrown.

Parameters:
sampleFile - a sample collection to learn from
learner - a learner to learn with
outputFile - a knowledge base file to write into
writer - a writer to write the learned knowledge base into the file
doNotOverwriteExisting - if false an already existing output file will be overwritten
doNotAddToProject - if false the newly create file will be add to the project.
doNotOpenFile - if false the newly create file will be open in KReator editor pane.
Returns:
the newly learned knowledge base file
Throws:
GroundAtomParsingException
AbortedLearningException
GeneralLearningException
java.io.IOException
FileNotSavedException
FileExistsException
ParsingException
See Also:
#learnKnowledgebaseStructure(SampleCollection, Learner)

learnKnowledgebaseParameter

public Knowledgebase learnKnowledgebaseParameter(SampleCollection sampleFile,
                                                 Knowledgebase baseKb,
                                                 ParameterLearner plearner)
                                          throws AbortedLearningException,
                                                 GeneralLearningException,
                                                 FileNotSavedException,
                                                 ParsingException,
                                                 java.io.IOException
Learns the parameters of a given knowledge base from a sample collection. The sample collection will be saved without confirmation. All information will be posted to the console and report belonging to the current thread.

Parameters:
sampleFile - a sample collection to learn from
baseKb - the knowledgebase giving the structure.
plearner - a parameter learner to learn the parameters of the given knowledgebase structure.
Returns:
a knowledgebase using the learned parameters.
Throws:
AbortedLearningException
GeneralLearningException
FileNotSavedException
ParsingException
java.io.IOException

learnKnowledgebaseParameter

public KnowledgebaseFile learnKnowledgebaseParameter(SampleCollection sampleFile,
                                                     Knowledgebase baseKb,
                                                     ParameterLearner plearner,
                                                     KnowledgebaseFile outputFile,
                                                     KnowledgebaseWriter writer,
                                                     boolean doNotOverwriteExisting,
                                                     boolean doNotAddToProject,
                                                     boolean doNotOpenfile)
                                              throws ParsingException,
                                                     AbortedLearningException,
                                                     GeneralLearningException,
                                                     java.io.IOException,
                                                     FileNotSavedException,
                                                     FileExistsException
Takes a given knowledgebase and learns its parameters from a sample collection and writes it to a file. The output file will be overwritten if overwriteExisting is set to true. Otherwise an FileExistsException will be thrown.

Parameters:
sampleFile - a sample collection to learn from
baseKb - the basic knowledgebase to perform the parameter learning.
plearner - a learner which learns the parameters of the kb with the given sampleFile
outputFile - a knowledge base file to write into
writer - a writer to write the learned knowledge base into the file
doNotOverwriteExisting - if false an already existing output file will be overwritten
doNotAddToProject - if false the newly create file will be add to the project.
doNotOpenFile - if false the newly create file will be open in KReator editor pane.
Returns:
the newly learned knowledge base file
Throws:
GroundAtomParsingException
AbortedLearningException
GeneralLearningException
java.io.IOException
FileNotSavedException
FileExistsException
ParsingException
See Also:
#learnKnowledgebaseParameter(SampleCollection, Knowledgebase, Learner)

learnKnowledgebaseStructureAndParameter

public KnowledgebaseFile learnKnowledgebaseStructureAndParameter(SampleCollection sampleFile,
                                                                 StructureLearner slearner,
                                                                 ParameterLearner plearner,
                                                                 KnowledgebaseFile outputFile,
                                                                 KnowledgebaseWriter writer,
                                                                 boolean doNotOverwriteExisting,
                                                                 boolean doNotAddToProject,
                                                                 boolean doNotOpenfile)
                                                          throws ParsingException,
                                                                 AbortedLearningException,
                                                                 GeneralLearningException,
                                                                 java.io.IOException,
                                                                 FileNotSavedException,
                                                                 FileExistsException
Learns a new knowledge base from a sample collection also learns the parameter of this knowledgebase and writes it to a file. The output file will be overwritten if overwriteExisting is set to true. Otherwise an FileExistsException will be thrown.

Parameters:
sampleFile - a sample collection to learn from
slearner - a structure-learner to learn the structure of the kb.
plearner - a parameter-learner to learn the parameters of the kb.
outputFile - a knowledge base file to write into
writer - a writer to write the learned knowledge base into the file
doNotOverwriteExisting - if false an already existing output file will be overwritten
doNotAddToProject - if false the newly create file will be add to the project.
doNotOpenFile - if false the newly create file will be open in KReator editor pane.
Returns:
the newly learned knowledge base file
Throws:
GroundAtomParsingException
AbortedLearningException
GeneralLearningException
java.io.IOException
FileNotSavedException
FileExistsException
ParsingException
See Also:
learnKnowledgebaseStructure(SampleCollection, StructureLearner), learnKnowledgebaseParameter(SampleCollection, Knowledgebase, ParameterLearner)

addKnowledgeBaseAsFile

public KnowledgebaseFile addKnowledgeBaseAsFile(Knowledgebase toAdd,
                                                KnowledgebaseFile outputFile,
                                                KnowledgebaseWriter writer,
                                                boolean doNotOverwriteExisting,
                                                boolean doNotAddToProject,
                                                boolean doNotOpenfile)
                                         throws FileExistsException,
                                                FileNotSavedException
Adds a knowledgebase which exist in memory to a file using the specified Writer. There are several flags for customizing the behavior of this method.

Parameters:
toAdd - the knowledgebase which should be written to outputFile
outputFile - a datafile which should contain the content of the given knowledgebase toAdd
writer - a writer defining the transformation from memory to string representation (saved in file)
doNotOverwriteExisting - if false an already existing output file will be overwritten
doNotAddToProject - if false the newly create file will be add to the project.
doNotOpenFile - if false the newly create file will be open in KReator editor pane.
Returns:
a knowledgebase file containing the content of the knowledgebase toAdd
Throws:
FileExistsException
FileNotSavedException

generateData

public SampleCollection generateData(KnowledgebaseFile inputFile,
                                     SampleCollection outputFile,
                                     int number,
                                     boolean doNotOverwriteExisting,
                                     boolean doNotAddToProject,
                                     boolean openfile)
                              throws FileNotSavedException,
                                     ParsingException,
                                     java.io.IOException,
                                     FileExistsException
Parameters:
inputFile -
outputFile -
number -
overwriteExisting -
addToProject -
openfile -
Returns:
Throws:
FileNotSavedException
ParsingException
java.io.IOException
FileExistsException

executeKreatorScriptInNewConsole

public void executeKreatorScriptInNewConsole(KreatorScript file)
                                      throws FileNotSavedException
Opens a new console tab and executes the given script in it.

Parameters:
file - the script
Throws:
FileNotSavedException - if the file could not be saved (e.g. due to IO errors)
See Also:
executeKreatorScriptInExistingConsole(KreatorScript, KreatorConsole)

executeKreatorScriptInExistingConsole

public void executeKreatorScriptInExistingConsole(KreatorScript file,
                                                  KreatorConsole console)
                                           throws FileNotSavedException
Executes the given script in the given console tab. Saves the script without confirmation.

Parameters:
file - the script
console - the console where the script puts its output
Throws:
FileNotSavedException - if the file could not be saved (e.g. due to IO errors)

executeKreatorScriptInDefaultConsole

public void executeKreatorScriptInDefaultConsole(KreatorScript file)
                                          throws FileNotSavedException
Executes the given script in the default console tab.

Parameters:
file - the script
Throws:
FileNotSavedException - if the file could not be saved (e.g. due to IO errors)
See Also:
executeKreatorScriptInExistingConsole(KreatorScript, KreatorConsole)

executeKreatorScriptInCurrentConsole

public void executeKreatorScriptInCurrentConsole(KreatorScript file)
                                          throws FileNotSavedException
Executes a script in the currently selected console tab.

Parameters:
file -
Throws:
FileNotSavedException

getStructureLearnerById

public StructureLearner getStructureLearnerById(java.lang.String id)
                                         throws UnknownLearnerIdException
Returns the knowledge base structure-learner with the given id. Throws an UnknownLearnerIdException if no such leaner is registered.

Parameters:
id - a learner id
Returns:
the learner with the given id.
Throws:
UnknownLearnerIdException - if no learner with the given id is registered

getParameterLearnerById

public ParameterLearner getParameterLearnerById(java.lang.String id)
                                         throws UnknownLearnerIdException
Returns the knowledge base paremter-learner with the given id. Throws an UnknownLearnerIdException if no such leaner is registered.

Parameters:
id - a learner id
Returns:
the learner with the given id.
Throws:
UnknownLearnerIdException - if no learner with the given id is registered

getWriterById

public KnowledgebaseWriter getWriterById(java.lang.String id)
                                  throws UnknownKnowledgebaseWriterIdException
Returns the knowledge base writer with the given id. Throws an UnknownKnowledgebaseWriterIdException if no such writer is registered.

Parameters:
id - a writer id
Returns:
the writer with the given id.
Throws:
UnknownKnowledgebaseWriterIdException - if no writer with the given id is registered

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener