コード例 #1
0
ファイル: GenerationLoader.java プロジェクト: pk359/oryx
 private static LongSet stringToSet(CharSequence values) {
   LongSet result = new LongSet();
   for (String valueString : DelimitedDataUtils.decode(values, ',')) {
     result.add(Long.parseLong(valueString));
   }
   return result;
 }
コード例 #2
0
ファイル: TrainServlet.java プロジェクト: RedShifted/oryx
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    RDFGenerationManager generationManager = getGenerationManager();
    Generation generation = generationManager.getCurrentGeneration();
    if (generation == null) {
      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
      return;
    }

    InboundSettings inboundSettings = getInboundSettings();

    TreeBasedClassifier forest = generation.getForest();
    Map<Integer, BiMap<String, Integer>> columnToCategoryNameToIDMapping =
        generation.getColumnToCategoryNameToIDMapping();

    int totalColumns = getTotalColumns();

    for (CharSequence line : CharStreams.readLines(request.getReader())) {

      generationManager.append(line);

      String[] tokens = DelimitedDataUtils.decode(line);
      if (tokens.length != totalColumns) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
      }

      Feature target = null;
      Feature[] features = new Feature[totalColumns]; // Too big by 1 but makes math easier
      try {
        for (int col = 0; col < features.length; col++) {
          if (col == inboundSettings.getTargetColumn()) {
            target = buildFeature(col, tokens[col], columnToCategoryNameToIDMapping);
            features[col] = IgnoredFeature.INSTANCE;
          } else {
            features[col] = buildFeature(col, tokens[col], columnToCategoryNameToIDMapping);
          }
        }
      } catch (IllegalArgumentException iae) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad input line");
        return;
      }

      Preconditions.checkNotNull(target);
      Example example = new Example(target, features);

      forest.update(example);
    }
  }
コード例 #3
0
ファイル: AddServlet.java プロジェクト: RedShifted/oryx
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    KMeansGenerationManager generationManager = getGenerationManager();
    Generation generation = generationManager.getCurrentGeneration();
    if (generation == null) {
      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
      return;
    }

    for (CharSequence line : CharStreams.readLines(request.getReader())) {
      generationManager.append(line);

      RealVector vec = generation.toVector(DelimitedDataUtils.decode(line));
      if (vec == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
      }

      // TODO update the centers, along the lines of Meyerson et al.
    }
  }