我必须从一个字符串中确定出发城市和到达城市

c8ib6hqw  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(328)

我有下面的代码,通过键盘输入,给我开始和到达。。开始是根据“da”命题来决定的,而到达是根据介词“a”来决定的,所以我现在要做的是:我想得到开始和到达,即使我改变了命题的顺序。。你知道我该怎么做。。这是我得到的结果:

I want to go from ostuni to trapani

    Partenza :ostuni 

    Arrivo :trapani

    but if I wrote like this:

    I want to go to ostuni by trapani

    I would like to print the same start and finish correctly ..that is

    Patenza :trapani

    Arrivo :ostuni

    Is this processing possible?

thanks a lot for the attention! Good day

包eubot.controller;

import eubot.intent.Intent;

public class EubotEngine {
    public Intent getIntent(String stringInput) {
     String str1 = "";
     String str2 = "";
     Intent dictionary = null;

     for (String str3 : Intent.keyWord) {
     if (stringInput.contains(str3)) {

     //System.out.println("La stringa contiene : " + str3);
     int indice1 = stringInput.indexOf(str3) + str3.length();
     String splittable =
     stringInput.substring(indice1,stringInput.length()).trim();
     String splittable2[] = splittable.split(" ");
     int index = 0;
     for (String str : splittable2) {
     str = splittable2[index +1];
     str1 = str;
     System.out.println("Partenza :" + str1);
     break;
     }
     String splittable3[] = splittable.split(" ");
     for(String str : splittable3) {
     str = splittable3[index + 3];
     str2 = str;
     System.out.println("Arrivo :" + str2);
     break;
     }
     index++;
     dictionary = new Intent();
     dictionary.setTesto(stringInput);
     }
     }
     return dictionary;
     }
}

package eustema.eubot.intent;

public class Intent {

    public String testo;

    public String getTesto() {
        return testo;
    }

    public void setTesto(String testo) {
        this.testo = testo;
    }

    public static String[] keyWord = { "devo andare", "voglio andare", "vorrei andare", "devo recarmi"};

    public static String[] parameter = { "bari", "roma", "milano","pisa","firenze","napoli","como","torino" };
}
package eustema.eubot.main;

import java.util.Scanner;

import eustema.eubot.controller.*;
import eustema.eubot.intent.*;

public class Test {

    public static void main(String[] args) {

        System.out.println("<<-|-|-|-|-|-|-|-|-|<<<BENVENUTO IN EuBoT>>>|-|-|-|-|-|-|-|-|->>");
        EubotEngine controller = new EubotEngine();
        Scanner input = new Scanner(System.in);
        String string;
        while (true) {
            string = input.nextLine();
            Intent intent = controller.getIntent(string);
        }
    }
}
mqxuamgl

mqxuamgl1#

我知道这不是一个好答案:)
用命令式编程的方法来解决这一问题是非常重要的。原因是有许多形式可以表达相同的意图。诸如填充词、同义词、倒装词以及通常你没有想到的事情可能会破坏你的算法。
当然,这取决于你想要达到的准确度。如果您很高兴这种方法不适用于所有情况,您可以设置如下条件:

if (arr[index-1] == "from") setStart(arr[index]);
if (arr[index-1] == "to") setDestination(arr[index]);

谷歌、亚马逊和苹果都在努力改善这种人机交互方式,但他们通过机器学习使用了更为数学/统计的方法。
所以,如果你在寻找最先进的技术:
主要搜索词:上下文无关语法。
其他关键词:马尔可夫模型,信息抽取,向量空间模型,tf-idf

相关问题