【问题标题】:I have to determine from a string the starting and arrival cities我必须从字符串中确定出发城市和到达城市
【发布时间】:2017-10-31 13:56:22
【问题描述】:

我有以下代码,通过键盘输入,给我开始和到达.. 开始是根据“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);
        }
    }
}

【问题讨论】:

标签: java string input split output


【解决方案1】:

我知道这不是一个好的答案:)

通过命令式编程来解决这个问题并非易事。原因是有许多形式可以表达相同的意图。诸如填充词、同义词、倒置以及您没有想到的一般事物之类的东西可能会破坏您的算法。

当然,这取决于您想要达到的准确度。如果您很高兴这不适用于所有情况,您可以随时设置以下条件:

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

Google、Amazon 和 Apple 正在努力改进这种人机交互方式,但他们正在通过机器学习使用更数学/统计的方法。

所以,如果您正在寻找最先进的技术:

  • 主要搜索词:上下文无关语法。
  • 其他关键词:马尔可夫模型、信息抽取、向量空间模型、tf-idf

【讨论】:

  • 感谢您对我的问题的关注..我不知道这个问题..无论如何您的建议肯定会回到我身边..这是肯定的..关于我正在制作的程序..我希望能够获得自动化的机制..我必须更好地记录..非常感谢您的回答:)
猜你喜欢
  • 2020-05-14
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 2021-09-11
  • 2015-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多