【发布时间】:2013-06-25 21:35:40
【问题描述】:
我希望能够检测一个字符串是否是数学的。
数学运算结果为 true 的字符串是 "2"、"42000"、"-10"、"-55.22"、"forty-two"、"fifty six"、"negative ninety nine" 和 "negative one point seven"。
因为它不是数字和数学,所以像"negative two times seven"、"two plus two"、"3 plus two"、"two - 1" 或"2 ^ 7" 这样复杂的东西会通过。
基本上拼出数字,拼出所有格数(第一,十三,千)和单词"plus","negative","positive","minus","subtracted","from","times", "multiplied", "by", "divided", "over", "point", "to", "the", "power", "of", 和, @9876543554@, @9876p
如果函数与这些示例之一不同,则该函数将返回 false。
使用机器学习/NLP 来做到这一点是否合适?有没有比 NLP / 机器学习更好的方法?
是否有任何现有的脚本或函数可以做到这一点?
如果没有,我该如何使用 NLPTools 或 PHP NLP tools 来做到这一点?
【问题讨论】:
-
我认为这会相当困难,但这可能适用:stackoverflow.com/questions/2010663/lucene-with-php
-
另外,您可能也对此感兴趣:github.com/srgoogleguy/Mphp
-
@RobW 这很有趣。这是一个不错的计算器。但是,据我所知,它无法处理像“二加二”或“2 + 二”这样的输入。
-
它是一个运算符优先级解析器。接受并扩展它是相当容易的。这只是令牌的翻译。
-
@RobW 你能写一个答案来解释你会怎么做/怎么做吗?我对如何做到这一点感到困惑。然后我会选择它作为正确答案(如果有效)。
标签: php math numbers machine-learning nlp