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();
}
};
}
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();
}
Aggregations