public void execute()

in ruta-core/src/main/java/org/apache/uima/ruta/action/ConfigureAction.java [62:164]


  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
    RuleElement element = context.getElement();
    RutaBlock parent = element.getParent();
    RutaModule thisScript = parent.getScript();
    AnalysisEngine targetEngine = thisScript.getEngine(namespace);
    if (targetEngine == null) {
      throw new IllegalArgumentException("Analysis Engine with name '" + namespace
              + "' is unknown in script " + context.getParent().getName() + ".");
    }
    ConfigurationParameterDeclarations configurationParameterDeclarations = targetEngine
            .getAnalysisEngineMetaData().getConfigurationParameterDeclarations();

    Set<Entry<IStringExpression, IRutaExpression>> entrySet = parameterMap.entrySet();
    for (Entry<IStringExpression, IRutaExpression> entry : entrySet) {
      IStringExpression key = entry.getKey();
      String stringValue = key.getStringValue(context, stream);
      ConfigurationParameter configurationParameter = configurationParameterDeclarations
              .getConfigurationParameter(null, stringValue);
      if (configurationParameter != null) {
        IRutaExpression value = entry.getValue();
        String type = configurationParameter.getType();
        if (type.equals("String")) {
          if (configurationParameter.isMultiValued()) {
            if (value instanceof AbstractStringListExpression) {
              AbstractStringListExpression sle = (AbstractStringListExpression) value;
              List<String> list = sle.getList(context, stream);
              targetEngine.setConfigParameterValue(stringValue, list.toArray(new String[0]));
            } else if (value instanceof AbstractTypeListExpression) {
              AbstractTypeListExpression tle = (AbstractTypeListExpression) value;
              List<Type> list = tle.getList(context, stream);
              List<String> stringList = new ArrayList<String>();
              for (Type each : list) {
                stringList.add(each.getName());
              }
              targetEngine.setConfigParameterValue(stringValue, stringList.toArray(new String[0]));
            }
          } else {
            if (value instanceof IStringExpression) {
              IStringExpression se = (IStringExpression) value;
              String string = se.getStringValue(context, stream);
              targetEngine.setConfigParameterValue(stringValue, string);
            } else if (value instanceof ITypeExpression) {
              ITypeExpression te = (ITypeExpression) value;
              Type t = te.getType(context, stream);
              if (t != null) {
                targetEngine.setConfigParameterValue(stringValue, t.getName());
              }
            }
          }
        } else if (type.equals("Float")) {
          if (value instanceof AbstractNumberListExpression) {
            AbstractNumberListExpression nle = (AbstractNumberListExpression) value;
            List<Number> list = nle.getList(context, stream);
            List<Float> numbers = new ArrayList<Float>();
            for (Number number : list) {
              numbers.add(number.floatValue());
            }
            targetEngine.setConfigParameterValue(stringValue, numbers.toArray());
          } else {
            if (value instanceof INumberExpression) {
              INumberExpression ne = (INumberExpression) value;
              Double d = ne.getDoubleValue(context, stream);
              targetEngine.setConfigParameterValue(stringValue, d.floatValue());
            }
          }
        } else if (type.equals("Integer")) {
          if (value instanceof AbstractNumberListExpression) {
            AbstractNumberListExpression nle = (AbstractNumberListExpression) value;
            List<Number> list = nle.getList(context, stream);
            List<Integer> numbers = new ArrayList<Integer>();
            for (Number number : list) {
              numbers.add(number.intValue());
            }
            targetEngine.setConfigParameterValue(stringValue, numbers.toArray());
          } else {
            if (value instanceof INumberExpression) {
              INumberExpression ne = (INumberExpression) value;
              Integer i = ne.getIntegerValue(context, stream);
              targetEngine.setConfigParameterValue(stringValue, i);
            }
          }
        } else if (type.equals("Boolean")) {
          if (value instanceof AbstractBooleanListExpression) {
            AbstractBooleanListExpression ble = (AbstractBooleanListExpression) value;
            List<Boolean> list = ble.getList(context, stream);
            targetEngine.setConfigParameterValue(stringValue, list.toArray());
          } else {
            if (value instanceof IBooleanExpression) {
              IBooleanExpression be = (IBooleanExpression) value;
              Boolean b = be.getBooleanValue(context, stream);
              targetEngine.setConfigParameterValue(stringValue, b);
            }
          }
        }
      }
    }

    try {
      targetEngine.reconfigure();
    } catch (ResourceConfigurationException e) {
      e.printStackTrace();
    }
  }