<commit_before>// -*- indent-tabs-mode: nil; js2-basic-offset: 2 -*-
/*
  QueryTranslator translates Queries into Boolean Queries in Amazon
  CloudSearch.

  Expression Syntax for Queries:
    http://docs.amazonwebservices.com/cloudsearch/latest/developerguide/Search.Requests.html#Search.ReqParams

  Expression Syntax for Boolean Queries:
    http://docs.amazonwebservices.com/cloudsearch/latest/developerguide/Search.Requests.html#Search.MatchSetExpression

  FIXME: Returns null if the given query is not supported.
         Shuold raise.
*/


function QueryTranslator() {
}

function throwTranslateError(query, context, detail) {
  var message = "";
  message += "<";
  message += query.substring(0, context.offset);
  message += "|" + query[context.offset] + "|";
  message += query.substring(context.offset + 1);
  message += ">";
  message += ": " + detail;
  throw new Error(message);
}

QueryTranslator.prototype = {
  translateIndividualTerm: function(query, context) {
    var term = '';
    for (; context.offset < query.length; context.offset++) {
      if (/[^ \+\-\|]/.test(query[context.offset])) {
        term += query[context.offset];
      } else {
        break;
      }
    }
    return context.defaultField + ":'" + term + "'";
  },
  skipSpaces: function(query, context) {
    for (; context.offset < query.length; context.offset++) {
      if (query[context.offset] != " ") {
        return;
      }
    }
  }
};

exports.QueryTranslator = QueryTranslator;<commit_msg>Move normal case code to normal level<commit_after>// -*- indent-tabs-mode: nil; js2-basic-offset: 2 -*-
/*
  QueryTranslator translates Queries into Boolean Queries in Amazon
  CloudSearch.

  Expression Syntax for Queries:
    http://docs.amazonwebservices.com/cloudsearch/latest/developerguide/Search.Requests.html#Search.ReqParams

  Expression Syntax for Boolean Queries:
    http://docs.amazonwebservices.com/cloudsearch/latest/developerguide/Search.Requests.html#Search.MatchSetExpression

  FIXME: Returns null if the given query is not supported.
         Shuold raise.
*/


function QueryTranslator() {
}

function throwTranslateError(query, context, detail) {
  var message = "";
  message += "<";
  message += query.substring(0, context.offset);
  message += "|" + query[context.offset] + "|";
  message += query.substring(context.offset + 1);
  message += ">";
  message += ": " + detail;
  throw new Error(message);
}

QueryTranslator.prototype = {
  translateIndividualTerm: function(query, context) {
    var term = '';
    for (; context.offset < query.length; context.offset++) {
      if (/[ \+\-\|]/.test(query[context.offset])) {
        break;
      }
      term += query[context.offset];
    }
    return context.defaultField + ":'" + term + "'";
  },
  skipSpaces: function(query, context) {
    for (; context.offset < query.length; context.offset++) {
      if (query[context.offset] != " ") {
        return;
      }
    }
  }
};

exports.QueryTranslator = QueryTranslator;
{'fraction_non_alphanumeric': 0.1479625918503674, 'fraction_numerical': 0.0026720106880427524, 'mean_word_length': 3.328034682080925, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6917100', 'n_tokens_mistral': 923, 'n_tokens_neox': 900, 'n_words': 186}