From 3fd30dde029db506c5d7946b9bbe17ce0bf0e018 Mon Sep 17 00:00:00 2001
From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl>
Date: Mon, 20 Feb 2012 13:44:47 +0100
Subject: [PATCH] fix tagger-eval script: dont stop when denominator==0

---
 utils/tagger-eval.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/utils/tagger-eval.py b/utils/tagger-eval.py
index f12f401..9d9ab12 100755
--- a/utils/tagger-eval.py
+++ b/utils/tagger-eval.py
@@ -304,11 +304,15 @@ class TokComp:
 		"""Returns the percentage of reference tokens that have the given
 		features. By default all the reference tokens are treated as the
 		denominator. If wrt_to given, will be used as a reference feat set."""
-		if wrt_to:
-			return 100.0 * self.count_with(feats) / self.count_with(wrt_to)
+		count = self.count_with(feats)
+		if wrt_to is not None:
+			denom = self.count_with(wrt_to)
 		else:
-			return 100.0 * self.count_with(feats) / self.ref_toks
-	
+			denom = self.ref_toks
+		if denom == 0:
+			return 0.0 # what else can we do? should be labelled N/A
+		return 100.0 * count / denom
+
 	def value_of(self, metric):
 		"""Calculates the value of the given metric, being a tuple of
 		features for tokens counted as hit and features for tokens counted
-- 
GitLab