@Override
 public void doWork() throws OperatorException {
   clearAllInnerSinks();
   inputExtender.passDataThrough();
   super.doWork();
   outputExtender.passDataThrough();
 }
  @Override
  public void doWork() throws OperatorException {
    DataTable table = null;
    if (isParameterSet(PARAMETER_LOG_NAME)) {
      String dataTableName = getParameterAsString(PARAMETER_LOG_NAME);
      table = getProcess().getDataTable(dataTableName);
    } else {
      if (getProcess().getDataTables().size() > 0) {
        table = getProcess().getDataTables().iterator().next();
        logNote("No log name was specified, using first data table found...");
      }
    }

    // check
    if (table == null) {
      throw new UserError(this, 939);
    }

    // create attributes
    List<Attribute> attributes = new ArrayList<Attribute>();
    for (int i = 0; i < table.getNumberOfColumns(); i++) {
      String name = table.getColumnName(i);
      if (table.isDate(i)) {
        attributes.add(AttributeFactory.createAttribute(name, Ontology.DATE));
      } else if (table.isDateTime(i)) {
        attributes.add(AttributeFactory.createAttribute(name, Ontology.DATE_TIME));
      } else if (table.isNumerical(i)) {
        attributes.add(AttributeFactory.createAttribute(name, Ontology.REAL));
      } else {
        attributes.add(AttributeFactory.createAttribute(name, Ontology.NOMINAL));
      }
    }

    // create table
    MemoryExampleTable exampleTable = new MemoryExampleTable(attributes);
    for (int r = 0; r < table.getNumberOfRows(); r++) {
      DataTableRow row = table.getRow(r);
      double[] data = new double[attributes.size()];
      for (int i = 0; i < table.getNumberOfColumns(); i++) {
        if (table.isDate(i)) {
          data[i] = row.getValue(i);
        } else if (table.isDateTime(i)) {
          data[i] = row.getValue(i);
        } else if (table.isNumerical(i)) {
          data[i] = row.getValue(i);
        } else {
          Attribute attribute = attributes.get(i);
          String value = table.getValueAsString(row, i);
          data[i] = attribute.getMapping().mapString(value);
        }
      }
      exampleTable.addDataRow(new DoubleArrayDataRow(data));
    }

    // create and return example set
    exampleSetOutput.deliver(exampleTable.createExampleSet());
    dummyPorts.passDataThrough();
  }
  @Override
  public void doWork() throws OperatorException {
    getProcess().clearDataTable(getParameterAsString(PARAMETER_LOG_NAME));
    if (getParameterAsBoolean(PARAMETER_DELETE_TABLE)) {
      getProcess().deleteDataTable(getParameterAsString(PARAMETER_LOG_NAME));
    }

    dummyPorts.passDataThrough();
  }
 protected PerformanceVector getPerformance(boolean cloneInput) {
   try {
     inputExtender.passDataThrough();
     executeSubprocess();
     if (isPerformanceRequired()) {
       return getPerformanceInnerSink().getData(PerformanceVector.class);
     } else {
       return getPerformanceInnerSink().getDataOrNull(PerformanceVector.class);
     }
   } catch (OperatorException e) {
     StringBuilder builder = new StringBuilder();
     builder.append(this.getName());
     builder.append(
         ": Cannot evaluate performance for current parameter combination because of an error in one of the inner operators: ");
     builder.append(e.getMessage());
     getLogger().severe(builder.toString());
     //            getLogger().severe("Cannot evaluate performance for current parameter
     // combination: " + e.getMessage());
     if (Boolean.parseBoolean(
         ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_GENERAL_DEBUGMODE)))
       e.printStackTrace();
     return null;
   }
 }
 /** Passes data from the inner sinks to the output ports. */
 protected void passResultsThrough() {
   innerSinkExtender.passDataThrough();
 }
 @Override
 public void doWork() throws OperatorException {
   dummyPorts.passDataThrough();
 }
  @Override
  public void doWork() throws OperatorException {
    String command = getParameterAsString(PARAMETER_COMMAND);
    final boolean logOut = !stdout.isConnected() && getParameterAsBoolean(PARAMETER_LOG_STDOUT);
    final boolean logErr = !stderr.isConnected() && getParameterAsBoolean(PARAMETER_LOG_STDERR);
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>(3));
    try {
      final Process process = Runtime.getRuntime().exec(command);
      final ByteArrayOutputStream stdOutBuf = new ByteArrayOutputStream();
      final ByteArrayOutputStream stdErrBuf = new ByteArrayOutputStream();

      if (stdin.isConnected()) {
        final FileObject input = stdin.getData(FileObject.class);
        new Thread(getName() + "-stdin") {
          public void run() {
            try {
              Tools.copyStreamSynchronously(input.openStream(), process.getOutputStream(), true);
            } catch (Exception e) {
              exceptions.add(e);
            }
          };
        }.start();
      }

      new Thread(getName() + "-stdout") {
        public void run() {
          try {
            if (logOut) {
              logOutput("stdout:", process.getInputStream());
            } else {
              Tools.copyStreamSynchronously(process.getInputStream(), stdOutBuf, true);
            }
          } catch (Exception e) {
            exceptions.add(e);
          }
        }
      }.start();
      new Thread(getName() + "-stderr") {
        public void run() {
          try {
            if (logErr) {
              logOutput("stderr:", process.getErrorStream());
            } else {
              Tools.copyStreamSynchronously(process.getErrorStream(), stdErrBuf, true);
            }
          } catch (Exception e) {
            exceptions.add(e);
          }
        }
      }.start();

      Tools.waitForProcess(this, process, command);
      getLogger().info("Program exited succesfully.");

      if (stdout.isConnected()) {
        stdout.deliver(new BufferedFileObject(stdOutBuf.toByteArray()));
      }
      if (stderr.isConnected()) {
        stderr.deliver(new BufferedFileObject(stdErrBuf.toByteArray()));
      }
    } catch (IOException e) {
      throw new UserError(this, e, 310, new Object[] {command, e.getMessage()});
    } finally {
      getLogger()
          .log(
              Level.WARNING,
              "com.rapidminer.operator.CommandLineOperator.errors_occurred",
              new Object[] {exceptions.size(), command});
      for (Throwable t : exceptions) {
        getLogger().log(Level.WARNING, t.toString(), t);
      }
      if (!exceptions.isEmpty()) {
        Throwable t = exceptions.get(0);
        if (t instanceof OperatorException) {
          throw (OperatorException) t;
        } else {
          throw new UserError(this, t, 310, new Object[] {command, t.getMessage()});
        }
      }
    }

    dummyPorts.passDataThrough();
  }
Пример #8
0
 @Override
 public void doWork() throws OperatorException {
   this.currentValue =
       getProcess().getMacroHandler().getMacro(getParameterAsString(PARAMETER_MACRO_NAME));
   dummyPorts.passDataThrough();
 }