コード例 #1
0
  private static List<Double> getWeightVectorForClass(
      Map<String, List<LinkedHashMap<String, Object>>> documents,
      String key,
      List<Integer> featureIndexList,
      GraphDatabaseService db) {
    List<Double> weightVector;

    Transaction tx = db.beginTx();
    // Get class id
    Long classId =
        db.findNodesByLabelAndProperty(DynamicLabel.label("Class"), "name", key)
            .iterator()
            .next()
            .getId();

    // Get weight vector for class
    List<Long> longs =
        documents
            .get(key)
            .stream()
            .map(a -> ((Integer) a.get("feature")).longValue())
            .collect(Collectors.toList());

    weightVector =
        featureIndexList
            .stream()
            .map(i -> longs.contains(i.longValue()) ? tfidf(db, i.longValue(), classId) : 0.0)
            .collect(Collectors.toList());
    tx.success();
    tx.close();
    return weightVector;
  }
コード例 #2
0
  private static List<Double> getFeatureVector(
      GraphDatabaseService db,
      GraphManager graphManager,
      String input,
      List<Integer> featureIndexList) {
    List<LinkedHashMap<String, Object>> featureFrequencyMap =
        getFeatureFrequencyMap(db, input, graphManager);

    List<Integer> longs =
        featureFrequencyMap
            .stream()
            .map(a -> (Integer) a.get("feature"))
            .collect(Collectors.toList());

    //        ((Integer) featureFrequencyMap.stream()
    //                .filter(a -> (a.get("feature")).equals(i))
    //                .collect(Collectors.toList()).get(0).get("frequency")).doubleValue()

    return featureIndexList
        .stream()
        .map(i -> longs.contains(i) ? 1.0 : 0.0)
        .collect(Collectors.toList());
  }