Platform Explorer / Nuxeo Platform 9.2

Component org.nuxeo.vision.core.chains

Contributions

XML Source

<?xml version="1.0"?>
<component name="org.nuxeo.vision.core.chains">
  <extension target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent" point="operation">
    <scriptedOperation id="javascript.PictureVisionDefaultMapper">
      <inputType>Document</inputType>
      <outputType>Document</outputType>
      <category>javascript</category>
      <description></description>
      <script><![CDATA[function run(input, params) {

              var blob = Picture.GetView(input, {'viewName': 'Medium'});

              blob = VisionOp(blob, {
                'features': ['LABEL_DETECTION'],
                'maxResults': 5,
                'outputVariable': 'annotations'
              });

              var annotations = ctx.annotations;

              if (annotations===undefined || annotations.length===0) return;

              var textAndLabels = annotations[0];

              // build tag list
              var labels = textAndLabels.getClassificationLabels();

              if (labels !== undefined && labels !== null && labels.length>0) {
                  var tags = [];
                  for(var i=0;i<labels.length;i++) {
                    var label = labels[i];
                    var tag = label.getText();
                    if (tag ===undefined || tag ===null) continue;
                    tags.push(tag.replace(/[^A-Z0-9]+/ig,'+'));
                  }

                  input = Services.TagDocument(input, {'tags': tags });
              }

              return input;

        }]]></script>
    </scriptedOperation>

    <scriptedOperation id="javascript.VideoVisionDefaultMapper">
      <inputType>Document</inputType>
      <outputType>Document</outputType>
      <category>javascript</category>
      <description></description>
      <script><![CDATA[function run(input, params) {
              var storyboard = input['vid:storyboard'];
              var blobs = [];
              var index;
              var tags = [];

              for (index=0;index<storyboard.length;index++) {

                var blob = storyboard[index].content;

                VisionOp(blob, {
                  'features': ['LABEL_DETECTION'],
                  'maxResults': 5,
                  'outputVariable': 'annotations'
                });

                var annotations = ctx.annotations;

                if (annotations===undefined || annotations.length===0) return;

                // build tag list
                var textAndLabels = annotations[0];
                var labels = textAndLabels.getClassificationLabels();

                if (labels === undefined || labels === null || labels===0) continue;

                for(var j=0;j<labels.length;j++) {
                    var label = labels[j];
                    var tag = label.getText();
                    if (tag ===undefined || tag ===null) continue;
                    tags.push(tag.replace(/[^A-Z0-9]+/ig,'+'));
                    tags.push(label.getText().replace(/\s/g,'+'));
                }
              }

              input = Services.TagDocument(input, {'tags': tags });

              return input;

            }]]></script>
    </scriptedOperation>

  </extension>
</component>