Search in sources :

Example 1 with AmazonComprehend

use of com.amazonaws.services.comprehend.AmazonComprehend in project knime-cloud by knime.

the class BaseComprehendNodeModel method createStreamableOperator.

@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[DATA_PORT_IDX];
    final ConnectionInformationPortObjectSpec cnxSpec = (ConnectionInformationPortObjectSpec) inSpecs[CNX_PORT_IDX];
    final int textColIdx = spec.findColumnIndex(m_textColumnName.getStringValue());
    final CloudConnectionInformation cxnInfo = (CloudConnectionInformation) cnxSpec.getConnectionInformation();
    final ComprehendOperation op = getOperationInstance(cxnInfo, generateOutputTableSpec(((DataTableSpec) inSpecs[DATA_PORT_IDX])), m_textColumnName.getStringValue());
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final RowInput input = (RowInput) inputs[DATA_PORT_IDX];
            final RowOutput output = (RowOutput) outputs[0];
            final ComprehendConnection connection = new ComprehendConnection(cxnInfo);
            final AmazonComprehend comprehendClient = connection.getClient();
            op.compute(input, output, comprehendClient, textColIdx, exec, 0L);
            input.close();
            output.close();
        }
    };
}
Also used : ConnectionInformationPortObjectSpec(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) AmazonComprehend(com.amazonaws.services.comprehend.AmazonComprehend) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) RowInput(org.knime.core.node.streamable.RowInput)

Example 2 with AmazonComprehend

use of com.amazonaws.services.comprehend.AmazonComprehend in project knime-cloud by knime.

the class BaseComprehendOperation method compute.

@Override
public BufferedDataTable compute(final ExecutionContext exec, final BufferedDataTable data) throws Exception {
    // Create the data container for the output data
    final BufferedDataContainer dc = exec.createDataContainer(m_outputTableSpec);
    // table.
    if (data.size() == 0) {
        dc.close();
        return dc.getTable();
    }
    // Create stream enabled input and output ports wrapping the input data table
    // and output table.
    final DataTableRowInput in = new DataTableRowInput(data);
    final BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(dc);
    // Create a connection to the Comprehend service in the provided region
    final ComprehendConnection connection = new ComprehendConnection(m_cxnInfo);
    final AmazonComprehend comprehendClient = connection.getClient();
    // Access the input data table
    final int textColumnIdx = in.getDataTableSpec().findColumnIndex(m_textColumnName);
    // Invoke computation on the stream enabled ports
    try {
        compute(in, out, comprehendClient, textColumnIdx, exec, in.getRowCount());
    } finally {
        in.close();
        out.close();
    }
    return out.getDataTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) AmazonComprehend(com.amazonaws.services.comprehend.AmazonComprehend) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Aggregations

AmazonComprehend (com.amazonaws.services.comprehend.AmazonComprehend)2 ConnectionInformationPortObjectSpec (org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObjectSpec)1 CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 ExecutionContext (org.knime.core.node.ExecutionContext)1 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)1 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)1 RowInput (org.knime.core.node.streamable.RowInput)1 RowOutput (org.knime.core.node.streamable.RowOutput)1 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)1