Open IT Experts for Enterprise

Zylk empresa de desarrollo de ecommerce

Name-based autocategorization or tagging in Alfresco via content rule

Cesar Capillas
Cesar Capillas

I contributed in many threads in
Alfresco Spanish Forum some time ago, and now I do it less frequently
in English Forum. I read the autottager.js
script
and I found it very smart and simple. I prepared some new
javascript code for name-based auto-tagging and categorizing under a
defined space via content rule. For example, a file named
"ECMReport.pdf" is automatically tagged as
"ecm" and
"report" when created or added, if these
tags are previously used.


autotagger2.js

var docuname       = document.name;
var docuname_lower = docuname.toLowerCase();
var tagArray = [];
var taggable_array = ["PATH:"/cm:categoryRoot/cm:taggable/*""];
for each(var tag in taggable_array){
  var nodes = search.luceneSearch(tag);
  for each(var node in nodes) {
    var x = node.name.toLowerCase();
    var y = docuname_lower.indexOf(x);
    if (y >= 0) {
      tagArray.push(node.name);
    }
  }
}
document.addTags(tagArray);
document.save();

Consider now for example that you
categorize your business documents with three main axis defined in
categories (i.e: document type, product and technology). You can
extend the main array with the three root paths for the correspoding
vocabulary (known as parent category) and then adding tags or
categories. Something like this:

autocategorizer.js

var docuname = document.name;
var docuname_lower = docuname.toLowerCase();
var catArray = [];
var category_array = ["PATH:"cm:generalclassifiable/cm:DocumentType/*"","PATH:"cm:generalclassifiable/cm:Product/*"","PATH:"cm:generalclassifiable/cm:Technology/*""];
for each(var cat in category_array){
  var nodes = search.luceneSearch(cat);
  for each(var node in nodes) {
    var x = node.name.toLowerCase();
    var y = docuname_lower.indexOf(x);
    if (y >= 0) {
      catArray.push(node);
    }
  }
}
document.addAspect("cm:generalclassifiable");
document.properties["cm:categories"] = catArray;
document.save();


Tested in Alfresco 4.2.c CE

Si te ha parecido interesante comparte este post en RRS

Facebook
LinkedIn
Telegram
Email

Leer más sobre temas relacionados

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *