Skip to content

Commit

Permalink
Forgot to commit this file
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Dec 17, 2013
1 parent 97be9b8 commit 505925e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/summary.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var _ = require('underscore');
var _ = require('lodash-node/underscore');

function splitContentToSentences(content, callback) {
if(content.indexOf('.') === -1) {
return callback(false);
}

content = content.replace("\n", ". ");
content = content.replace("\n", '. ');
callback(content.match(/(.+?\.(?:\s|$))/g));
}

Expand All @@ -14,14 +14,14 @@ function splitContentToParagraphs(content, callback) {
}

function sentencesIntersection(sent1, sent2, callback) {
var s1 = sent1.split(" ");
var s2 = sent2.split(" ");
var s1 = sent1.split(' ');
var s2 = sent2.split(' ');

if((s1.length + s2.length) === 0) {
callback(true);
}

var intersect = _.intersection(s1, s2);
var intersect = _.intersection(s1, s2);
var spliceHere = ((s1.length + s2.length) / 2);

callback(false, intersect.splice(0, spliceHere).length);
Expand All @@ -36,10 +36,10 @@ function formatSentence(sentence, callback) {

function getBestSentence(paragraph, sentences_dict, callback) {
splitContentToSentences(paragraph, function(sentences) {
if (!sentences) return "";
if (sentences.length < 2) return "";
if (!sentences) return '';
if (sentences.length < 2) return '';

var best_sentence = "", max_value = 0, strip_s;
var best_sentence = '', max_value = 0, strip_s;
_.each(sentences, function(s) {
formatSentence(s, function(strip_s) {
if(strip_s && sentences_dict[strip_s] > max_value) {
Expand All @@ -55,8 +55,8 @@ function getBestSentence(paragraph, sentences_dict, callback) {

function getSortedSentences(paragraph, sentences_dict, n, callback) {
splitContentToSentences(paragraph, function(sentences) {
if (!sentences) return callback("");
if (sentences.length < 2) return callback("");
if (!sentences) return callback('');
if (sentences.length < 2) return callback('');

var sentence_scores = [], strip_s;
_.each(sentences, function(s, i) {
Expand Down Expand Up @@ -130,7 +130,7 @@ function getSentencesRanks(content, callback) {
}

exports.summarize = function(title, content, callback) {
var summary = [], paragraphs = [], sentence = "", err = false;
var summary = [], paragraphs = [], sentence = '', err = false;
getSentencesRanks(content, function(dict) {
splitContentToParagraphs(content, function(paragraphs) {
summary.push(title); // Store the title.
Expand All @@ -156,7 +156,7 @@ exports.getSortedSentences = function(content, n, callback) {

getSentencesRanks(content, function(dict) {
getSortedSentences(content, dict, n, function(sorted_sentences) {
if(sorted_sentences === "") {
if(sorted_sentences === '') {
callback(new Error('Too short to summarize.'));
} else {
callback(null, sorted_sentences);
Expand Down

0 comments on commit 505925e

Please sign in to comment.