<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/imagerecognition.js<|end_filename|>
var indico = require('../..')
  , settings = require('../../lib/settings.js')
  , should = require('chai').should()
  , fs = require('fs')
  , path = require('path')
  ;

var data = fs.readFileSync(path.join(__dirname, '..', 'base64.txt'), { encoding: 'utf8' });
console.warn = function () {};
describe('ImageRecognition', function () {
    if (settings.resolveApiKey() === false) {
      // skip test -- indico auth keys are not available
      console.warn('Api keys are now required. Skipping some tests.\nhttp://docs.indico.io/v2.0/docs/api-keys')
      return;
    }
    describe('single', function() {
      it('should get the right response format', function(done) {
        indico.imageRecognition(data, {'top_n': 3})
          .then(function(res){

            Object.keys(res).should.have.length(3);
            done();
          })
          .catch(function(err) {

            done(err);
            return;
          })

      });
    });
    describe('batch', function() {
      it('should get the right response format', function(done) {
        indico.imageRecognition([data, data], {'top_n': 3})
          .then(function(res){

            res.should.have.length(2);
            Object.keys(res[0]).should.have.length(3);
            done();
          })
          .catch(function(err) {

            done(err);
            return;
          })

      });
    });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/testsummarization.js<|end_filename|>
var indico = require('../..')
  , settings = require('../../lib/settings.js')
  , should = require('chai').should()
  ;

var data = "Most people have a story or two about teachers who really gave of themselves. But <NAME>'s most likely trumps everyone's. \
            Her teacher, <NAME>, gave her a kidney.\
            Natasha is an 8-year-old, a student at Oakfield Elementary School in Wisconsin. \
            She suffered from prune belly syndrome, a rare birth defect marked by urinary tract problems and weak abdominal muscles. \
            For the brave 2nd grader, the clock was ticking. \
            Natasha endured regular dialysis as she waited on the national donor list, desperately hoping for a kidney transplant. \
            Through it all, she attended school part-time with a bright smile.";

console.warn = function () {};
describe('TestSummarization', function () {
    if (settings.resolveApiKey() === false) {
      // skip test -- indico auth keys are not available
      console.warn('Api keys are now required. Skipping some tests.\nhttp://indico.io/docs')
      return;
    }
    describe('single', function() {
      it('should get the right response format', function(done) {
        indico.summarization(data, {top_n: 1})
          .then(function(res){
            res.length.should.eql(1);
            done();
          })
          .catch(function(err) {
            done(err);
            return;
          })

      });
    });
    describe('batch', function() {
      it('should get the right response format', function(done) {
        indico.summarization([data, data], {top_n: 3})
          .then(function(res){

            res.should.have.length(2);
            res[0].should.have.length(3);
            res[1].should.have.length(3);
            done();
          })
          .catch(function(err) {

            done(err);
            return;
          })

      });
    });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/lib/pdf.js<|end_filename|>
var fs = require('fs'),
    filetype = require("file-type"),
    request = require('request'),
    validUrl = require("valid-url"),
    Promise = require('bluebird');

// Backwards compatibility for array checking
if (typeof Array.isArray === 'undefined') {
  Array.isArray = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
  }
};

var handleString = function (pdf) {
  return new Promise(function (resolve, reject) {
    var input, options;
    if (validUrl.isWebUri(pdf)) {
      // File
      resolve({
        "pdf": pdf,
        "type": "url"
      });
    } else if (typeof pdf === 'string') {
      if (pdf.length <= 260 && fs.lstatSync(pdf).isFile()) {
        // File
        input = pdf;
        resolve({
          "pdf": input,
          "type": "file"
        });
      } else {
        // Base64 encoded pdf
        input = new Buffer(pdf, 'base64');
        resolve({
          "pdf": input,
          "type": "b64"
        });
      }
    } else {
      resolve(new Error(
        "Data input type must be url, filepath, or base64 encoded string"
      ));
    }
  });
}
var handlePdf = function (pdf) {
  return new Promise(function (resolve, reject) {
    handleString(pdf).then(function (output) {
      var input = output.pdf;
      var type = output.type;

      if (type === "url" || type === 'b64') {
        resolve(input);
      } else {
        // Type: file
        try {
          fs.readFile(input, function (err, pdf) {
            resolve(pdf.toString('base64'));
          });
        } catch (err) {
          reject(new Error("An unknown error while loading your pdf."));
        }
      }
    });
  });
}

module.exports = {
  preprocess: function (pdfs, batch) {
    return new Promise(function (resolve, reject) {
      // aggregate asynchronous results for batch reqs
      if (batch) {
        Promise.all(pdfs.map(function (pdf) {
          return handlePdf(pdf);
        })).then(function (data) {
          resolve(data);
        });
      } else {
        handlePdf(pdfs).then(function (b64) {
          resolve(b64);
        });
      }
    });
  }
}


<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/pdfs.js<|end_filename|>
var indico = require('../..')
  , settings = require('../../lib/settings.js')
  , should = require('chai').should()
  , fs = require('fs')
  , path = require('path');
  ;

var pdfFile = path.join(__dirname, '..', 'test.pdf');
var pdfUrl = "https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf";

// Silence Warnings
describe('PDF', function() {
  if (settings.resolveApiKey() === false) {
    // skip test -- indico auth keys are not available
    console.warn('Api keys are now required. Skipping some tests.\nhttp://docs.indico.io/v2.0/docs/api-keys')
    return;
  }

  describe('url support', function() {
    it('should get the right response format', function(done) {
      indico.pdfExtraction(pdfUrl)
        .then(function(res){

          console.log(res);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });

  describe('filepath', function() {
    it('should get the right response format', function(done) {
      indico.pdfExtraction(pdfFile)
        .then(function(res){
          console.log(res);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/images.js<|end_filename|>
var indico = require('../..')
  , settings = require('../../lib/settings.js')
  , should = require('chai').should()
  , image = require('../../lib/image.js')
  , lwip = require('lwip')
  , fs = require('fs')
  , path = require('path');
  ;

var data = fs.readFileSync(path.join(__dirname, '..', 'base64.txt'), { encoding: 'utf8' });
 // Silence Warnings
console.warn = function () {};
describe('BatchImage', function () {
  if (settings.resolveApiKey() === false) {
    // skip test -- indico auth keys are not available
    console.warn('Api keys are now required. Skipping some tests.\nhttp://docs.indico.io/v2.0/docs/api-keys')
    return;
  }
  describe('batchFer', function() {
    it('should get the right response format', function(done) {
      indico.fer([data])
        .then(function(res){

          res.should.have.length(1);
          Object.keys(res[0]).should.have.length(6);
          done();
        })
        .catch(function(err) {

          done(err);
          return;
        })

    });
  });

  describe('batchContentFiltering', function() {
    it('should get the right response format', function(done) {
      indico.contentFiltering([data])
        .then(function(res){

          res.should.have.length(1);
          res[0].should.be.below(.5);
          done();
        })
        .catch(function(err) {

          done(err);
          return;
        })

    });
  });

  describe('batchFacialFeatures', function() {
    it('should get the right response format', function(done) {
      indico.facialFeatures([data])
        .then(function(res){

          res.should.have.length(1);
          Object.keys(res[0]).should.have.length(48);
          done();
        })
        .catch(function(err) {

          done(err);
          return;
        })
    });
  });

  describe('batchFacialLocalization', function() {
    it('should get the right response format', function(done) {
      indico.facialLocalization([data])
        .then(function(res){

          res.should.have.length(1);
          Object.keys(res[0]).should.have.length(1);
          done();
        })
        .catch(function(err) {

          done(err);
          return;
        })
    });
  });

  describe('batchImageFeatures', function() {
    it('should get the right response format', function(done) {
      indico.imageFeatures([data])
        .then(function(res){

          res.should.have.length(1);
          Object.keys(res[0]).should.have.length(4096);
          done();
        })
        .catch(function(err) {

          done(err);
          return;
        })

    });
  });
});

describe('Image', function() {
  if (settings.resolveApiKey() === false) {
    // skip test -- indico auth keys are not available
    console.warn('Api keys are now required. Skipping some tests.\nhttp://docs.indico.io/v2.0/docs/api-keys')
    return;
  }
  describe('fer', function() {
    it('should get the right response format', function(done) {
      indico.fer(data)
        .then(function(res){

          Object.keys(res).should.have.length(6);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });

  describe('url support', function() {
    it('should get the right response format', function(done) {
      indico.fer("https://s3-us-west-2.amazonaws.com/indico-test-data/face.jpg")
        .then(function(res){

          Object.keys(res).should.have.length(6);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });


  describe('contentFiltering', function() {
    it('should get the right response format', function(done) {
      indico.contentFiltering(data)
        .then(function(res){

          res.should.be.below(.5)
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });

  describe('facialFeatures', function() {
    it('should get the right response format', function(done) {
      indico.facialFeatures(data)
        .then(function(res){

          res.should.have.length(48);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });

  describe('facialLocalization', function() {
    it('should get the right response format', function(done) {
      indico.facialLocalization(data)
        .then(function(res){

          res.should.have.length(1);
          Object.keys(res[0]).should.have.length(2);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })

    });
  });

  describe('imageFeatures', function() {
    this.timeout(5000);
    it('should get the right response format', function(done) {
      indico.imageFeatures(data)
        .then(function(res){

          res.should.have.length(4096);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });

  describe('base64', function() {
    it('should get the right response format', function(done) {
      indico.imageFeatures(data)
        .then(function(res){

          res.should.have.length(4096);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });

  describe('filepath', function() {
    it('should get the right response format', function(done) {
      var filePath = path.join(__dirname, '..', 'face1.png')
      indico.imageFeatures(filePath)
        .then(function(res){

          res.should.have.length(4096);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });

  describe('imageResizing', function() {
    it('should get the right sized image in b64', function(done) {
      image.preprocess(data, 48, false)
        .then(function(res){
          lwip.open(new Buffer(res, 'base64'), 'png', function (err, image) {
              if (err) {
                  return;
              }
              image.width().should.equal(48)
              done();
          });
      });
    });
  });

  describe('analyzeImage', function() {
    it('should get the right response format', function(done) {
      indico.analyzeImage(data, {'apis': ['imageFeatures', 'facialFeatures']})
        .then(function(res) {
          Object.keys(res).should.have.length(2);
          Object.keys(res['imageFeatures']).should.have.length(4096)
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });

  describe('batchAnalyzeImage', function() {
    it('should get the right response format', function(done) {
      indico.analyzeImage([data], {'apis': ['imageFeatures', 'facialFeatures']})
        .then(function(res){
          res['imageFeatures'].should.have.length(1)
          res['imageFeatures'][0].should.have.length(4096)
          done();
        })
        .catch(function(err){

          done(err);
          return;
        })
    });
  });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/imagetypes.js<|end_filename|>
var indico = require('../..'),
  should = require('chai').should(),
  image = require('../../lib/image.js'),
  fs = require('fs'),
  path = require('path');

// Silence Warnings
var read = function (name) {
    return fs.readFileSync(path.join(__dirname, '..', name), { encoding: 'utf8' });
};
console.warn = function () {};
describe('File types', function () {
  it('PNG', function (done) {
    var filePath = path.join(__dirname, '..', 'face1.png')
    image.preprocess(filePath, 64, true, false).then(function (result) {
        result.should.be.a('string');
        done();
    });
  });

  it('JPG', function (done) {
      var filePath = path.join(__dirname, '..', 'dog.jpg')
      image.preprocess(filePath, 64, true, false).then(function (result) {
          result.should.be.a('string');
          done();
      });
  });

  it('JPG Base64', function (done) {
      image.preprocess(read("jpgbase64.txt"), 64, true, false).then(function (result) {
          result.should.be.a('string');
          done();
      });
  });

  it('PNG Base64', function (done) {
      image.preprocess(read("base64.txt"), 64, true, false).then(function (result) {
          result.should.be.a('string');
          done();
      });
  });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/lib/image.js<|end_filename|>
var fs = require('fs'),
    filetype = require("file-type"),
    request = require('request'),
    validUrl = require("valid-url"),
    Promise = require('bluebird');

try {
  lwip = require('lwip')
} catch (err) {
  lwip = null;
}

// Backwards compatibility for array checking
if (typeof Array.isArray === 'undefined') {
  Array.isArray = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
  }
};

var handleString = function (image) {
  return new Promise(function (resolve, reject) {
    var input, options;
    if (validUrl.isWebUri(image)) {
      resolve({
        "image": image,
        "type": "url"
      });
    } else if (typeof image === 'string') {
      if (image.length <= 260 && fs.lstatSync(image).isFile()) {
        input = image;
        var arr = image.split('.');
        options = arr[arr.length - 1];
        resolve({
          "image": input,
          "options": options,
        });
      } else {
        input = new Buffer(image, 'base64');
        options = filetype(input).ext;
        resolve({
          "image": input,
          "options": options,
        });
      }
    } else {
      resolve(new Error(
        "Data input type must be array, filepath, or base64 encoded string"
      ));
    }
  });
}
var handleImage = function (image, size, min_axis) {
  return new Promise(function (resolve, reject) {
    handleString(image).then(function (output) {
      var input = output.image;
      var options = output.options;
      var type = output.type;

      if (type === "url") {
        resolve(input);
      } else {
        // Image reading and resizing
        if (!lwip) {
          reject(new Error(
            "Image processing dependency LWIP could not be loaded."
          ))
        }
        try {
          lwip.open(input, options, function (err, image) {
            var ratio = image.width() / image.height();
            if (ratio >= 10 || ratio <= .1)
              console.warn(
                "For best performance, we recommend using images of aspect ratio less than 1:10."
              );

            if (size) {
              var new_height = size,
                  new_width = size;

              if (min_axis) {
                new_height = ratio > 1 ? 1 / ratio * size : size;
                new_width = ratio > 1 ? size : ratio * size;
              }
              image.resize(new_width, new_height, function (err, image) {
                image.toBuffer('png', function (err, buffer) {
                  resolve(buffer.toString("base64"));
                });
              });
            } else {
              image.toBuffer('png', function (err, buffer) {
                resolve(buffer.toString("base64"));
              });
            }
          });
        } catch (err) {
          reject(new Error("An unknown error while loading your image."));
        }
      }
    });
  });
}

module.exports = {
  preprocess: function (images, size, min_axis, batch) {
    return new Promise(function (resolve, reject) {
      // aggregate asynchronous results for batch reqs
      if (batch) {
        Promise.all(images.map(function (image) {
          return handleImage(image, size, min_axis);
        })).then(function (data) {
          resolve(data);
        });
      } else {
        handleImage(images, size).then(function (b64) {
          resolve(b64);
        });
      }
    });
  }
}


<|start_filename|>Server/Node Backend/node_modules/indico.io/test/integration/text.js<|end_filename|>
var indico = require('../..')
  , settings = require('../../lib/settings.js')
  , should = require('chai').should()
  , expect = require('chai').expect
  ;

var compare_by_confidence = function(a, b) {
  if (a['confidence'] < b['confidence']) {
     return 1;
  }
  if (a['confidence'] > b['confidence']) {
     return -1;
  }
  // a must be equal to b
  return 0;
}

describe('Text', function() {
  this.timeout(10000);

  if (settings.resolveApiKey() === false) {
    // skip test -- indico auth keys are not available
    console.warn('Api keys are now required. Skipping some tests.\nhttp://indico.io/docs')
    return;
  }

  describe('emotion', function() {
    it('should get the right response format', function(done) {

      indico.emotion("I did it. I got into Grad School. Not just any program, but a GREAT program. :-)")
        .then(function(res) {
          Object.keys(res).should.have.length(5);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  });

  describe('personality', function() {
    it('should get the right response format', function(done) {

      indico.personality("I love my friends!")
        .then(function(res) {
          Object.keys(res).should.have.length(4);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  });

  describe('personas', function() {
    it('should get the right response format', function(done) {

      indico.personas("I love my friends!")
        .then(function(res) {
          Object.keys(res).should.have.length(16);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  });

  describe('people', function() {
    it('should get the right response format', function(done) {

      var text = '<NAME> is scheduled to give a talk next Saturday at the White House.';
      indico.people(text)
        .then(function(res) {
          res.sort(compare_by_confidence)
          res[0]['text'].should.contain('<NAME>')
          indico.people(text, {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0]['confidence'] - resv1[0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('people', function() {
    it('should get the right response format', function(done) {

      var text = '<NAME> is scheduled to give a talk next Saturday at the White House.';
      indico.people([text, text])
        .then(function(res) {
          res[0].sort(compare_by_confidence)
          res[0][0]['text'].should.contain('<NAME>')
          indico.people([text, text], {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0][0]['confidence'] - resv1[0][0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('places', function() {
    it('should get the right response format', function(done) {

      var text = 'Lets all go to Virginia beach before it gets too cold to wander outside.';
      indico.places(text)
        .then(function(res) {
          res.sort(compare_by_confidence)
          res[0]['text'].should.contain('Virginia')
           indico.places(text, {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0]['confidence'] - resv1[0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('places', function() {
    it('should get the right response format', function(done) {

      var text = 'Lets all go to Virginia beach before it gets too cold to wander outside.';
      indico.places([text, text])
        .then(function(res) {
          res[0].sort(compare_by_confidence)
          res[0][0]['text'].should.contain('Virginia')
          indico.places([text, text], {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0][0]['confidence'] - resv1[0][0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('organizations', function() {
    it('should get the right response format', function(done) {

      var text = "A year ago, the New York Times published confidential comments about ISIS' ideology by Major General <NAME>, then U.S. Special Operations commander in the Middle East.";
      indico.organizations(text)
        .then(function(res) {
          res.sort(compare_by_confidence)
          res[0]['text'].should.contain('U.S. Special Operations')
          indico.organizations(text, {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0]['confidence'] - resv1[0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('organizations', function() {
    it('should get the right response format', function(done) {

      var text = "A year ago, the New York Times published confidential comments about ISIS' ideology by Major General <NAME>, then U.S. Special Operations commander in the Middle East.";
      indico.organizations([text, text])
        .then(function(res) {
          res[0].sort(compare_by_confidence)
          res[0][0]['text'].should.contain('U.S. Special Operations')
          indico.organizations([text, text], {"version": 1})
            .then(function(resv1) {
              resv1.sort(compare_by_confidence)
              expect(Math.abs(res[0][0]['confidence'] - resv1[0][0]['confidence']) > .00001)
              done();
            })
            .catch(function(err){
              done(err);
              return;
            });
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('relevance', function() {
    it('should get the right response format', function(done) {

      indico.relevance('president', 'president')
        .then(function(res) {
          res.should.be.above(0.5);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('relevance', function() {
    it('should get the right response format', function(done) {

      indico.relevance(['president', '<NAME>'], ['president', 'prime minister'])
        .then(function(res) {
          res[0][0].should.be.above(0.5);
          res.should.have.length(2);
          res[0].should.have.length(2);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('text features', function() {
    it('should get the right response format', function(done) {

      indico.textFeatures('Queen of England')
        .then(function(res) {
          res.should.have.length(300);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })

  describe('text features batch', function() {
    it('should get the right response format', function(done) {

      indico.textFeatures(['Queen of England', 'Prime Minister of Canada'])
        .then(function(res) {
          res.should.have.length(2);
          res[0].should.have.length(300);
          res[1].should.have.length(300);
          done();
        })
        .catch(function(err){
            done(err);
            return;
        });
    });
  })


  describe('sentiment', function() {
    it('should get the right response format', function(done) {
      indico.sentiment('Really enjoyed the movie.')
        .then(function(res) {
          res.should.be.above(0.5);
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('twitter_engagement', function() {
    it('should get the right response format', function(done) {
      indico.twitterEngagement('#Breaking rt if you <3 pic.twitter.com @Startup')
        .then(function(res) {
          res.should.be.above(0.5);
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('sentimentHQ', function() {
    it('should get the right response format', function(done) {
      indico.sentimentHQ('Really enjoyed the movie.')
        .then(function(res) {

          res.should.be.above(0.5);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('language', function() {
    it('should get the right response format', function(done) {
      indico.language('Quis custodiet ipsos custodes')
        .then(function(res) {
          // number of languages
          Object.keys(res).should.have.length(33)
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('textTags', function() {
    it('should get the right response format', function(done) {
      indico.textTags('Really enjoyed the movie.')
        .then(function(res){
          // number of categories
          Object.keys(res).should.have.length(111)
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });


  describe('analyzeText', function() {
    it('should get results from multiple text apis', function(done) {

      var example = 'Really enjoyed the movie.';

      indico.analyzeText(example, {'apis': ['sentiment', 'textTags']})
        .then(function(res){
          Object.keys(res).should.have.length(2);
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('Keyword Arguments Function', function() {
    it('Keyword arguments should function when passed into config', function(done) {
      indico.textTags('Really enjoyed the movie.', {'top_n': 5})
        .then(function(res){

          // number of categories
          Object.keys(res).should.have.length(5);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('keywords', function() {
    it('should get the right response format', function(done) {
      indico.keywords("A working api is key to our young company's success", {top_n: 3})
        .then(function(res){

          // number of keywords
          Object.keys(res).should.have.length(3);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('keywords', function() {
    it('should get the right response format with specified language', function(done) {
      text = "La semaine suivante, il remporte sa premiere victoire, dans la descente de Val Gardena en Italie, près de cinq ans après la dernière victoire en Coupe du monde d'un Français dans cette discipline, avec le succès de <NAME> à Kvitfjell."
      indico.keywords(text, {top_n: 3, language: 'French'})
        .then(function(res){

          // number of keywords
          Object.keys(res).should.have.length(3)
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('keywords', function() {
    it('should get the right response format with auto detect language', function(done) {
      text = "La semaine suivante, il remporte sa premiere victoire, dans la descente de <NAME> en Italie, près de cinq ans après la dernière victoire en Coupe du monde d'un Français dans cette discipline, avec le succès de <NAME> à Kvitfjell."
      indico.keywords(text, {top_n: 3, language: 'detect'})
        .then(function(res){

          // number of keywords
          Object.keys(res).should.have.length(3);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });
});

describe('BatchText', function() {
  if (settings.resolveApiKey() === false) {
    // skip test -- indico auth keys are not available
    console.warn('Api keys are now required. Skipping some tests.\nhttp://docs.indico.io/v2.0/docs/api-keys')
    return;
  }

  describe('batchPersonality', function() {
    it('should get the right response format', function(done) {

      var examples = [
        "I love my friends!",
        "I like to be alone."
      ];

      indico.personality(examples)
        .then(function(res) {

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(4);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchPersonas', function() {

    it('should get the right response format', function(done) {

      var examples = [
        "I love my friends!",
        "I like to be alone."
      ];

      indico.personas(examples)
        .then(function(res) {

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(16);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchSentiment', function() {
    it('should get the right response format', function(done) {

      var examples = [
        'Really enjoyed the movie.',
        'Worst day ever.'
      ];

      indico.sentiment(examples)
        .then(function(res){

          res.should.have.length(examples.length);
          res[0].should.be.above(0.5);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchSentimentHQ', function() {
    it('should get the right response format', function(done) {

      var examples = [
        'Really enjoyed the movie.',
        'Worst day ever.'
      ];

      indico.sentimentHQ(examples)
        .then(function(res){

          res.should.have.length(examples.length);
          res[0].should.be.above(0.5);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchTwitterEngagement', function() {
    it('should get the right response format', function(done) {

      var examples = [
        'Pic.twitter.com rt if #breaking',
        'Worst tweet ever'
      ];

      indico.twitterEngagement(examples)
        .then(function(res){

          res.should.have.length(examples.length);
          res[0].should.be.above(0.5);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchLanguage', function() {
    it('should get the right response format', function(done) {

      var examples = [
        'Quis custodiet ipsos custodes',
        'Clearly an english sentence'
      ];
      indico.language(examples)
        .then(function(res) {

          // number of languages
          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(33);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchTextTags', function() {
    it('should get the right response format', function(done) {

      var examples = [
        'Really enjoyed the movie.',
        'Not looking forward to rain tomorrow'
      ];

      indico.textTags(examples)
        .then(function(res){

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(111);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchKeywords', function() {
    it('should get the right response format', function(done) {
      var examples = [
        'Really enjoyed the movie.',
        'Not looking forward to rain tomorrow'
      ];
      indico.keywords(examples, {top_n:3})
        .then(function(res){

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(3);
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('batchAnalyzeText', function() {
    it('should get results from multiple text apis', function(done) {
      var examples = [
        'Really enjoyed the movie.',
        'Not looking forward to rain tomorrow'
      ];
      indico.analyzeText(examples, {'apis': ['sentiment', 'textTags']})
        .then(function(res){
          Object.keys(res).should.have.length(2);
          res['sentiment'].should.have.length(2);
          done();
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('intersections', function() {
    var examples = [
      'Really enjoyed the movie.',
      'Not looking forward to rain tomorrow',
      'Our apis go together like pb and j'
    ];

    it('should get the right response format in api mode', function(done) {

      indico.intersections(examples, {'apis': ['textTags', 'sentiment']})
      .then(function (res){
        expect(Object.keys(res)).to.have.length(111);
        expect(res['golf']).to.have.property('sentiment');
        done()
      })
      .catch(function(err){
        done(err);
        return;
      });
    });

    it('should get the right response format in historic mode', function(done) {
        this.timeout(5000);
      indico.analyzeText(examples, {'apis': ['textTags', 'sentiment']})
      .then(function (res) {
          indico.intersections(res, {'apis': ['textTags', 'sentiment']})
          .then(function (res){
              expect(res['golf']).to.have.property('sentiment');
              expect(Object.keys(res)).to.have.length(111);
            done();
          })
          .catch(function(err){
            done(err);
            return;
          });
        })
        .catch(function(err){
          done(err);
          return;
        });
    });
  });

  describe('batchPersonality', function() {

    it('should get the right response format', function(done) {

      var examples = [
        "I love my friends!",
        "I like to be alone."
      ];

      indico.personality(examples)
        .then(function(res) {

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(4);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });

  describe('batchPersonas', function() {

    it('should get the right response format', function(done) {

      var examples = [
        "I love my friends!",
        "I like to be alone."
      ];

      indico.personas(examples)
        .then(function(res) {

          res.should.have.length(examples.length);
          Object.keys(res[0]).should.have.length(16);
          done();
        })
        .catch(function(err){

          done(err);
          return;
        });
    });
  });
});


<|start_filename|>Server/Node Backend/node_modules/indico.io/lib/indico.js<|end_filename|>
var services = require('./services.js').services
  , makeRequest = require('./services.js').makeRequest
  , apiRequest = require('./services.js').apiRequest
  , detectBatch = require('./services.js').detectBatch
  , Collection = require('./custom.js')
  , indico = require('./services.js').base;

function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

function snakeCase(str) {
  return str.replace(/([A-Z])/g, function (char) {
    return '_' + char.toLowerCase();
  });
}

services.forEach(function (api) {
  indico[api.name] = apiRequest(api, false);
  indico["batch" + capitalize(api.name)] = apiRequest(api, true);
});

// camelCase + snake_case + lowercase supported
for (name in indico) {
  indico[snakeCase(name)] = indico[name];
  indico[name.toLowerCase()] = indico[name];
}

indico.Collection = function(collectionName, config) {
  return new Collection(collectionName, config);
}

indico.collections = function(config) {
  version = config['version'] || '1'
  delete config['version']
  return makeRequest('/custom/collections', version, {}, false, config);
}

indico.relevance = function(data, queries, config) {
  var batch = detectBatch(data);
  config = config || {};
  config.queries = queries
  version = config['version'] || '1'
  config.synonyms = config.synonyms || false;
  delete config['version']
  return makeRequest('/relevance', version, data, batch, config)
}
indico.posneg = indico.sentiment;

module.exports = indico;
