1- var _ = require ( 'underscore' ) ;
1+ var _ = require ( 'lodash-node/ underscore' ) ;
22
33function splitContentToSentences ( content , callback ) {
44 if ( content . indexOf ( '.' ) === - 1 ) {
55 return callback ( false ) ;
66 }
77
8- content = content . replace ( "\n" , ". " ) ;
8+ content = content . replace ( "\n" , '. ' ) ;
99 callback ( content . match ( / ( .+ ?\. (?: \s | $ ) ) / g) ) ;
1010}
1111
@@ -14,14 +14,14 @@ function splitContentToParagraphs(content, callback) {
1414}
1515
1616function sentencesIntersection ( sent1 , sent2 , callback ) {
17- var s1 = sent1 . split ( " " ) ;
18- var s2 = sent2 . split ( " " ) ;
17+ var s1 = sent1 . split ( ' ' ) ;
18+ var s2 = sent2 . split ( ' ' ) ;
1919
2020 if ( ( s1 . length + s2 . length ) === 0 ) {
2121 callback ( true ) ;
2222 }
2323
24- var intersect = _ . intersection ( s1 , s2 ) ;
24+ var intersect = _ . intersection ( s1 , s2 ) ;
2525 var spliceHere = ( ( s1 . length + s2 . length ) / 2 ) ;
2626
2727 callback ( false , intersect . splice ( 0 , spliceHere ) . length ) ;
@@ -36,10 +36,10 @@ function formatSentence(sentence, callback) {
3636
3737function getBestSentence ( paragraph , sentences_dict , callback ) {
3838 splitContentToSentences ( paragraph , function ( sentences ) {
39- if ( ! sentences ) return "" ;
40- if ( sentences . length < 2 ) return "" ;
39+ if ( ! sentences ) return '' ;
40+ if ( sentences . length < 2 ) return '' ;
4141
42- var best_sentence = "" , max_value = 0 , strip_s ;
42+ var best_sentence = '' , max_value = 0 , strip_s ;
4343 _ . each ( sentences , function ( s ) {
4444 formatSentence ( s , function ( strip_s ) {
4545 if ( strip_s && sentences_dict [ strip_s ] > max_value ) {
@@ -55,8 +55,8 @@ function getBestSentence(paragraph, sentences_dict, callback) {
5555
5656function getSortedSentences ( paragraph , sentences_dict , n , callback ) {
5757 splitContentToSentences ( paragraph , function ( sentences ) {
58- if ( ! sentences ) return callback ( "" ) ;
59- if ( sentences . length < 2 ) return callback ( "" ) ;
58+ if ( ! sentences ) return callback ( '' ) ;
59+ if ( sentences . length < 2 ) return callback ( '' ) ;
6060
6161 var sentence_scores = [ ] , strip_s ;
6262 _ . each ( sentences , function ( s , i ) {
@@ -130,7 +130,7 @@ function getSentencesRanks(content, callback) {
130130}
131131
132132exports . summarize = function ( title , content , callback ) {
133- var summary = [ ] , paragraphs = [ ] , sentence = "" , err = false ;
133+ var summary = [ ] , paragraphs = [ ] , sentence = '' , err = false ;
134134 getSentencesRanks ( content , function ( dict ) {
135135 splitContentToParagraphs ( content , function ( paragraphs ) {
136136 summary . push ( title ) ; // Store the title.
@@ -156,7 +156,7 @@ exports.getSortedSentences = function(content, n, callback) {
156156
157157 getSentencesRanks ( content , function ( dict ) {
158158 getSortedSentences ( content , dict , n , function ( sorted_sentences ) {
159- if ( sorted_sentences === "" ) {
159+ if ( sorted_sentences === '' ) {
160160 callback ( new Error ( 'Too short to summarize.' ) ) ;
161161 } else {
162162 callback ( null , sorted_sentences ) ;
0 commit comments