static {
    // 加载xml文件,初始spring容器
    ApplicationContextHelper.loadApplicationContext();

    // phraseParser配置于qphrase.xml文件
    parser = (PhraseParser) ApplicationContextHelper.getBean("phraseParser");
  }
Exemple #2
0
  public void test() {
    // 加载xml文件,初始spring容器
    ApplicationContextHelper.loadApplicationContext();

    // phraseParser配置于qphrase.xml文件
    parser = (PhraseParser) ApplicationContextHelper.getBean("phraseParser");

    List<String> qlist = new ArrayList<String>();
    String fileName = "知识类问句_file.csv";
    String queryName = "知识类问句_knowledge.txt";
    File f = new File(fileName);
    try {
      // 获取问句
      qlist = readTxtLine(queryName);
      int num = 0;
      BufferedWriter bw =
          new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
      bw.write("query,score,checkRet,thematic");
      bw.newLine();
      for (String query : qlist) {
        System.out.println(String.format("########################\nQUERY: %d", ++num));
        Query q = new Query(query.toLowerCase(), "ALL");
        ParseResult parseRet = parser.parse(q);
        saveCsv(bw, parseRet, query);
      }
      bw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #3
0
  public void test() {
    // 加载xml文件,初始spring容器
    ApplicationContextHelper.loadApplicationContext();

    ArrayList<String> qlist = new ArrayList<String>();

    try {
      // 解析问句读取
      BufferedReader br =
          new BufferedReader(new InputStreamReader(new FileInputStream("query.txt"), "utf-8"));
      String s = null;
      boolean flag = true;
      while ((s = br.readLine()) != null) {
        s = s.trim();
        if (s.startsWith("#") || s.length() == 0) {
          continue;
        } else if (s.startsWith("break")) {
          break;
        } else if (s.startsWith("/*")) {
          flag = false;
        } else if (s.endsWith("*/")) {
          flag = true;
          continue;
        }
        if (flag) {
          qlist.add(s);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }

    // phraseParser配置于qphrase.xml文件
    PhraseParser parser = (PhraseParser) ApplicationContextHelper.getBean("phraseParser");
    parser.setSplitWords("; ");

    // parser.parse(new Query("0"));
    for (String query : qlist) {
      long beforeTime = System.currentTimeMillis();
      int num = 0;
      // System.out.println(String.format("########################\nQUERY[%d]:%s",
      // ++num, query));
      Query q = new Query(query.toLowerCase());
      try {
        ParseResult pr = parser.parse(q);
        System.out.println(q.getParseResult().processLog);
      } catch (Exception e) {
        e.printStackTrace();
      }
      long afterTime = System.currentTimeMillis();
      long timeDistance = afterTime - beforeTime;
      System.out.println("time:" + timeDistance);
    }
  }
  public void test() {
    // 加载xml文件,初始spring容器
    ApplicationContextHelper.loadApplicationContext();

    // phraseParser配置于qphrase.xml文件
    parser = (PhraseParser) ApplicationContextHelper.getBean("phraseParser");

    List<String> qlist = new ArrayList<String>();
    String fileName = "file.csv";
    String queryName = "query.txt";
    File f = new File(fileName);
    // 获取问句
    qlist = readTxtLine(queryName);
    saveCsv(f, qlist);
  }