-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
175 lines (150 loc) · 4.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//#region Info
/**
* @file <h3>DropSuit</h3>
* <p>
* DropSuit is a JavaScript(ES6) and Node.js(v14.x) module library
* created by Lado Oniani that offers a diverse collection of functions
* for natural language processing (NLP) and data manipulation.
* It provides a curated collection of original and classic techniques and methods
* for tasks such as text analysis, language understanding and generation,
* as well as for data manipulation tasks. Additionally,
* it includes unique tools and features for chatbot dialog flow logic
* and other specific use cases.
* The library is open-source and available under the Apache License 2.0.
* Whether you're a researcher, developer, or data scientist,
* DropSuit offers a range of tools to enhance your work,
* with a focus on diversity and experimentation.
* </p>
* @author Lado Oniani
* {@link https://github.com/ladooniani GitHub}
* @see mailto:[email protected]
* @version 1.0.2
* @see https://github.com/ladooniani/DropSuit#readme
* @copyright 2016-2023 Lado Oniani - DropSuit. All Rights Reserved.
* @license Apache License 2.0
*/
//#endregion
//#region Constructor
function Constructor(dsout) {
this.dsout = dsout;
}
//#endregion
//#region clnarr
/**
* @class clnarr
* @description clnarr(array, 0-2) function -
* Duplicate and empty element free trimmed lower case strings array.
* Processes any input array.
* @param {array} arr - Raw array input.
* @param {number} type - Return option parameter arguments
* (0) keep duplicate, (1) remove duplicate, (2) remove duplicate and extra marks.
* Note: Number out of range returns 0 option result.
* @returns {array} - Duplicate, empty element and extra punctuation marks
* free trimmed lower case strings array.
* @example let out = clnarr.clnarr(myArray, 2); console.log(out);
*/
Constructor.prototype.clnarr = function (arr, type) {
let out = clnarr_f(arr, type, this.dsout);
return out;
};
//#endregion
//#region clnarr_f
const dropsuit_clnstr = require("../dropsuit-clnstr/index.js");
var ds_clnstr = new dropsuit_clnstr(null, false);
/**
* Duplicate, empty element and extra punctuation marks free trimmed lower case strings array.
* @function
* @param {array} arr - Raw array input.
* @param {number} type - Return option parameter arguments (0) keep duplicate (1) remove duplicate
* (2) remove duplicate and extra marks.
* @param {boolean} dispout - (true/false) Display processing output results in terminal.
* @returns {array} - Duplicate, empty element and extra punctuation marks free trimmed lower case strings array.
* @example clnarr(myArray, 2, false)
*/
function clnarr_f(arr, type, dispout) {
let array = [];
type = checkType(type, 2);
let ar = avoidMarks(arr);
array = removeEmptyElementAndDuplicateFromArray(ar, type);
for (let s = 0; s < array.length; s++) {
var str = array[s].toString().replace(/\s\s+/g, " ").trim().toLowerCase();
if (str) {
if (type == 2) {
str = ds_clnstr.clnstr(str).txt();
} else if (type == 0 || type == 1) {
let containsLetters = /[a-zA-Z]/.test(str);
if (containsLetters) {
str = ds_clnstr.clnstr(str).pnc();
}
}
array[s] = str;
}
}
array = removeEmptyElementAndDuplicateFromArray(array, type);
display(dispout, arr, array, type); /// DISPLAY >>
return array;
}
function avoidMarks(inputArray) {
let filteredArray = inputArray.filter((str) => {
return !/^[^a-zA-Z]+$/.test(str);
});
return filteredArray;
}
function removeEmptyElementAndDuplicateFromArray(arr, type) {
arr = arr.filter((e) => e);
if (type == 1 || type == 2) {
arr = [...new Set(arr)];
}
arr = arr.filter((val) => val !== "true" && val !== "false");
return arr;
}
function checkType(type, range) {
if (range == 1) {
if (type == 0 || type == 1) {
return type;
} else {
return (type = 0);
}
}
if (range == 2) {
if (type == 0 || type == 1 || type == 2) {
return type;
} else {
return (type = 0);
}
}
}
//#endregion
//#region console log
const getdt = require("./infodt.js");
let fnctit = getdt.displayInfoData();
const line = fnctit.line;
var description = fnctit.descript;
function display(dispout, arr, array, type) {
let return_type;
if (type == 0) {
return_type = "Keep duplicate:\n\n";
} else if (type == 1) {
return_type = "Remove duplicate:\n\n";
} else if (type == 2) {
return_type = "Remove duplicate and extra marks:\n\n";
}
if (dispout == true) {
console.log(
description,
"\nInput:\n\n",
arr,
"\n\nReturn type (",
type,
") -->",
return_type,
array,
"\n",
line
);
}
}
//#endregion
//#region Export Module Constructor
module.exports = Constructor;
//#endregion