services/annotators/annotateLib.js
function instancesFromMatches(word, text, selector) {
  var match, ret = [];
  var re = new RegExp('\\b'+utils.escapeRegex(word)+'\\b', 'gi');
  var instance = 1;
  while ((match = re.exec(text)) !== null) {
    GLOBAL.debug(text.length, text.substring(0, 10), word, match.index, text.substr(match.index, word.length));
    // It's not in a tag
    if (text.indexOf('<' < 0) || (text.indexOf('>', match.index) > text.indexOf('<'.match.index))) {
      ret.push(annoLib.createInstance({exact: text.substr(match.index, word.length), instance: instance, selector: selector}));
    }
    instance++;
  }
  return ret;
}
function instancesFromMatches(word, text, selector) {
  var match, ret = [];
  var re = new RegExp('\\b'+utils.escapeRegex(word)+'\\b', 'gi');
  var instance = 1;
  while ((match = re.exec(text)) !== null) {
    GLOBAL.debug(text.length, text.substring(0, 10), word, match.index, text.substr(match.index, word.length));
    // It's not in a tag
    if (text.indexOf('<' < 0) || (text.indexOf('>', match.index) > text.indexOf('<'.match.index))) {
      ret.push(annoLib.createInstance({exact: text.substr(match.index, word.length), instance: instance, selector: selector}));
    }
    instance++;
  }
  return ret;
}
function instancesFromMatches ( word , text , selector ) { var match , ret = [ ] ; var re = new RegExp ( '\\b' + utils . escapeRegex ( word ) + '\\b' , 'gi' ) ; var instance = 1 ; while ( ( match = re . exec ( text ) ) !== null ) { GLOBAL . debug ( text . length , text . substring ( 0 , 10 ) , word , match . index , text . substr ( match . index , word . length ) ) ; // It's not in a tag if ( text . indexOf ( '<' < 0 ) || ( text . indexOf ( '>' , match . index ) > text . indexOf ( '<' . match . index ) ) ) { ret . push ( annoLib . createInstance ( { exact : text . substr ( match . index , word . length ) , instance : instance , selector : selector } ) ) ; } instance ++ ; } return ret ; }
convert instances of a match to instances
convert instances of a match to instances