Skip to content

Commit

Permalink
syhu/scalra-WPA: make output to files optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ImonCloud committed Sep 7, 2017
1 parent ae85010 commit 70388be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
16 changes: 9 additions & 7 deletions modules/WPA.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ var getBridgingEdge = function (edges, authors) {
/*
example input:
var input = {
names: args.names,
file_paths: file_paths,
authors: authors,
words: args.word_size,
R_CUT: R_CUT,
stat_scope: stat_scope,
set_type: set_type
names: 'string', // array of data labels (ex. filenames)
data: [string], // array of raw data (with puntuation marks)
authors: [string], // array of author names
words: 'number', // ex. 2
R_CUT: 'number', // ex. 70
stat_scope: 'string', // ['r_cut', 'full']
set_type: 'string', // ['union', 'intersection']
write_freq_table: 'boolean', // whether to output frequency table to file
write_raw: 'boolean' // whether to output raw data to file
};
*/
exports.analyze = function (input, onDone) {
Expand Down
36 changes: 21 additions & 15 deletions modules/word_frequency.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,28 @@ word_frequency.prototype.parse = function (input, onDone) {

// store raw & frequency to files
var filename = input.names[input.index];
// NOTE: currently the same exact file will be written multiple times,
// if 'unique_words' are different due to different word-length selection
// do not write files depend on settings
if (input.write_raw === true) {
fs.writeFile(
"./output/A_raw_data_"
+ string_without_marks.length
+ "_"
+ unique_words
+ "_"
+ filename,
string_without_marks
);
}

fs.writeFile(
"./output/A_raw_data_"
+ string_without_marks.length
+ "_"
+ unique_words
+ "_"
+ filename,
string_without_marks
);

fs.writeFile(
"./output/B_freq_table_"
+ filename,
util.inspect(sorted_words)
);
if (input.write_freq_table === true) {
fs.writeFile(
"./output/B_freq_table_"
+ filename,
util.inspect(sorted_words)
);
}

return onDone(null, {freq_table: sorted_words, filename: filename});
}
Expand Down

0 comments on commit 70388be

Please sign in to comment.