【发布时间】:2026-01-23 05:30:02
【问题描述】:
我正在制作一个待办事项应用程序,我想在用户不打字时实现自然语言检测/处理系统。最喜欢流行的待办事项应用程序(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;
}
}
}
}
我怎样才能正确实施呢?我应该使用神经网络吗?如果有,具体是怎样的?
PS:我宁愿不使用外部库
【问题讨论】:
标签: java android nlp artificial-intelligence