// 输入待分类问题,输出一个问题向量。
  public double[] getQuestionVector(String question) {
    // TODO Auto-generated method stub
    List<Term> parse = IndexAnalysis.parse(question);
    System.out.println(parse);
    String name = null;
    double values[] = new double[11];
    int whiteWordNum = 0;
    for (int m = 0; m < 11; m++) {
      values[m] = 0;
    }

    for (int i = 0; i < parse.size(); i++) {

      System.out.println("正在处理第" + i + "个词。");
      name = parse.get(i).getName();
      for (int j = 0; j < 10; j++) {
        int times = belongQuestionClass(name, j + 1); // times的值只可能是0和1
        values[j] = values[j] + times;
        whiteWordNum = whiteWordNum + times;
      }
    }
    if (whiteWordNum != 0) {
      for (int m = 0; m < 11; m++) {
        values[m] = values[m] / whiteWordNum;
      }
    }

    return values;
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws IOException {
    MyStaticValue.isNumRecognition = true;
    MyStaticValue.isQuantifierRecognition = false;
    MyStaticValue.userLibrary = null;
    UserDefineLibrary.insertWord("蛇药片", "n", 1000);
    UserDefineLibrary.insertWord("蛇药", "n", 1000);
    UserDefineLibrary.insertWord("鲁花", "n", 1000);
    UserDefineLibrary.insertWord("隐形", "n", 1000);
    UserDefineLibrary.insertWord("眼镜", "n", 1000);
    UserDefineLibrary.insertWord("隐形眼镜", "n", 1000);
    UserDefineLibrary.insertWord("海昌 ", "n", 1000);
    UserDefineLibrary.insertWord("美瞳", "n", 1000);

    System.out.println(IndexAnalysis.parse("海昌 润洁除蛋白隐形眼镜美瞳护理液 500+120ml"));

    System.out.println(IndexAnalysis.parse("隐形眼镜 护理"));

    System.out.println(IndexAnalysis.parse("海昌 润洁除蛋白隐形眼镜美瞳护理液 500+120ml"));

    System.out.println(IndexAnalysis.parse("季德胜蛇药片"));

    System.out.println(IndexAnalysis.parse("鲁花一级花生油"));

    System.out.println(IndexAnalysis.parse("上海虹桥机场旅游和服务都是一流的"));

    System.out.println(IndexAnalysis.parse("北京地铁"));

    UserDefineLibrary.insertWord("隐形", "attr", 1000);
    UserDefineLibrary.insertWord("眼镜", "attr", 1000);
    UserDefineLibrary.insertWord("隐形", "attr", 1000);
    UserDefineLibrary.insertWord("形眼", "attr", 1000);
    UserDefineLibrary.insertWord("隐形眼", "attr", 1000);
    System.out.println(IndexAnalysis.parse("隐形眼镜"));

    //		long start = System.currentTimeMillis() ;
    //
    //		IndexAnalysis indexAnalysis = new IndexAnalysis(new InputStreamReader(new
    // FileInputStream("/home/ansj/temp/one_day_all.txt"))) ;
    //
    //		while(indexAnalysis.next()!=null){
    //
    //		}
    //		System.out.println(System.currentTimeMillis()-start);
  }