gov.sandia.cognition.framework.learning.EvaluatorBasedCognitiveModuleFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* File: EvaluatorBasedCognitiveModuleFactory.java
* Authors: Justin Basilico and Kevin R. Dixon
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright June 21, 2007, Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
* or on behalf of the U.S. Government. Export of this program may require a
* license from the United States Government. See CopyrightHistory.txt for
* complete details.
*
*
*/
package gov.sandia.cognition.framework.learning;
import gov.sandia.cognition.framework.CognitiveModel;
import gov.sandia.cognition.framework.CognitiveModule;
import gov.sandia.cognition.framework.CognitiveModuleFactory;
import gov.sandia.cognition.util.CloneableSerializable;
import gov.sandia.cognition.evaluator.StatefulEvaluator;
import gov.sandia.cognition.util.AbstractCloneableSerializable;
/**
* The EvaluatorBasedCognitiveModuleFactory class implements a factory for the
* EvaluatorBasedCognitiveModule. When a module is created the factory checks
* to see if the underlying evaluator is a StatefulEvaluator to determine if
* a normal EvaluatorBasedCognitiveModule should be created (non-stateful) or
* a StatefulEvaluatorBasedCognitiveModule should be created (stateful).
*
* @param Input type of the embedded Evaluator
* @param Output type of the embedded Evaluator
* @author Justin Basilico
* @author Kevin R. Dixon
* @since 2.0
*/
public class EvaluatorBasedCognitiveModuleFactory
extends AbstractCloneableSerializable
implements CognitiveModuleFactory
{
/** The settings for the module. */
private EvaluatorBasedCognitiveModuleSettings
settings;
/**
* Human-readable name of the module
*/
private String name;
/**
* Creates a new instance of EvaluatorBasedCognitiveModuleFactory.
*/
public EvaluatorBasedCognitiveModuleFactory()
{
this(
new EvaluatorBasedCognitiveModuleSettings(),
EvaluatorBasedCognitiveModule.DEFAULT_NAME );
}
/**
* Creates a new instance of EvaluatorBasedCognitiveModuleFactory.
*
*
* @param name
* Human-readable name of the module
* @param settings The settings for the module.
*/
public EvaluatorBasedCognitiveModuleFactory(
EvaluatorBasedCognitiveModuleSettings settings,
String name )
{
super();
this.setSettings(settings);
this.setName( name );
}
/**
* Creates a new copy of a EvaluatorBasedCognitiveModuleFactory.
*
* @param other The other EvaluatorBasedCognitiveModuleFactory to copy.
*/
public EvaluatorBasedCognitiveModuleFactory(
EvaluatorBasedCognitiveModuleFactory other)
{
this( other.getSettings().clone(), other.getName() );
}
/**
* Creates a clone of this EvaluatorBasedCognitiveModuleFactory.
*
* @return A clone of this object.
*/
@Override
public EvaluatorBasedCognitiveModuleFactory clone()
{
return new EvaluatorBasedCognitiveModuleFactory(
this);
}
/**
* {@inheritDoc}
*
* @param model {@inheritDoc}
* @return {@inheritDoc}
*/
public CognitiveModule createModule(
CognitiveModel model)
{
// Validate the state of the factory.
EvaluatorBasedCognitiveModuleSettings localSettings =
this.getSettings();
if ( localSettings == null )
{
throw new IllegalStateException("settings is null");
}
else if ( localSettings.getEvaluator() == null )
{
throw new IllegalStateException("settings evaluator is null");
}
if ( localSettings.getEvaluator() instanceof StatefulEvaluator )
{
// This is a stateful Evaluator so we have to put it in the proper
// cognitive module class.
return new StatefulEvaluatorBasedCognitiveModule(model, this.getSettings(), this.getName() );
}
else
{
// This a standard Evaluator with no state.
return new EvaluatorBasedCognitiveModule(
model, this.getSettings(), this.getName() );
}
}
/**
* Gets the settings of the module created by the factory.
*
* @return The settings of the module created by the factory.
*/
public EvaluatorBasedCognitiveModuleSettings
getSettings()
{
return settings;
}
/**
* Sets the settings of the module created by the factory.
*
* @param settings The settings of the module created by the factory.
*/
public void setSettings(
EvaluatorBasedCognitiveModuleSettings settings)
{
this.settings = settings;
}
/**
* Getter for name
* @return
* Human-readable name of the module
*/
public String getName()
{
return this.name;
}
/**
* Setter for name
* @param name
* Human-readable name of the module
*/
public void setName(
String name)
{
this.name = name;
}
}