Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix cognitive service errors #1176

Merged
merged 14 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ abstract class CognitiveServicesBaseNoHandler(val uid: String) extends Transform
assert(badColumns.isEmpty,
s"Could not find dynamic columns: $badColumns in columns: ${schema.fieldNames.toSet}")

val missingRequiredParams = this.getRequiredParams.filter {
p => this.get(p).isEmpty && this.getDefault(p).isEmpty
}
assert(missingRequiredParams.isEmpty,
s"Missing required params: ${missingRequiredParams.map(s => s.name).mkString("(", ", ", ")")}")

val dynamicParamCols = getVectorParamMap.values.toList.map(col) match {
case Nil => Seq(lit(false).alias("placeholder"))
case l => l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ class RecognizeText(override val uid: String)
"printed text recognition is performed. If 'Handwritten' is specified," +
" handwriting recognition is performed",
{
case Left(_) => true
case Right(s) => Set("Printed", "Handwritten")(s)
case Left(s) => Set("Printed", "Handwritten")(s)
case Right(_) => true
}, isURLParam = true)

def getMode: String = getScalarParam(mode)
Expand Down Expand Up @@ -361,8 +361,8 @@ class ReadImage(override val uid: String)
" so only provide a language code if you would like to force the documented" +
" to be processed as that specific language.",
{
case Left(_) => true
case Right(s) => Set("en", "nl", "fr", "de", "it", "pt", "es")(s)
case Left(s) => Set("en", "nl", "fr", "de", "it", "pt", "es")(s)
case Right(_) => true
}, isURLParam = true)

def setLanguage(v: String): this.type = setScalarParam(language, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ trait HasModelID extends HasServiceParams {
trait HasLocale extends HasServiceParams {
val locale = new ServiceParam[String](this, "locale", "Locale of the receipt. Supported" +
" locales: en-AU, en-CA, en-GB, en-IN, en-US.", {
case Left(_) => true
case Right(s) => Set("en-AU", "en-CA", "en-GB", "en-IN", "en-US")(s)
case Left(s) => Set("en-AU", "en-CA", "en-GB", "en-IN", "en-US")(s)
case Right(_) => true
}, isURLParam = true)

def setLocale(v: String): this.type = setScalarParam(locale, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ abstract class TextAnalyticsBase(override val uid: String) extends CognitiveServ
override protected def getInternalTransformer(schema: StructType): PipelineModel = {
val dynamicParamColName = DatasetExtensions.findUnusedColumnName("dynamic", schema)

val missingRequiredParams = this.getRequiredParams.filter {
p => this.get(p).isEmpty && this.getDefault(p).isEmpty
}
assert(missingRequiredParams.isEmpty,
s"Missing required params: ${missingRequiredParams.map(s => s.name).mkString("(", ", ", ")")}")

def reshapeToArray(parameterName: String): Option[(Transformer, String, String)] = {
val reshapedColName = DatasetExtensions.findUnusedColumnName(parameterName, schema)
getVectorParamMap.get(parameterName).flatMap {
Expand Down
Loading