I want to be able to detect if a string is mathematical.
Strings that would evaluate to true on being mathematical would be "2"
, "42000"
, "-10"
, "-55.22"
, "forty-two"
, "fifty six"
, "negative ninety nine"
, and "negative one point seven"
.
And since it is not numerical and mathematical something as complex as "negative two times seven"
, or "two plus two"
, or "3 plus two"
, or "two - 1"
, or "2 ^ 7"
would pass.
Basically spelled out numbers, spelled out possessive numbers (first, thirteenth, thousandth) and the words "plus"
, "negative"
, "positive"
, "minus"
, "subtracted"
, "from"
, "times"
, "multiplied"
, "by"
"divided"
, "over"
, "point"
, "to"
, "the"
, "power"
, "of"
, and, "and"
, "raised"
And the function would return false if it is not like one of those examples.
Is it proper to use machine learning / NLP to do this? Is there a better way to do this than NLP / Machine Learning?
Are there any existing scripts or functions that can do this?
If not, how can I do this with NLPTools or PHP NLP tools ?