<commit_before>var _ = require('lodash')
var express = require('express')
var w2v = require('word2vec')
var mongoose = require('mongoose')
var winston = require('winston')
winston.add(winston.transports.File, { filename: 'npm-recommender.log' })
var format = require('string-format')
format.extend(String.prototype)

var PackageInfo = require('./package-info.js')
var settings = require('../conf/main.js')

mongoose.connect(settings.db)

var computeSimilarity = function (model, name, cb) {
  var mostSimilar = model.mostSimilar(name, settings.numSimilar)
  PackageInfo.find().where('name').in(_.map(mostSimilar, 'word')).exec(function (err, docs) {
    if (err) return cb(err)
    var descriptions = _.zipObject(_.map(docs, 'name'), _.map(docs, 'description'))
    _.forEach(mostSimilar, function (entry) {
      entry.description = descriptions[entry.word]
    })
    PackageInfo.update({ name: name }, { similar: mostSimilar }, function (err) {
      if (err) return cb(err)
      return cb(null, mostSimilar)
    })
  })
}

var start = function (opts) {
  opts = opts || {}
  var port = opts.port || 8080
  var app = express()
  console.log('Loading model...')
  w2v.loadModel(settings.outputFile, function (err, model) {
    if (err) return err
    app.get('/api/mostSimilar/:package', function (req, res) {
      var pkg = req.params.package
      winston.info('mostSimilar/' + pkg)
      PackageInfo.findOne({ name: pkg }, function (err, doc) {
        if (err) return res.status(500).send(err)<commit_msg>Changed mostSimilar to similar<commit_after>var _ = require('lodash')
var express = require('express')
var w2v = require('word2vec')
var mongoose = require('mongoose')
var winston = require('winston')
winston.add(winston.transports.File, { filename: 'npm-recommender.log' })
var format = require('string-format')
format.extend(String.prototype)

var PackageInfo = require('./package-info.js')
var settings = require('../conf/main.js')

mongoose.connect(settings.db)

var computeSimilarity = function (model, name, cb) {
  var mostSimilar = model.mostSimilar(name, settings.numSimilar)
  PackageInfo.find().where('name').in(_.map(mostSimilar, 'word')).exec(function (err, docs) {
    if (err) return cb(err)
    var descriptions = _.zipObject(_.map(docs, 'name'), _.map(docs, 'description'))
    _.forEach(mostSimilar, function (entry) {
      entry.description = descriptions[entry.word]
    })
    PackageInfo.update({ name: name }, { similar: mostSimilar }, function (err) {
      if (err) return cb(err)
      return cb(null, mostSimilar)
    })
  })
}

var start = function (opts) {
  opts = opts || {}
  var port = opts.port || 8080
  var app = express()
  console.log('Loading model...')
  w2v.loadModel(settings.outputFile, function (err, model) {
    if (err) return err
    app.get('/api/similar/:package', function (req, res) {
      var pkg = req.params.package
      winston.info('similar/' + pkg)
      PackageInfo.findOne({ name: pkg }, function (err, doc) {
        if (err) return res.status(500).send(err)
{'fraction_non_alphanumeric': 0.1601317957166392, 'fraction_numerical': 0.006589785831960461, 'mean_word_length': 4.043189368770764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6834867', 'n_tokens_mistral': 998, 'n_tokens_neox': 957, 'n_words': 228}