angeloskath / php-nlp-tools

Natural Language Processing Tools in PHP
Do What The F*ck You Want To Public License
749 stars 153 forks source link

Division by zero #19

Closed formigone closed 11 years ago

formigone commented 11 years ago

NlpTools\Similarity\CosineSimilarity::similarity() can divide by zero if $v1_norm or $v2_norm (or both) are equal to zero.

angeloskath commented 11 years ago

That is true.

What do you suggest to remedy this? RuntimeException ? InvalidArgumentException? return 0?

It currently returns false and issues a warning.

yooper commented 11 years ago

It should throw a UnexpectedValueException. I will work on this next.

angeloskath commented 11 years ago

UnexpectedValueException php.net Typically this happens when a function calls another function and expects the return value to be of a certain type or value not including arithmetic or buffer related errors

So I am guessing InvalidArgumentException.