From a606c62cbe83f7e8cc945c3b3c864f403af9204f Mon Sep 17 00:00:00 2001 From: Keith Alcock Date: Thu, 7 Jul 2022 11:36:08 -0700 Subject: [PATCH] Rewrite without null --- main/src/main/scala/org/clulab/dynet/Eisner.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/src/main/scala/org/clulab/dynet/Eisner.scala b/main/src/main/scala/org/clulab/dynet/Eisner.scala index af3740688..fbf48bf7d 100644 --- a/main/src/main/scala/org/clulab/dynet/Eisner.scala +++ b/main/src/main/scala/org/clulab/dynet/Eisner.scala @@ -245,7 +245,8 @@ class Eisner { val relativeHead = scores(i).maxBy(_._2)._1.toInt val depMod = i + 1 val depHead = if (relativeHead == 0) 0 else depMod + relativeHead - val valid = dependencies(depMod).indices.contains(depHead) && dependencies(depMod)(depHead) != null + // lift() checks the index, and Option(_) checks for nulls. + val valid = dependencies(depMod).lift(depHead).flatMap(Option(_)).isDefined val label = if (valid) dependencies(depMod)(depHead).label else "root" val head = if(generateRelativeHeads) {