Java 编辑文本检查是否有关键字
我正在制作一个todo应用程序,我想在用户不打字的情况下实现一个自然语言检测/处理系统。主要像流行的todo应用程序(Todoist、Ticktick等)。这应该支持不同的语言,(我可以做翻译) 我尝试过获取EditText中的所有单词(在键入时),然后检查所写内容是否与strings.xml中存储的关键字匹配(这样它就可以处理转换,获得一个特定的语言strings.xml文件),但是,我认为这不是最合适的方法,这可能会对性能有害,这是一种痛苦,因为我应该写所有的同义词 我当前的代码如下所示:Java 编辑文本检查是否有关键字,java,android,nlp,artificial-intelligence,Java,Android,Nlp,Artificial Intelligence,我正在制作一个todo应用程序,我想在用户不打字的情况下实现一个自然语言检测/处理系统。主要像流行的todo应用程序(Todoist、Ticktick等)。这应该支持不同的语言,(我可以做翻译) 我尝试过获取EditText中的所有单词(在键入时),然后检查所写内容是否与strings.xml中存储的关键字匹配(这样它就可以处理转换,获得一个特定的语言strings.xml文件),但是,我认为这不是最合适的方法,这可能会对性能有害,这是一种痛苦,因为我应该写所有的同义词 我当前的代码如下所示:
et1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
//Knows that it is a word because it is separated with a space
if (s.getCharAt(s.lenght() -1) == ‘ ‘)
{
String[] words = s.split(“ “);
for(int i = 0; i < s.words(); i++)
{
if (getType(words[i]) == 0)
//Do word stuff
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
private int TYPE = 0;
private int getType(String givenword)
{
String[] words = getResources().getStringArray(R.array.words);
for(int i = 0; i < words.length(); i++)
{
//As you can see, each item of the string array has their synonym in the item itself, just divided with a “.” Ex: house.home
String[] synonyms = words[i].split(“.”);
for (int ii = 0; ii < synonyms.length(); i++)
{
if (synonyms[ii].equals(givenword)
{
return TYPE;
}
}
}
}
et1.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列、int start、int before、int count)
//知道它是一个单词,因为它是用空格隔开的
如果(s.getCharAt(s.lenght()-1)='')
{
字符串[]字=s.split(“”);
for(int i=0;i
我怎样才能正确地实现这一点?我应该使用神经网络吗?如果是,具体如何实现
注:我不希望使用外部库来添加自动补全和翻译。您有三种选择 1-如果您熟悉人工智能,您可以通过使用任何开源数据(如Kaggle)中的数据,为自然语言处理模型培训您的人工智能 2-使用数据库和正则表达式来匹配用户输入,从而生成一些逻辑 3-使用API这是首选,如果你不熟悉人工智能自然语言处理,如谷歌云翻译API,谷歌云API非常好的选择你可以找到许多有用的API