1- import { convertHTMLToText , getTitle } from './helpers/html'
2- import { isValidUrl } from './helpers/urls'
1+ import { convertHTMLToText , getTitle } from './helpers/html.js'
2+ import { isValidUrl } from './helpers/urls.js'
3+ import { default as request } from 'request'
34import {
45 onlyGetSentences ,
56 splitContentToSentences ,
67 splitContentToParagraphs ,
78 sentencesIntersection ,
89 formatSentence ,
910 getBestSentence ,
10- getSortedSentences ,
11+ getSortedSentences as getSortedSentencesInner ,
1112 getSentencesRanks ,
12- } from './helpers/summarizer'
13+ } from './helpers/summarizer.js '
1314
14- const request = require ( 'request' )
15-
16- exports . summarizeFromUrl = function ( url , callback ) {
17- var summaryToolContext = this
15+ export const summarizeFromUrl = function ( url , callback ) {
1816 if ( isValidUrl ( url ) ) {
1917 request . get ( url , function ( error , response , body ) {
2018 let title = getTitle ( body )
2119 let text = convertHTMLToText ( body )
2220 let content = onlyGetSentences ( text )
23- return summaryToolContext . summarize (
24- title ,
25- content ,
26- ( err , result , dict ) => {
27- if ( err ) {
28- callback ( err , result , dict )
29- } else {
30- callback ( err , result , dict )
31- }
21+ return summarize ( title , content , ( err , result , dict ) => {
22+ if ( err ) {
23+ callback ( err , result , dict )
24+ } else {
25+ callback ( err , result , dict )
3226 }
33- )
27+ } )
3428 } )
3529 } else {
3630 callback (
@@ -40,18 +34,11 @@ exports.summarizeFromUrl = function (url, callback) {
4034 }
4135}
4236
43- exports . summarize = ( title , content , callback , sentences_dict ) => {
37+ export const summarize = ( title , content , callback , sentences_dict ) => {
4438 var summary = [ ] ,
4539 paragraphs = [ ] ,
4640 sentence = '' ,
4741 err = false
48- if ( arguments . length < 3 ) {
49- if ( content . constructor === Function ) {
50- callback = content
51- content = title
52- title = ''
53- }
54- }
5542 getSentencesRanks (
5643 content ,
5744 dict => {
@@ -73,7 +60,7 @@ exports.summarize = (title, content, callback, sentences_dict) => {
7360 )
7461}
7562
76- exports . getSortedSentences = ( content , n , callback , sentences_dict ) => {
63+ export const getSortedSentences = ( content , n , callback , sentences_dict ) => {
7764 if ( typeof n === 'function' ) {
7865 callback = n
7966 n = 0
@@ -82,7 +69,7 @@ exports.getSortedSentences = (content, n, callback, sentences_dict) => {
8269 getSentencesRanks (
8370 content ,
8471 dict => {
85- getSortedSentences ( content , dict , n , sorted_sentences => {
72+ getSortedSentencesInner ( content , dict , n , sorted_sentences => {
8673 if ( sorted_sentences === '' ) {
8774 callback ( new Error ( 'Too short to summarize.' ) )
8875 } else {
0 commit comments