Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it work on MacOS? #5

Open
fmmsilva opened this issue Dec 21, 2020 · 1 comment
Open

How to make it work on MacOS? #5

fmmsilva opened this issue Dec 21, 2020 · 1 comment

Comments

@fmmsilva
Copy link

Got this error:

159 error In file included from ../src/bson.cc:41:
159 error ../src/bson.h:182:92: error: too few arguments to function call, single argument 'isolate' was not specified
159 error void WriteLengthPrefixedString(const Local& value) { WriteInt32(value->Utf8Length()+1); WriteString(value); }
159 error void WriteDouble(const Local& object, const Local&
159 error
~~~~~~~~~~~~~~~~~~ ^
159 error /Users/fmmsilva/.node-gyp/15.4.0/include/node/v8.h:2907:3: note: 'NumberValue
' declared here
159 error V8_WARN_UNUSED_RESULT Maybe NumberValue(Local context) con
st;

@radekstepan
Copy link
Owner

radekstepan commented Dec 22, 2020

CoffeeScript is out of date. I'll appreciate a PR to fix.

In the meantime, here's the same code in JS:

var Minimatch, TfIdf, _;

({Minimatch} = require('minimatch'));

({TfIdf} = require('natural'));

_ = require('lodash');

module.exports = function(opts) {
  var index, mm, tfidf;
  if (opts == null) {
    opts = {};
  }
  if (opts.pattern == null) {
    opts.pattern = '**/*.md';
  }
  if (opts.max == null) {
    opts.max = 5;
  }
  if (opts.terms == null) {
    opts.terms = 5;
  }
  if (opts.threshold == null) {
    opts.threshold = 0;
  }
  if (opts.text == null) {
    opts.text = function(doc) {
      return String(doc.contents);
    };
  }
  mm = new Minimatch(opts.pattern);
  tfidf = new TfIdf();
  index = [];
  return function(files, metalsmith, done) {
    var doc, freq, i, j, k, key, ref, related, term, terms, top;
    for (key in files) {
      doc = files[key];
      if (!(mm.match(key))) {
        continue;
      }
      index.push(key);
      tfidf.addDocument(opts.text(doc));
    }
    for (i = k = 0, ref = index.length; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {
      terms = tfidf.listTerms(i);
      top = (function() {
        var l, len, ref1, results;
        ref1 = terms.slice(0, Math.min(opts.terms, terms.length));
        results = [];
        for (l = 0, len = ref1.length; l < len; l++) {
          ({term} = ref1[l]);
          results.push(term);
        }
        return results;
      })();
      related = _((function() {
        var l, len, ref1, results;
        ref1 = tfidf.tfidfs(top);
        results = [];
        for (j = l = 0, len = ref1.length; l < len; j = ++l) {
          freq = ref1[j];
          if (j !== i && freq > opts.threshold) {
            results.push({freq, j});
          }
        }
        return results;
      })()).sortBy('freq').map('j').value().reverse().map(function(j) {
        return files[index[j]];
      });
      if (related.length) {
        files[index[i]].related = related.slice(0, Math.min(opts.max, related.length));
      }
    }
    return done();
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants