public class SimplePatternRecognizer extends AbstractCloneableSerializable implements MutablePatternRecognizerLite
Constructor and Description |
---|
SimplePatternRecognizer()
Creates a new, empty instance of SimplePatternRecognizer.
|
SimplePatternRecognizer(SemanticNetwork network)
Creates a new instance of SimplePatternRecognizer.
|
SimplePatternRecognizer(SimplePatternRecognizer other)
Creates a new instance of SimplePatternRecognizer.
|
Modifier and Type | Method and Description |
---|---|
void |
addNode(SemanticLabel label)
Adds a node to the pattern recognizer.
|
protected void |
buildNodeToIDMap()
Builds the map of nodes to identifiers from the list of nodes.
|
SimplePatternRecognizer |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
Vector |
createEmptyInputVector()
Creates an empty vector to use for input.
|
java.util.Collection<SemanticLabel> |
getAllLabels()
Gets the collection of all the labels used in the recognizer.
|
double |
getAssociation(SemanticLabel from,
SemanticLabel to)
Gets the association between two nodes in the network.
|
int |
getIndex(SemanticLabel label)
Gets the index in the vector of the given label.
|
int |
getInputDimensionality()
Gets the dimensionality of the input vector to the pattern recognizer.
|
java.util.Collection<SemanticLabel> |
getInputLabels()
Gets the labels for the dimensions of the input vector.
|
SemanticNetwork |
getNetwork()
Gets the SemanticNetwork describing the structure of the pattern
recognizer.
|
int |
getOutputDimensionality()
Gets the dimensionality of the output vector to the pattern recognizer.
|
java.util.Collection<SemanticLabel> |
getOutputLabels()
Gets the labels for the dimensions of the output vector.
|
SimplePatternRecognizerState |
initialState()
Creates a new initial state for the recognizer.
|
boolean |
isInputLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if it is a label used to
provide input to the PatternRecognizerLite.
|
boolean |
isLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if the PatternRecognizer
uses it.
|
boolean |
isOutputLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if it is a label used as
output from the PatternRecognizerLite.
|
Vector |
recognize(CognitiveModuleState state,
Vector inputs)
Computes the recognition.
|
void |
removeNode(SemanticLabel label)
Removes a node and all links associated with that node from the pattern
recognizer.
|
void |
setAssociation(SemanticLabel from,
SemanticLabel to,
double weight)
Sets the association between nodes in the recognizer.
|
protected void |
setMatrix(Matrix matrix)
Sets the underlying matrix.
|
protected void |
setNodes(java.util.ArrayList<SemanticLabel> nodes)
Sets the nodes in the recognizer.
|
protected void |
setNodeToIDMap(java.util.HashMap<SemanticLabel,java.lang.Integer> nodeToIDMap)
Sets the mapping of nodes to their vector indices.
|
boolean |
trySetInputLabel(SemanticLabel label,
boolean inputLabel)
Attempts to set whether or not the given label is an input label.
|
boolean |
trySetOutputLabel(SemanticLabel label,
boolean outputLabel)
Attempts to set whether or not the given label is an output label.
|
public SimplePatternRecognizer()
public SimplePatternRecognizer(SemanticNetwork network)
network
- The network to create the pattern recognizer from.public SimplePatternRecognizer(SimplePatternRecognizer other)
other
- The SimplePatternRecognizer to copy.public SimplePatternRecognizer clone()
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface PatternRecognizerLite
clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public SimplePatternRecognizerState initialState()
initialState
in interface PatternRecognizerLite
public Vector recognize(CognitiveModuleState state, Vector inputs)
recognize
in interface PatternRecognizerLite
state
- The previous state of the module.inputs
- The vector of inputs to the recognizer.public void addNode(SemanticLabel label)
addNode
in interface MutablePatternRecognizerLite
label
- The label for the node to add.public void removeNode(SemanticLabel label)
removeNode
in interface MutablePatternRecognizerLite
label
- The label of the node to remove.public double getAssociation(SemanticLabel from, SemanticLabel to)
from
- The label the association is fromto
- The label the association is to.public void setAssociation(SemanticLabel from, SemanticLabel to, double weight)
setAssociation
in interface MutablePatternRecognizerLite
from
- The label of the node the assocation is from.to
- The label of the node the assocation is to.weight
- The weight of the association.public int getIndex(SemanticLabel label)
label
- The label to get the index of.public boolean isLabel(SemanticLabel label)
isLabel
in interface PatternRecognizerLite
label
- The label to determine if the recognizer uses.public boolean isInputLabel(SemanticLabel label)
isInputLabel
in interface PatternRecognizerLite
label
- The label to determine if it is an input label.public boolean isOutputLabel(SemanticLabel label)
isOutputLabel
in interface PatternRecognizerLite
label
- The label to determine if it is an output label.public java.util.Collection<SemanticLabel> getAllLabels()
getAllLabels
in interface PatternRecognizerLite
public boolean trySetInputLabel(SemanticLabel label, boolean inputLabel)
trySetInputLabel
in interface MutablePatternRecognizerLite
label
- The label to set whether or not it is input label.inputLabel
- Whether or not the label is an input label.public boolean trySetOutputLabel(SemanticLabel label, boolean outputLabel)
trySetOutputLabel
in interface MutablePatternRecognizerLite
label
- The label to set whether or not it is output label.outputLabel
- Whether or not the label is an output label.protected void buildNodeToIDMap()
public Vector createEmptyInputVector()
createEmptyInputVector
in interface PatternRecognizerLite
public int getInputDimensionality()
getInputDimensionality
in interface PatternRecognizerLite
public int getOutputDimensionality()
getOutputDimensionality
in interface PatternRecognizerLite
public java.util.Collection<SemanticLabel> getInputLabels()
getInputLabels
in interface PatternRecognizerLite
public java.util.Collection<SemanticLabel> getOutputLabels()
getOutputLabels
in interface PatternRecognizerLite
public SemanticNetwork getNetwork()
getNetwork
in interface PatternRecognizerLite
protected void setNodes(java.util.ArrayList<SemanticLabel> nodes)
nodes
- The new list of nodes.protected void setNodeToIDMap(java.util.HashMap<SemanticLabel,java.lang.Integer> nodeToIDMap)
nodeToIDMap
- The new mapping of nodes to vector indices.protected void setMatrix(Matrix matrix)
matrix
- The new underlying matrix.