goete111 / factorie

Automatically exported from code.google.com/p/factorie
0 stars 0 forks source link

Bug in Chain variable #28

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

new Template2[MedicalNerLabel,MedicalNerLabel] with 
DotStatistics1[BooleanValue] {
    println("The skip chain template is invoked with value of excludeSkipEdges = " + excludeSkipEdges)
    def unroll1(label: MedicalNerLabel) = if (excludeSkipEdges) Nil else for (other <- label.chainAfter; if (other !=null && other.token.string == label.token.string)) yield Factor(label, other)
    def unroll2(label: MedicalNerLabel) = if (excludeSkipEdges) Nil else for (other <- label.chainBefore; if (other !=null && other.token.string == label.token.string)) yield Factor(other, label)
    def statistics(v:Values) = Stat(BooleanDomain.getValue(v._1.intValue == v._2.intValue))
  }

What is the expected output? What do you see instead?

I get a null pointer exception at at 
cc.factorie.ChainLink$class.chainAfter(ChainVariable.scala:77). 

I tried changing the definition of chainAfter to :

 def chainAfter = if(chain != null && _position < _chain.length) _chain.drop(_position+1)

But that still doesn't work.

What version of the product are you using? On what operating system?

I have code checked out on 04/04/12

Please provide any additional information below.

Original issue reported on code.google.com by pall...@gmail.com on 6 Jun 2012 at 3:20

GoogleCodeExporter commented 8 years ago
Actually, this is not a bug. The correct code should be :

 def unroll1(label: MedicalNerLabel) = if (excludeSkipEdges) Nil else for (other <- label.token.chainAfter; if (other !=null && other.string == label.token.string)) yield Factor(label, other.attr[MedicalNerLabel])
    def unroll2(label: MedicalNerLabel) = if (excludeSkipEdges) Nil else for (other <- label.token.chainBefore; if (other !=null && other.string == label.token.string)) yield Factor(other.attr[MedicalNerLabel], label)
    def statistics(v:Values) = Stat(BooleanDomain.getValue(v._1.intValue == v._2.intValue))

The mistake was due to the fact that I was trying to follow the example of 
chainNer2, which uses different kinds of variables. 

Original comment by pall...@gmail.com on 6 Jun 2012 at 8:00