-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
177 lines (155 loc) · 5.19 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
176
177
//#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(requests, tags, responses, dsout) {
this.requests = requests;
this.tags = tags;
this.responses = responses;
this.dsout = dsout;
}
//#endregion
//#region dtstruc
/**
* @function dtstruc
* @description - dtstruc() function - Data structure re-constructor.
* Processes default object instance json key value
* (this.requests: requests), (this.tags: tags), (this.responses: responses) array patterns.
* @returns {array} - Return options
* qa() QA data structure,
* xy() XY train data structure,
* id() IDx chain data structure.
* Using split marks provides sentence boundary detection.
*/
Constructor.prototype.dtstruc = function () {
let out = dtstruc_f(this.requests, this.tags, this.responses, this.dsout);
return out;
};
//#endregion
//#region dtstruc_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);
/**
* Data structure re-constructor
* @param {array} requests - Requests pattern.
* @param {array} tags - Tags.
* @param {array} responses - Responses pattern.
* @param {boolean} [dispout=false] - A flag to enable or disable
* displaying processing output results in the terminal.
* @returns {Object} - An object containing the following properties:
* qa: QA data structure
* xy: XY train data structure
* id: IDx chain data structure
* @example
* let dtstruc_result = dtstruc(req_arr, tag_arr, res_arr, true);
* console.log(dtstruc_result.qa);
* console.log(dtstruc_result.xy);
* console.log(dtstruc_result.id);
*/
function dtstruc_f(requests, tags, responses, dispout) {
let XYtrainArrStruct = [];
let QADTStuct = [];
let IDxChainStuct = [];
for (i = 0; i < tags.length; i++) {
var tag = tags[i];
var pattern = requests[i];
var response = responses[i];
var patCont = "";
var resCont = "";
for (p = 0; p < pattern.length; p++) {
let patSentence = ds_clnstr.clnstr(pattern[p]).txt();
patSentence = patSentence.replace(/ /g, " ");
XYtrainArrStruct.push([i + "+" + tag + "=" + patSentence]);
patCont = patCont + "-" + patSentence;
}
for (r = 0; r < response.length; r++) {
let responses = ds_clnstr.clnstr(response[r]).txt();
resCont = resCont + "-" + responses;
}
patCont = patCont.slice(1);
resCont = resCont.slice(1);
var comb = i + ":" + tag + "/" + patCont + "=" + resCont;
QADTStuct.push([comb]);
var combQ = "Q=" + i + "+" + patCont;
var combA = "A=" + i + "+" + resCont;
IDxChainStuct.push(combQ);
IDxChainStuct.push(combA);
}
let QADTS = ds_clnarr.clnarr(QADTStuct, 1);
let XYTAS = ds_clnarr.clnarr(XYtrainArrStruct, 1);
let IDXCS = ds_clnarr.clnarr(IDxChainStuct, 1);
let outret = return_datsOut(QADTS, XYTAS, IDXCS);
displayF0(dispout, requests, tags.length, tags, responses, outret); /// DISPLAY >>>
return outret;
}
function return_datsOut(QADTS, XYTAS, IDXCS) {
const tokObj = {
qads: QADTS,
xyds: XYTAS,
idds: IDXCS,
qa: function () {
return this.qads;
},
xy: function () {
return this.xyds;
},
id: function () {
return this.idds;
},
};
return tokObj;
}
//#endregion
//#region console log
const getdt = require("./infodt.js");
let fnctit = getdt.displayInfoData();
const line = fnctit.line;
var description = fnctit.descript;
function displayF0(dispout, requests, tagslength, tags, responses, outret) {
if (dispout == true) {
console.log(
description,
"\nInput:\n\nRequests pattern:\n\n",
requests,
"\n\nTags (",
tagslength,
"):\n\n",
tags,
"\n\nResponses pattern:\n\n",
responses,
"\n\nOutput:\n\n",
outret,
"\n",
line
);
}
}
//#endregion
//#region Export Module Constructor
module.exports = Constructor;
//#endregion