Source code for mmlspark.cognitive.RecognizeText

# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in project root for information.


import sys
if sys.version >= '3':
    basestring = str

from pyspark import SparkContext, SQLContext
from pyspark.sql import DataFrame
from pyspark.ml.param.shared import *
from pyspark import keyword_only
from pyspark.ml.util import JavaMLReadable, JavaMLWritable
from mmlspark.core.serialize.java_params_patch import *
from pyspark.ml.wrapper import JavaTransformer, JavaEstimator, JavaModel
from pyspark.ml.common import inherit_doc
from mmlspark.core.schema.Utils import *

[docs]@inherit_doc class RecognizeText(ComplexParamsMixin, JavaMLReadable, JavaMLWritable, JavaTransformer): """ Args: backoffs (list): array of backoffs to use in the handler (default: [I@6ce2f9f8) concurrency (int): max number of concurrent calls (default: 1) concurrentTimeout (double): max number seconds to wait on futures if concurrency >= 1 (default: 100.0) errorCol (str): column to hold http errors (default: [self.uid]_error) imageBytes (object): bytestream of the image to use imageUrl (object): the url of the image to use maxPollingRetries (int): number of times to poll (default: 1000) mode (object): If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed outputCol (str): The name of the output column (default: [self.uid]_output) pollingDelay (int): number of milliseconds to wait between polling (default: 300) subscriptionKey (object): the API key to use timeout (double): number of seconds to wait before closing the connection (default: 60.0) url (str): Url of the service """ @keyword_only def __init__(self, backoffs=[100,500,1000], concurrency=1, concurrentTimeout=100.0, errorCol=None, imageBytes=None, imageUrl=None, maxPollingRetries=1000, mode=None, outputCol=None, pollingDelay=300, subscriptionKey=None, timeout=60.0, url=None): super(RecognizeText, self).__init__() self._java_obj = self._new_java_obj("com.microsoft.ml.spark.cognitive.RecognizeText") self.backoffs = Param(self, "backoffs", "backoffs: array of backoffs to use in the handler (default: [I@6ce2f9f8)") self._setDefault(backoffs=[100,500,1000]) self.concurrency = Param(self, "concurrency", "concurrency: max number of concurrent calls (default: 1)") self._setDefault(concurrency=1) self.concurrentTimeout = Param(self, "concurrentTimeout", "concurrentTimeout: max number seconds to wait on futures if concurrency >= 1 (default: 100.0)") self._setDefault(concurrentTimeout=100.0) self.errorCol = Param(self, "errorCol", "errorCol: column to hold http errors (default: [self.uid]_error)") self._setDefault(errorCol=self.uid + "_error") self.imageBytes = Param(self, "imageBytes", "imageBytes: bytestream of the image to use") self.imageUrl = Param(self, "imageUrl", "imageUrl: the url of the image to use") self.maxPollingRetries = Param(self, "maxPollingRetries", "maxPollingRetries: number of times to poll (default: 1000)") self._setDefault(maxPollingRetries=1000) self.mode = Param(self, "mode", "mode: If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed") self.outputCol = Param(self, "outputCol", "outputCol: The name of the output column (default: [self.uid]_output)") self._setDefault(outputCol=self.uid + "_output") self.pollingDelay = Param(self, "pollingDelay", "pollingDelay: number of milliseconds to wait between polling (default: 300)") self._setDefault(pollingDelay=300) self.subscriptionKey = Param(self, "subscriptionKey", "subscriptionKey: the API key to use") self.timeout = Param(self, "timeout", "timeout: number of seconds to wait before closing the connection (default: 60.0)") self._setDefault(timeout=60.0) self.url = Param(self, "url", "url: Url of the service") if hasattr(self, "_input_kwargs"): kwargs = self._input_kwargs else: kwargs = self.__init__._input_kwargs self.setParams(**kwargs)
[docs] @keyword_only def setParams(self, backoffs=[100,500,1000], concurrency=1, concurrentTimeout=100.0, errorCol=None, imageBytes=None, imageUrl=None, maxPollingRetries=1000, mode=None, outputCol=None, pollingDelay=300, subscriptionKey=None, timeout=60.0, url=None): """ Set the (keyword only) parameters Args: backoffs (list): array of backoffs to use in the handler (default: [I@6ce2f9f8) concurrency (int): max number of concurrent calls (default: 1) concurrentTimeout (double): max number seconds to wait on futures if concurrency >= 1 (default: 100.0) errorCol (str): column to hold http errors (default: [self.uid]_error) imageBytes (object): bytestream of the image to use imageUrl (object): the url of the image to use maxPollingRetries (int): number of times to poll (default: 1000) mode (object): If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed outputCol (str): The name of the output column (default: [self.uid]_output) pollingDelay (int): number of milliseconds to wait between polling (default: 300) subscriptionKey (object): the API key to use timeout (double): number of seconds to wait before closing the connection (default: 60.0) url (str): Url of the service """ if hasattr(self, "_input_kwargs"): kwargs = self._input_kwargs else: kwargs = self.__init__._input_kwargs return self._set(**kwargs)
[docs] def getBackoffs(self): """ Returns: list: array of backoffs to use in the handler (default: [I@6ce2f9f8) """ return self.getOrDefault(self.backoffs)
[docs] def getConcurrency(self): """ Returns: int: max number of concurrent calls (default: 1) """ return self.getOrDefault(self.concurrency)
[docs] def getConcurrentTimeout(self): """ Returns: double: max number seconds to wait on futures if concurrency >= 1 (default: 100.0) """ return self.getOrDefault(self.concurrentTimeout)
[docs] def getErrorCol(self): """ Returns: str: column to hold http errors (default: [self.uid]_error) """ return self.getOrDefault(self.errorCol)
[docs] def getImageBytes(self): """ Returns: object: bytestream of the image to use """ return self._cache.get("imageBytes", None)
[docs] def getImageUrl(self): """ Returns: object: the url of the image to use """ return self._cache.get("imageUrl", None)
[docs] def getMaxPollingRetries(self): """ Returns: int: number of times to poll (default: 1000) """ return self.getOrDefault(self.maxPollingRetries)
[docs] def getMode(self): """ Returns: object: If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed """ return self._cache.get("mode", None)
[docs] def getOutputCol(self): """ Returns: str: The name of the output column (default: [self.uid]_output) """ return self.getOrDefault(self.outputCol)
[docs] def getPollingDelay(self): """ Returns: int: number of milliseconds to wait between polling (default: 300) """ return self.getOrDefault(self.pollingDelay)
[docs] def getSubscriptionKey(self): """ Returns: object: the API key to use """ return self._cache.get("subscriptionKey", None)
[docs] def getTimeout(self): """ Returns: double: number of seconds to wait before closing the connection (default: 60.0) """ return self.getOrDefault(self.timeout)
[docs] def getUrl(self): """ Returns: str: Url of the service """ return self.getOrDefault(self.url)
[docs] def setBackoffs(self, value): """ Args: backoffs: array of backoffs to use in the handler (default: [I@6ce2f9f8) """ self._set(backoffs=value) return self
[docs] def setConcurrency(self, value): """ Args: concurrency: max number of concurrent calls (default: 1) """ self._set(concurrency=value) return self
[docs] def setConcurrentTimeout(self, value): """ Args: concurrentTimeout: max number seconds to wait on futures if concurrency >= 1 (default: 100.0) """ self._set(concurrentTimeout=value) return self
[docs] def setErrorCol(self, value): """ Args: errorCol: column to hold http errors (default: [self.uid]_error) """ self._set(errorCol=value) return self
[docs] def setImageBytes(self, value): """ Args: imageBytes: bytestream of the image to use """ self._java_obj = self._java_obj.setImageBytes(value) return self
[docs] def setImageBytesCol(self, value): """ Args: imageBytes: bytestream of the image to use """ self._java_obj = self._java_obj.setImageBytesCol(value) return self
[docs] def setImageUrl(self, value): """ Args: imageUrl: the url of the image to use """ self._java_obj = self._java_obj.setImageUrl(value) return self
[docs] def setImageUrlCol(self, value): """ Args: imageUrl: the url of the image to use """ self._java_obj = self._java_obj.setImageUrlCol(value) return self
[docs] def setMaxPollingRetries(self, value): """ Args: maxPollingRetries: number of times to poll (default: 1000) """ self._set(maxPollingRetries=value) return self
[docs] def setMode(self, value): """ Args: mode: If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed """ self._java_obj = self._java_obj.setMode(value) return self
[docs] def setModeCol(self, value): """ Args: mode: If this parameter is set to 'Printed', printed text recognition is performed. If 'Handwritten' is specified, handwriting recognition is performed """ self._java_obj = self._java_obj.setModeCol(value) return self
[docs] def setOutputCol(self, value): """ Args: outputCol: The name of the output column (default: [self.uid]_output) """ self._set(outputCol=value) return self
[docs] def setPollingDelay(self, value): """ Args: pollingDelay: number of milliseconds to wait between polling (default: 300) """ self._set(pollingDelay=value) return self
[docs] def setSubscriptionKey(self, value): """ Args: subscriptionKey: the API key to use """ self._java_obj = self._java_obj.setSubscriptionKey(value) return self
[docs] def setSubscriptionKeyCol(self, value): """ Args: subscriptionKey: the API key to use """ self._java_obj = self._java_obj.setSubscriptionKeyCol(value) return self
[docs] def setTimeout(self, value): """ Args: timeout: number of seconds to wait before closing the connection (default: 60.0) """ self._set(timeout=value) return self
[docs] def setUrl(self, value): """ Args: url: Url of the service """ self._set(url=value) return self
[docs] def setLocation(self, value): self._java_obj = self._java_obj.setLocation(value) return self
[docs] @classmethod def read(cls): """ Returns an MLReader instance for this class. """ return JavaMMLReader(cls)
[docs] @staticmethod def getJavaPackage(): """ Returns package name String. """ return "com.microsoft.ml.spark.cognitive.RecognizeText"
@staticmethod def _from_java(java_stage): module_name=RecognizeText.__module__ module_name=module_name.rsplit(".", 1)[0] + ".RecognizeText" return from_java(java_stage, module_name)