-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
193 lines (165 loc) · 5.47 KB
/
Copy pathindex.js
File metadata and controls
193 lines (165 loc) · 5.47 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//#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:ladooniani@gmail.com
* @version 1.0.0
* @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(input, dsout) {
this.input = input;
this.dsout = dsout;
}
//#endregion
//#region enoun
/**
* @Constructs enoun
* @description Constructs the 'enoun' function.
* @param {string} input - The input sentence raw string.
* Pass NULL to process the constructor's 'input'.
* @param {number} swa - An integer in the range of 0-2, which determines the amount of stop words to be processed.
* @returns {object} - Returns an object with the following options:
* - noun(): Separated English nouns
* - stop(): Rest of stop words
*/
Constructor.prototype.enoun = function (input, swa) {
input = objOrFncInp(input, this.input);
let out = enoun_f(input, swa, this.dsout);
return out;
};
//#endregion
//#region enoun_f
const dropsuit_clnstr = require("../dropsuit-clnstr/index.js");
var ds_clnstr = new dropsuit_clnstr(null, false);
const dropsuit_clnarr = require("../dropsuit-clnarr/index.js");
var ds_clnarr = new dropsuit_clnarr(false);
/**
* Separates English nouns and stop words from an input string.
* @param {string} input - The input sentence raw string.
* Pass NULL to process the constructor's 'input'.
* @param {number} swa - An integer in the range of 0-2, which determines the amount of stop words to be processed.
* 0 processes the minimum amount, 1 adds extra stop words,
* and 2 includes the maximum number of stop words from three distinct lists.
* @param {boolean} dispout - Determines if the processing output results are displayed in the terminal.
* @returns {object} - Returns an object with the following options:
* - noun(): Separated English nouns
* - stop(): Rest of stop words
* @example enoun_f(string, bool)
*/
function enoun_f(input, swa, dispout) {
let stopWords = buildList(swa);
let inputNounLst = [];
let inputNonNounLst = [];
input = ds_clnstr.clnstr(input).txt();
var inputSentenceWords = input.split(" ");
for (let i = 0; i < inputSentenceWords.length; i++) {
var val = inputSentenceWords[i].replace(/[0-9]/g, "");
var v = checkval(val);
if (v == true) {
val = ds_clnstr.clnstr(val).txt();
if (!stopWords.includes(val)) {
if (!inputNounLst.includes(val)) {
inputNounLst.push(val);
}
} else if (stopWords.includes(val)) {
if (!inputNonNounLst.includes(val)) {
inputNonNounLst.push(val);
}
}
}
}
inputNounLst = ds_clnarr.clnarr(inputNounLst, 1);
inputNonNounLst = ds_clnarr.clnarr(inputNonNounLst, 1);
let retout = return_enounOut(inputNounLst, inputNonNounLst);
display(dispout, input, retout); /// DISPLAY >>
return retout;
}
function buildList(swa) {
let avoidLst = [];
const getList = require("./swdt.js");
let sw1 = getList.stopwords_a();
let sw2 = getList.stopwords_b();
let sw3 = getList.stopwords_c();
if (swa > 2) {
swa = 0;
}
if (swa == 0) {
avoidLst = getList.stopwords_a();
} else if (swa == 1) {
avoidLst = sw1.concat(sw2);
} else if (swa == 2) {
avoidLst = sw1.concat(sw2, sw3);
}
avoidLst = ds_clnarr.clnarr(avoidLst, 2);
return avoidLst;
}
function checkval(v) {
if (v != "" && v != " " && v != undefined && v != null) {
return true;
} else {
return false;
}
}
function return_enounOut(inputNounLst, inputNonNounLst) {
const enounObj = {
nounw: inputNounLst,
stopw: inputNonNounLst,
noun: function () {
return this.nounw;
},
stop: function () {
return this.stopw;
},
};
return enounObj;
}
function objOrFncInp(function_input, constructor_input) {
if (function_input !== "" && function_input !== null) {
function_input = function_input;
} else {
function_input = constructor_input;
}
return function_input;
}
//#endregion
//#region console log
const getdt = require("./infodt.js");
let fnctit = getdt.displayInfoData();
const line = fnctit.line;
var description = fnctit.descript;
function display(dispout, input, retout) {
if (dispout == true) {
console.log(
description,
"\nInput:\n\n",
[input],
"\n\nOutput object:\n\n",
retout,
"\n",
line
);
}
}
//#endregion
//#region Export Module Constructor
module.exports = Constructor;
//#endregion