示例#1
0
  protected MMObjectNode getGroupOrUserNode(Parameters a) {
    MMObjectNode groupOrUser = getNode(a.getString(PARAMETER_GROUPORUSER));
    if (groupOrUser == null)
      throw new IllegalArgumentException(
          "There is no node with id '" + a.get(PARAMETER_GROUPORUSER) + "'");

    MMObjectBuilder parent = groupOrUser.getBuilder();
    MMObjectBuilder userBuilder = Authenticate.getInstance().getUserProvider().getUserBuilder();
    if (!(parent instanceof Groups || userBuilder.getClass().isInstance(parent))) {
      throw new IllegalArgumentException(
          "Node '" + a.get(PARAMETER_GROUPORUSER) + "' does not represent a group or a user");
    }
    return groupOrUser;
  }
示例#2
0
  @Override
  public void initialize(Parameters params) throws ResourceInitializationException {
    super.initialize(params);

    if (params.contains(Constants.REPRESENTER)) {
      representer = (TextRepresenter) params.get(Constants.REPRESENTER);
    } else {
      throw new ResourceInitializationException("No text representer specified.");
    }

    if (params.contains(Constants.FIND_BEST_PARAMETERS)) {
      findBestParameters = params.getBoolean(Constants.FIND_BEST_PARAMETERS);
    } else {
      gamma = 1.0 / (double) representer.getFeatures().size();
    }

    if (params.contains(Constants.C)) {
      if (findBestParameters) {
        logger.warn("Finding best parameters. The specified C value will be ignored.");
      } else {
        c = params.getDouble(Constants.C);
      }
    }

    if (params.contains(Constants.WEIGHTS)) {
      // Parse weight specs
      weights = new TreeMap<Integer, Double>();
      for (String piece : params.getString(Constants.WEIGHTS).split(",\\s*")) {
        String[] pair = piece.split(":");
        if (pair.length != 2) {
          throw new ResourceInitializationException(
              "Invalid weight specs in " + params.getString(Constants.WEIGHTS));
        }
        try {
          int i = Integer.parseInt(pair[0]);
          double w = Double.parseDouble(pair[1]);
          weights.put(i, w);
        } catch (Exception e) {
          throw new ResourceInitializationException(
              "Invalid weight specs in " + params.getString(Constants.WEIGHTS), e);
        }
      }
    }

    if (params.contains(Constants.GAMMA)) {
      if (findBestParameters) {
        logger.warn("Finding best parameters. The specified gamma value will be ignored.");
      } else {
        gamma = params.getDouble(Constants.GAMMA);
      }
    }

    if (params.contains(Constants.SAMPLE)) {
      if (findBestParameters) {
        sample = params.getDouble(Constants.SAMPLE);
        if (sample <= 0 || sample > 1) {
          throw new ResourceInitializationException("Invalid sample value " + sample);
        }
      } else {
        logger.warn(
            "Sample value valid for parameter optimization only. Provided sample value will be ignored.");
      }
    }

    if (params.contains(Constants.NUMBER_OF_THREADS)) {
      numberOfThreads = params.getInt(Constants.NUMBER_OF_THREADS);
      if (numberOfThreads < 1) {
        throw new ResourceInitializationException(Constants.NUMBER_OF_THREADS + " must be >= 1");
      }
    }

    if (params.contains(Constants.TARGET_CLASS)) {
      targetClass = params.getString(Constants.TARGET_CLASS);
      logger.debug("Target Class: " + targetClass);
    }
  }