Hi Everyone,

I tried to create a Context Feature to work in my CRF.
But I always get a very wrong result.

Could someone help me to undestand where I'm wrong?

Please, see my code for the follow methods (startScanFeaturesAt, HasNext and nextFeature - I put comments above, it's very naive):

public boolean startScanFeaturesAt(DataSequence data, int prevPos, int pos) {
if(currentState < 0) {
idContextFeature = supportContext.existContextInSequence(data, pos);
hasFoundContext = (idContextFeature >= 0);
if(hasFoundContext) {
featureName = "Cxt." + ((String)data.x(pos));
currentState = supportContext.getState(idContextFeature );
previousState = (pos > 0)?data.y(pos-1):-1;
} else {
hasFoundContext = false;

// In the method startScanFeaturesAt, my intention is starting the method checking in a list if the tokens around data.x(pos) has the same context of one element in the list. If true initialize the feature and give to the current state the value stored for that context like PER, LOC or ORG in ordinal number, otherwise the feature will not initialized.

public boolean hasNext() {
return (currentState >= 0);

//hasNext is to ensure that the feature need to be generated only one time per token.

public void next(FeatureImpl f) {
setFeatureIdentifier(idContextFeature, currentState, featureName + "(" + idContextFeature + ")", f);
f.yend = currentState;
f.ystart = -1;
f.val = 1;
//Restart to startScanFeaturesAt again
currentState = -1;

//next is only used one time for each token. The f.yend is the same of the the token found around context in the list of context that I created.

** Sorry for my not much good English..

Diego Oliveira
M.Sc. Student at University Federal of Minas Gerais
Website: http://dcc.ufmg.br/~dmoliveira