将自然语言转换为数学方程式 [英] Converting natural language to a math equation

查看:184
本文介绍了将自然语言转换为数学方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Java的家庭自动化系统,我想添加简单的数学功能,如加法,减法,乘法,除法,根和幂。

I've got a home automation system working in Java, and I want to add simple math capabilities such as addition, subtraction, multiplication, division, roots, and powers.

在系统当前状态下,它可以将短语转换为标签,如以下示例所示:

At the system current state, it can convert a phrase into tags, as shown in the following examples:

示例:

Phrase: "what is one hundred twenty two to the power of seven"
Tagged: {QUESTION/math} {NUMBER/122} {MATH/pwr} {NUMBER/7}

示例:

Phrase: "twenty seven plus pi 3 squared"
Tagged: {NUMBER/27} {MATH/add} {NUMBER/3.14159} {MATH/multiply} {MATH/pwr} {NUMBER/2}

这个例子可以很容易地转换成这样的东西: / p>

This example could be just as easily converted to something like this:

27 + 3.14159 * 3^2

每个标记都是一个可以查询其值的对象。

Each tag is an object that can be queried for it value.

编辑:具体问题:

所以没有我需要一种方法来将该组标签作为方程式读取,并返回数值结果。作为最后的手段,我可​​以使用google或wolfram alpha,但这会慢一些,我正在努力让自动化系统完全自包含。

So now I need a way to read that group of tags as an equation, and return a numerical result. As a last resort I could use google or wolfram alpha, but that will be slower, and I'm trying to keep the automation system completely self contained.

如果你愿意的话想看看整个来源,这里是github。
请注意,我没有提交最后几个更改,因此我给出的一些数学相关的事情将不起作用。

If you would like to see the entire source, here it is in github. Note that I have not committed the last few few changes, so some of the math related things I gave examples will not work.

推荐答案

经过一些更多的googleing(我最初不知道我在做什么的名字)我找到了一个已经做过类似事情的人:

After some more googleing (I didn't know the name for what I was doing at first) I found someone who has done something similar already:

http://www.objecthunter.net/exp4j/

编辑:完成:
https://github.com/S prakle / HomeAutomation / blob / master / HomeAutomation / src / net / sprakle / homeAutomation / interpretation / module / modules / math / Math.java

这篇关于将自然语言转换为数学方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆