Advanced configuration for AI Image Tagging

Within this chapter advanced configuration options will be described.

Mappings

A mapping is a String template of the following format

<expression> -> <mam-attribute-identifier>

Which means that the result of the expression will be written to the MAM Attribute with the given identifier.

The expression can be a simple static String:

testValue -> GOOGLE_TAGS

This would write the String "testValue" into the attribute GOOGLE_TAGS.

More important: The expression can contain a json path or a velocity template which selects or transforms the JSON content received from the AI provider.

Example

Google with feature "LABEL_DETECTION" enabled will return the following JSON (maxResults is 5 here for brevity):

{
  "labelAnnotations" : [ {
    "mid" : "/m/09j5n",
    "description" : "Footwear",
    "score" : 0.9843785,
    "topicality" : 0.9843785
  }, {
    "mid" : "/m/06rrc",
    "description" : "Shoe",
    "score" : 0.9569366,
    "topicality" : 0.9569366
  }, {
    "mid" : "/m/0hgrj75",
    "description" : "Outdoor shoe",
    "score" : 0.891524,
    "topicality" : 0.891524
  }, {
    "mid" : "/m/0hgs9bq",
    "description" : "Walking shoe",
    "score" : 0.864005,
    "topicality" : 0.864005
  }, {
    "mid" : "/m/09kjlm",
    "description" : "Sneakers",
    "score" : 0.8457816,
    "topicality" : 0.8457816
  } ]
}

The default mapping which is enabled for LABEL_DETECTION is the following:

jsonPath{$.labelAnnotations[?(@.score > ${ext.ai-imagetagging.tagThreshold})]['description']} : " + "jsonPath{$.labelAnnotations[?(@.score > ${ext.ai-imagetagging.tagThreshold})]['score'])} -> ${ext.ai-imagetagging.tagTargetAttribute}

After resolving the variable placeholder it looks like this (assuming we use the default threshold of 0.90 and GOOGLE_TAGS as target attribute identifier):

jsonPath{$.labelAnnotations[?(@.score > 0.90})]['description']} : jsonPath{$.labelAnnotations[?(@.score > 0.90)]['score'])} -> GOOGLE_TAGS

This means if the score is greater than 0.90 we write the string in the format "<description> : <score>" into GOOGLE_TAGS.

As there will be more than one match the strings will be separated by a NewLine character by default.

Because of the NewLine character a "Multiline label" should be used in FSDetails for this attribute.

For testing the expression it is recommended to use an online evaluator together with a sample JSON result. For example: https://jsonpath.com/

Supported Expressions

Currently we support the following expressions:

Expression Description

jsonPath{…​}

A jsonPath expression is expected between the curly brackets. We use this JsonPath implementation: https://github.com/json-path/JsonPath

velocity{…​}

An inline Apache Velocity template is expected between the curly braces

velocityFile{…​}

The parameter key of the velocity template file is expected between the curly braces. For example: "velocityFile{${myTemplate}}" whereby "myTemplate" is another config param of type FILE

Default Mappings

Google
jsonPath{$.labelAnnotations[?(@.score > ${ext.ai-imagetagging.tagThreshold})]['description']} : jsonPath{$.labelAnnotations[?(@.score > ${ext.ai-imagetagging.tagThreshold})]['score'])} -> ${ext.ai-imagetagging.tagTargetAttribute}
Amazon Rekognition
jsonPath{$.Labels[?(@.Confidence > \${scaledTagThreshold})].Name} -> ${ext.ai-imagetagging.tagTargetAttribute}
Clarifai
jsonPath{$.outputs[?(@.model.name == '${ext.ai-imagetagging.clarifai.modelName}')].data.concepts[?(@.value > ${ext.ai-imagetagging.tagThreshold})]['name']} : "jsonPath{$.outputs[?(@.model.name == '${ext.ai-imagetagging.clarifai.modelName}')].data.concepts[?(@.value > ${ext.ai-imagetagging.tagThreshold})]['value'])} -> ${ext.ai-imagetagging.tagTargetAttribute}
MS
jsonPath{$.tags[?(@.confidence > ${ext.ai-imagetagging.tagThreshold})]['name']} : jsonPath{$.tags[?(@.confidence > ${ext.ai-imagetagging.tagThreshold})]['confidence'])} -> ${ext.ai-imagetagging.tagTargetAttribute}
Pixyle
velocity{<default-pixyle-volicity-template>} -> ${ext.ai-imagetagging.tagTargetAttribute}

The default velocity template for pixyle is checked-in at the wfl extensions git repo.

Imagga
jsonPath{$..[?(@.confidence > ${ext.ai-imagetagging.tagThreshold})]['tag']['${ext.ai-imagetagging.imagga.language}']} : jsonPath{$..[?(@.confidence > ${ext.ai-imagetagging.tagThreshold})]['confidence']} -> ${ext.ai-imagetagging.tagTargetAttribute}

Welcome to the AI Chat!

Write a prompt to get started...