Platform Explorer / Nuxeo Platform 9.2

Contribution org.nuxeo.vision.core.chains--operation

This contribution is part of XML component org.nuxeo.vision.core.chains inside nuxeo-vision-core-1.2.1.jar /OSGI-INF/default-chain-contrib.xml

Extension Point

Extension point operation of component AutomationScriptingComponent.

Contributed Items

  • <scriptedOperation id="javascript.PictureVisionDefaultMapper">
          <inputType>Document</inputType>
          <outputType>Document</outputType>
          <category>javascript</category>
          <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/>
          <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>

XML Source

<extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
    <scriptedOperation id="javascript.PictureVisionDefaultMapper">
      <inputType>Document</inputType>
      <outputType>Document</outputType>
      <category>javascript</category>
      <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/>
      <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>