コード例 #1
0
 private ArrayList<String> readTxtLine(String txtName) {
   ArrayList<String> qlist = new ArrayList<String>();
   try {
     FileReader fr = new FileReader(txtName);
     BufferedReader br = new BufferedReader(fr);
     String s = null;
     boolean flag = true;
     while ((s = br.readLine()) != null) {
       s = s.trim();
       s = s.replace("_SMLNUM_", "1");
       s = s.replace("_BIGNUM_", "2000");
       s = s.replace("_STOCK_", "同花顺");
       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);
   }
   return qlist;
 }
コード例 #2
0
 private void saveCsv(File f, List<String> qlist) {
   List<String> standardQ = new ArrayList<String>();
   String ret = null;
   try {
     BufferedWriter bw =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
     bw.write("No,query,ret");
     bw.newLine();
     int num = 0;
     for (String query : qlist) {
       System.out.println(String.format("########################\nQUERY: %d", ++num));
       Query q = new Query(query.toLowerCase());
       ParseResult parseRet = parser.parse(q);
       standardQ = parseRet.getStandardQueries();
       query = query.replace(",", ";");
       bw.write(num + "," + query + ",");
       for (int i = 0; i < standardQ.size(); i++) {
         ret = standardQ.get(i);
         ret = ret.replace(",", ";");
         bw.write(ret + ",");
       }
       bw.newLine();
     }
     bw.close();
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #3
0
ファイル: TestPhrase.java プロジェクト: joey0922/QueryParser
  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);
    }
  }