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

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

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

  1. I want to go from ostuni to trapani
  2. Partenza :ostuni
  3. Arrivo :trapani
  4. but if I wrote like this:
  5. I want to go to ostuni by trapani
  6. I would like to print the same start and finish correctly ..that is
  7. Patenza :trapani
  8. Arrivo :ostuni
  9. Is this processing possible?
  10. thanks a lot for the attention! Good day

包eubot.controller;

  1. import eubot.intent.Intent;
  2. public class EubotEngine {
  3. public Intent getIntent(String stringInput) {
  4. String str1 = "";
  5. String str2 = "";
  6. Intent dictionary = null;
  7. for (String str3 : Intent.keyWord) {
  8. if (stringInput.contains(str3)) {
  9. //System.out.println("La stringa contiene : " + str3);
  10. int indice1 = stringInput.indexOf(str3) + str3.length();
  11. String splittable =
  12. stringInput.substring(indice1,stringInput.length()).trim();
  13. String splittable2[] = splittable.split(" ");
  14. int index = 0;
  15. for (String str : splittable2) {
  16. str = splittable2[index +1];
  17. str1 = str;
  18. System.out.println("Partenza :" + str1);
  19. break;
  20. }
  21. String splittable3[] = splittable.split(" ");
  22. for(String str : splittable3) {
  23. str = splittable3[index + 3];
  24. str2 = str;
  25. System.out.println("Arrivo :" + str2);
  26. break;
  27. }
  28. index++;
  29. dictionary = new Intent();
  30. dictionary.setTesto(stringInput);
  31. }
  32. }
  33. return dictionary;
  34. }
  35. }
  36. package eustema.eubot.intent;
  37. public class Intent {
  38. public String testo;
  39. public String getTesto() {
  40. return testo;
  41. }
  42. public void setTesto(String testo) {
  43. this.testo = testo;
  44. }
  45. public static String[] keyWord = { "devo andare", "voglio andare", "vorrei andare", "devo recarmi"};
  46. public static String[] parameter = { "bari", "roma", "milano","pisa","firenze","napoli","como","torino" };
  47. }
  48. package eustema.eubot.main;
  49. import java.util.Scanner;
  50. import eustema.eubot.controller.*;
  51. import eustema.eubot.intent.*;
  52. public class Test {
  53. public static void main(String[] args) {
  54. System.out.println("<<-|-|-|-|-|-|-|-|-|<<<BENVENUTO IN EuBoT>>>|-|-|-|-|-|-|-|-|->>");
  55. EubotEngine controller = new EubotEngine();
  56. Scanner input = new Scanner(System.in);
  57. String string;
  58. while (true) {
  59. string = input.nextLine();
  60. Intent intent = controller.getIntent(string);
  61. }
  62. }
  63. }
mqxuamgl

mqxuamgl1#

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

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

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

相关问题