operator
Class CRFOperator.Sequence

java.lang.Object
  extended by operator.CRFOperator.Sequence
Enclosing class:
CRFOperator

 class CRFOperator.Sequence
extends java.lang.Object

In-memory representation of a CRF chain. This class supports infer (both marginal and MAP) and dumps results to file.

Author:
Ce Zhang

Field Summary
(package private)  java.util.HashMap<java.lang.Integer,java.lang.String[]> id2Label
          See ConcurrentCRFOperator#label2ID.
(package private)  java.util.HashMap<java.lang.String,java.lang.Integer> label2ID
          See ConcurrentCRFOperator#id2Label.
(package private)  java.util.HashMap<java.lang.String,java.lang.Integer> last2maxArg
          The optimal labels for the last nodes, which are used in MAP inference.
(package private)  java.util.HashSet<java.lang.String> lasts
          Set of all last nodes in this sequence.
(package private)  java.lang.String lastSignature
          The signature of the last node
(package private)  java.util.HashMap<java.lang.String,java.lang.String> next
          Map from one node to the next node in the chain.
(package private)  mln.Predicate pred
          The predicate to be labeled.
(package private)  java.util.HashMap<java.lang.String,java.lang.String> prev
          Map from one node to the previous node in the chain.
(package private)  java.util.HashSet<java.lang.String> roots
          Set of all roots nodes in this sequence.
(package private)  java.lang.String rootSignature
          The signature of the root node.
(package private)  java.util.HashMap<java.lang.String,CRFOperator.Node> signature2Node
          Map from signature to Node object.
 
Constructor Summary
CRFOperator.Sequence(mln.Predicate _p, java.lang.String _rootSignature, java.util.HashMap<java.lang.Integer,java.lang.String[]> _id2Label, java.util.HashMap<java.lang.String,java.lang.Integer> _label2ID)
          the constructor.
 
Method Summary
 void dumpAnswers(java.io.BufferedWriter bw)
          Dump answers to the given buffered writer.
 void infer()
          Infer on this sequence.
 void registerBigramFeatures(java.lang.String _prevSignature, java.lang.String _currSignature, int _prevLabel, int _currLabel, java.lang.Double _weight)
          Add a bigram feature for a node with signature _currSignature and label _currLabel.
 void registerNodeIfNotExist(java.lang.String _signature)
          Add a node in this sequence with a given signature.
 void registerUnigramFeatures(java.lang.String _currSignature, int _currLabel, java.lang.Double _weight)
          Add a unigram feature for a node with signature _currSignature and label _currLabel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pred

mln.Predicate pred
The predicate to be labeled.


rootSignature

java.lang.String rootSignature
The signature of the root node.


lastSignature

java.lang.String lastSignature
The signature of the last node


signature2Node

java.util.HashMap<java.lang.String,CRFOperator.Node> signature2Node
Map from signature to Node object.


roots

java.util.HashSet<java.lang.String> roots
Set of all roots nodes in this sequence.


lasts

java.util.HashSet<java.lang.String> lasts
Set of all last nodes in this sequence.


last2maxArg

java.util.HashMap<java.lang.String,java.lang.Integer> last2maxArg
The optimal labels for the last nodes, which are used in MAP inference.


next

java.util.HashMap<java.lang.String,java.lang.String> next
Map from one node to the next node in the chain.


prev

java.util.HashMap<java.lang.String,java.lang.String> prev
Map from one node to the previous node in the chain.


id2Label

java.util.HashMap<java.lang.Integer,java.lang.String[]> id2Label
See ConcurrentCRFOperator#label2ID.


label2ID

java.util.HashMap<java.lang.String,java.lang.Integer> label2ID
See ConcurrentCRFOperator#id2Label.

Constructor Detail

CRFOperator.Sequence

public CRFOperator.Sequence(mln.Predicate _p,
                            java.lang.String _rootSignature,
                            java.util.HashMap<java.lang.Integer,java.lang.String[]> _id2Label,
                            java.util.HashMap<java.lang.String,java.lang.Integer> _label2ID)
the constructor.

Parameters:
_p - the predicate to be labeled.
_rootSignature - the root of this sequence, which can be null (in this case, this class will find roots before infer).
_id2Label -
_label2ID -
Method Detail

registerNodeIfNotExist

public void registerNodeIfNotExist(java.lang.String _signature)
Add a node in this sequence with a given signature.

Parameters:
_signature -

registerBigramFeatures

public void registerBigramFeatures(java.lang.String _prevSignature,
                                   java.lang.String _currSignature,
                                   int _prevLabel,
                                   int _currLabel,
                                   java.lang.Double _weight)
Add a bigram feature for a node with signature _currSignature and label _currLabel.

Parameters:
_prevSignature -
_currSignature -
_prevLabel -
_currLabel -
_weight -

registerUnigramFeatures

public void registerUnigramFeatures(java.lang.String _currSignature,
                                    int _currLabel,
                                    java.lang.Double _weight)
Add a unigram feature for a node with signature _currSignature and label _currLabel.

Parameters:
_currSignature -
_currLabel -
_weight -

infer

public void infer()
Infer on this sequence.


dumpAnswers

public void dumpAnswers(java.io.BufferedWriter bw)
Dump answers to the given buffered writer. These answers are in a format that can be COPY into postgres table directly.

Parameters:
bw -