smart-word-generator 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -1
- package/generators/index.js +159 -0
- package/index.js +7 -151
- package/logo-color.png +0 -0
- package/package.json +1 -1
- /package/{utils.js → utils/index.js} +0 -0
package/README.md
CHANGED
|
@@ -1 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://user-images.githubusercontent.com/59231851/209891435-14146604-3927-40f9-a439-73ca623a8db6.jpg">
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center"><b>A javaScript library for generating words using artificial intelligence depending on your needs.
|
|
5
|
+
</b></p>
|
|
6
|
+
|
|
7
|
+
## Description
|
|
8
|
+
|
|
9
|
+
Smart word generator is a framewjavaScript library for generating words using artificial intelligence depending on your needs. It uses API call to generate words that suits the use case you are facing, you can find the original API used from <a href="https://www.datamuse.com/api/?fbclid=IwAR2GxnfFJqlA78kKGYtPIemRSpA45RAEWqGYCSRCxVyPsWk-0n1n9E6UoOQ" target="_blank">here</a>.
|
|
10
|
+
|
|
11
|
+
<p>Under the hood, Smart-Word-generator is just working as interface to that API with different easy callable and readable function that would suit your use case.</p>
|
|
12
|
+
|
|
13
|
+
## Philosophy
|
|
14
|
+
|
|
15
|
+
<p>In recent years, thanks to AI, most of stuff around us had been managed by AI in someway, AI has multiple fields like computer vision which is related to images and videos, that field made the computers able to see and recognize stuff then take actions depending on that, also there is another field which is NLP (Natural language processing) which is related to words, that field gave machines the ability to understand the language and generate words and sentences.
|
|
16
|
+
|
|
17
|
+
And here came the idea of smart-word-generator where you do not just generate random words when you need some real data related to some area or some meaning, or when you want to fill your database with data which is meaningful, in the past, people would just go and enter the data directly if they want meaningful data, but it is the AI era, and that is why we had created smart-word-generator.
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
## Questions
|
|
21
|
+
For questions and support please email me on: MahmoudMagdyMahmoud1@gmail.com. Or just open new issue here, and for sure, PRs are very welcomed.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
* Generate words have similar meaning to the word you are providing
|
|
25
|
+
* Generate words have sound like the word you are providing (the results are pronounced similarly to this string of characters).
|
|
26
|
+
* Generate words are spelled like the word you are providing (the results are spelled similarly to this string of characters, or that they match this wildcard pattern).
|
|
27
|
+
* Generate words that appears immediately to the left of the target word in a sentence.
|
|
28
|
+
* Generate words that appears immediately to the right of the target word in a sentence.
|
|
29
|
+
* Provide optional parameters to get more specific data like:
|
|
30
|
+
* maximum number of generated words
|
|
31
|
+
* the generated words should start with a specific character
|
|
32
|
+
* the generated words should end with a specific character
|
|
33
|
+
* the generated words should be in which type (part-of-speech) like (noun, adj, adv, v, ...etc)
|
|
34
|
+
* the generated words should be in related to which topic
|
|
35
|
+
* the generated words should be represented as array of words or array of objects with extra information for each word like part of speech and the score of the word
|
|
36
|
+
* In progress...
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ npm i smart-word-generator
|
|
42
|
+
```
|
|
43
|
+
### Params which is provided to all functions by order:
|
|
44
|
+
* @param {String} The input word
|
|
45
|
+
* @param {Boolean} (false by default) transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
46
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
47
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
48
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
49
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
50
|
+
* @param {String} max Optional param to specify number of returned words
|
|
51
|
+
|
|
52
|
+
## examples
|
|
53
|
+
Generate __array of noun words__ have similar meaning to the word __'great'__
|
|
54
|
+
```sh
|
|
55
|
+
const smartWordGenerator = require("smart-word-generator");
|
|
56
|
+
|
|
57
|
+
smartWordGenerator
|
|
58
|
+
.generateWordMeansLike("great", true, "n")
|
|
59
|
+
.then((res) => console.log(res));
|
|
60
|
+
# Output: ['big','corking','extraordinary', 'neat', 'bully', 'expectant', 'majuscule', 'uppercase', 'capital', 'groovy', 'pregnant', 'enceinte', 'vast', 'mega', 'massive','immense','hefty','mighty','strong','staggering','full',lot','lofty']
|
|
61
|
+
```
|
|
62
|
+
Generate __array of objects__ containing words and extra info that have spelling like the word __'flower'__
|
|
63
|
+
```sh
|
|
64
|
+
const smartWordGenerator = require("smart-word-generator");
|
|
65
|
+
|
|
66
|
+
smartWordGenerator
|
|
67
|
+
.generateWordSpelledLike("flower", false)
|
|
68
|
+
.then((res) => console.log(res));
|
|
69
|
+
# Output: [{word:'flower',score:67939,tags:['n']},{word:'lower',score:879,tags:['adj']},{word:'glower',score:710,tags:['n','v']},{word:'blower',score:686,tags:['n']},{word:'slower',score:163,tags:['n']},{word:'flowed',score:129,tags:['v']},{word:'frower',score:109,tags:['n']},{word:'clower',score:95,tags:['n','prop']},{word:'plower',score:57,tags:['n']},{word:'flewer',score:38},{word:'flowen',score:17,tags:['n']},{word:'fower',score:16,tags:['n']}]
|
|
70
|
+
```
|
|
71
|
+
Generate only __array of words__ which has __length of 5__ that sounds like the word __'flower'__
|
|
72
|
+
```sh
|
|
73
|
+
const smartWordGenerator = require("smart-word-generator");
|
|
74
|
+
|
|
75
|
+
smartWordGenerator
|
|
76
|
+
.generateWordSoundsLike("flower", true, null, null, null, null, 5)
|
|
77
|
+
.then((res) => console.log(res));
|
|
78
|
+
# Output:['flower','flour','floor','flohr','flaugher']
|
|
79
|
+
```
|
|
80
|
+
Generate only __array of words__, all of them should start with character __s__ (Note: could be a substring not only a character) that mostly placed to the left of the word like __'computer'__ in most of sentences.
|
|
81
|
+
```sh
|
|
82
|
+
const smartWordGenerator = require("smart-word-generator");
|
|
83
|
+
|
|
84
|
+
smartWordGenerator
|
|
85
|
+
.generateWordHasLeftContext("computer", true, null, null, 's')
|
|
86
|
+
.then((res) => console.log(res));
|
|
87
|
+
# Output:['science','system','systems','software','simulation','screen','simulations','society','security','services','scientists','skills','sciences','screens','storage','support','service','studies','scientist']
|
|
88
|
+
```
|
|
89
|
+
Generate only __array of words__, all of them should end with character __e__ (Note: could be a substring not only a character) that mostly placed to the left of the word like __'medicine'__ in most of sentences.
|
|
90
|
+
```sh
|
|
91
|
+
const smartWordGenerator = require("smart-word-generator");
|
|
92
|
+
|
|
93
|
+
smartWordGenerator
|
|
94
|
+
.generateWordHasRightContext("medicine", true, null, null, null,'e')
|
|
95
|
+
.then((res) => console.log(res));
|
|
96
|
+
# Output: ['the','preventive','chinese','alternative','practice','some','care','reproductive','take','like','practise','state','palliative']
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Stay in touch
|
|
100
|
+
|
|
101
|
+
* Author - [Mahmoud Magdy](MahmoudMagdyMahmoud1@gmail.com)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const { wordOptionalParams, decorateWords } = require("../utils");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate words that have similar meaning of input word
|
|
6
|
+
* @param {String} word The input word
|
|
7
|
+
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
8
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
9
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
10
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
11
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
12
|
+
* @param {String} max Optional param to specify number of returned words
|
|
13
|
+
*/
|
|
14
|
+
const generateWordMeansLike = async (
|
|
15
|
+
word,
|
|
16
|
+
transformToArray = false,
|
|
17
|
+
partOfSpeech,
|
|
18
|
+
topics,
|
|
19
|
+
startWith,
|
|
20
|
+
endWith,
|
|
21
|
+
max
|
|
22
|
+
) => {
|
|
23
|
+
try {
|
|
24
|
+
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
25
|
+
let response = await axios.get(
|
|
26
|
+
`https://api.datamuse.com/words?ml=${word}&${optionalParams}`
|
|
27
|
+
);
|
|
28
|
+
return decorateWords(partOfSpeech, transformToArray, response);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(err);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate words that sounds like input word
|
|
36
|
+
* @param {String} word The input word
|
|
37
|
+
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
38
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
39
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
40
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
41
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
42
|
+
* @param {String} max Optional param to specify number of returned words
|
|
43
|
+
*/
|
|
44
|
+
const generateWordSoundsLike = async (
|
|
45
|
+
word,
|
|
46
|
+
transformToArray = false,
|
|
47
|
+
partOfSpeech,
|
|
48
|
+
topics,
|
|
49
|
+
startWith,
|
|
50
|
+
endWith,
|
|
51
|
+
max
|
|
52
|
+
) => {
|
|
53
|
+
try {
|
|
54
|
+
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
55
|
+
let response = await axios.get(
|
|
56
|
+
`https://api.datamuse.com/words?sl=${word}&${optionalParams}`
|
|
57
|
+
);
|
|
58
|
+
return decorateWords(partOfSpeech, transformToArray, response);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error(err);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generate words that spelled like input word
|
|
66
|
+
* @param {String} word The input word
|
|
67
|
+
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
68
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
69
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
70
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
71
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
72
|
+
* @param {String} max Optional param to specify number of returned words
|
|
73
|
+
*/
|
|
74
|
+
const generateWordSpelledLike = async (
|
|
75
|
+
word,
|
|
76
|
+
transformToArray = false,
|
|
77
|
+
partOfSpeech,
|
|
78
|
+
topics,
|
|
79
|
+
startWith,
|
|
80
|
+
endWith,
|
|
81
|
+
max
|
|
82
|
+
) => {
|
|
83
|
+
try {
|
|
84
|
+
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
85
|
+
let response = await axios.get(
|
|
86
|
+
`https://api.datamuse.com/words?sp=${word}&${optionalParams}`
|
|
87
|
+
);
|
|
88
|
+
return decorateWords(partOfSpeech, transformToArray, response);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error(err);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Generate words that have left context of input word
|
|
96
|
+
* @param {String} word The input word
|
|
97
|
+
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
98
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
99
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
100
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
101
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
102
|
+
* @param {String} max Optional param to specify number of returned words
|
|
103
|
+
*/
|
|
104
|
+
const generateWordHasLeftContext = async (
|
|
105
|
+
word,
|
|
106
|
+
transformToArray = false,
|
|
107
|
+
partOfSpeech,
|
|
108
|
+
topics,
|
|
109
|
+
startWith,
|
|
110
|
+
endWith,
|
|
111
|
+
max
|
|
112
|
+
) => {
|
|
113
|
+
try {
|
|
114
|
+
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
115
|
+
let response = await axios.get(
|
|
116
|
+
`https://api.datamuse.com/words?lc=${word}&${optionalParams}`
|
|
117
|
+
);
|
|
118
|
+
return decorateWords(partOfSpeech, transformToArray, response);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error(err);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Generate words that have right context of input word
|
|
126
|
+
* @param {String} word The input word
|
|
127
|
+
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
128
|
+
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
129
|
+
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
130
|
+
* @param {String} startWith Optional param to specify what returned words should start with
|
|
131
|
+
* @param {String} endWith Optional param to specify what returned words should end with
|
|
132
|
+
* @param {String} max Optional param to specify number of returned words
|
|
133
|
+
*/
|
|
134
|
+
const generateWordHasRightContext = async (
|
|
135
|
+
word,
|
|
136
|
+
transformToArray = false,
|
|
137
|
+
partOfSpeech,
|
|
138
|
+
topics,
|
|
139
|
+
startWith,
|
|
140
|
+
endWith,
|
|
141
|
+
max
|
|
142
|
+
) => {
|
|
143
|
+
try {
|
|
144
|
+
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
145
|
+
let response = await axios.get(
|
|
146
|
+
`https://api.datamuse.com/words?rc=${word}&${optionalParams}`
|
|
147
|
+
);
|
|
148
|
+
return decorateWords(partOfSpeech, transformToArray, response);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.error(err);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
module.exports = {
|
|
154
|
+
generateWordMeansLike,
|
|
155
|
+
generateWordSoundsLike,
|
|
156
|
+
generateWordSpelledLike,
|
|
157
|
+
generateWordHasLeftContext,
|
|
158
|
+
generateWordHasRightContext,
|
|
159
|
+
};
|
package/index.js
CHANGED
|
@@ -1,155 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
9
|
-
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
10
|
-
* @param {String} startWith Optional param to specify what returned words should start with
|
|
11
|
-
* @param {String} endWith Optional param to specify what returned words should end with
|
|
12
|
-
* @param {String} max Optional param to specify number of returned words
|
|
13
|
-
*/
|
|
14
|
-
const generateWordMeansLike = async (
|
|
15
|
-
word,
|
|
16
|
-
transformToArray = false,
|
|
17
|
-
partOfSpeech,
|
|
18
|
-
topics,
|
|
19
|
-
startWith,
|
|
20
|
-
endWith,
|
|
21
|
-
max
|
|
22
|
-
) => {
|
|
23
|
-
try {
|
|
24
|
-
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
25
|
-
let response = await axios.get(
|
|
26
|
-
`https://api.datamuse.com/words?ml=${word}&${optionalParams}`
|
|
27
|
-
);
|
|
28
|
-
return decorateWords(partOfSpeech, transformToArray, response);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
console.error(err);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Generate words that sounds like input word
|
|
36
|
-
* @param {String} word The input word
|
|
37
|
-
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
38
|
-
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
39
|
-
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
40
|
-
* @param {String} startWith Optional param to specify what returned words should start with
|
|
41
|
-
* @param {String} endWith Optional param to specify what returned words should end with
|
|
42
|
-
* @param {String} max Optional param to specify number of returned words
|
|
43
|
-
*/
|
|
44
|
-
const generateWordSoundsLike = async (
|
|
45
|
-
word,
|
|
46
|
-
transformToArray = false,
|
|
47
|
-
partOfSpeech,
|
|
48
|
-
topics,
|
|
49
|
-
startWith,
|
|
50
|
-
endWith,
|
|
51
|
-
max
|
|
52
|
-
) => {
|
|
53
|
-
try {
|
|
54
|
-
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
55
|
-
let response = await axios.get(
|
|
56
|
-
`https://api.datamuse.com/words?sl=${word}&${optionalParams}`
|
|
57
|
-
);
|
|
58
|
-
return decorateWords(partOfSpeech, transformToArray, response);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.error(err);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Generate words that spelled like input word
|
|
66
|
-
* @param {String} word The input word
|
|
67
|
-
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
68
|
-
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
69
|
-
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
70
|
-
* @param {String} startWith Optional param to specify what returned words should start with
|
|
71
|
-
* @param {String} endWith Optional param to specify what returned words should end with
|
|
72
|
-
* @param {String} max Optional param to specify number of returned words
|
|
73
|
-
*/
|
|
74
|
-
const generateWordSpelledLike = async (
|
|
75
|
-
word,
|
|
76
|
-
transformToArray = false,
|
|
77
|
-
partOfSpeech,
|
|
78
|
-
topics,
|
|
79
|
-
startWith,
|
|
80
|
-
endWith,
|
|
81
|
-
max
|
|
82
|
-
) => {
|
|
83
|
-
try {
|
|
84
|
-
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
85
|
-
let response = await axios.get(
|
|
86
|
-
`https://api.datamuse.com/words?sp=${word}&${optionalParams}`
|
|
87
|
-
);
|
|
88
|
-
return decorateWords(partOfSpeech, transformToArray, response);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.error(err);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Generate words that have left context of input word
|
|
96
|
-
* @param {String} word The input word
|
|
97
|
-
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
98
|
-
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
99
|
-
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
100
|
-
* @param {String} startWith Optional param to specify what returned words should start with
|
|
101
|
-
* @param {String} endWith Optional param to specify what returned words should end with
|
|
102
|
-
* @param {String} max Optional param to specify number of returned words
|
|
103
|
-
*/
|
|
104
|
-
const generateWordHasLeftContext = async (
|
|
105
|
-
word,
|
|
106
|
-
transformToArray = false,
|
|
107
|
-
partOfSpeech,
|
|
108
|
-
topics,
|
|
109
|
-
startWith,
|
|
110
|
-
endWith,
|
|
111
|
-
max
|
|
112
|
-
) => {
|
|
113
|
-
try {
|
|
114
|
-
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
115
|
-
let response = await axios.get(
|
|
116
|
-
`https://api.datamuse.com/words?lc=${word}&${optionalParams}`
|
|
117
|
-
);
|
|
118
|
-
return decorateWords(partOfSpeech, transformToArray, response);
|
|
119
|
-
} catch (err) {
|
|
120
|
-
console.error(err);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
1
|
+
const {
|
|
2
|
+
generateWordMeansLike,
|
|
3
|
+
generateWordSoundsLike,
|
|
4
|
+
generateWordSpelledLike,
|
|
5
|
+
generateWordHasLeftContext,
|
|
6
|
+
generateWordHasRightContext,
|
|
7
|
+
} = require("./generators");
|
|
123
8
|
|
|
124
|
-
/**
|
|
125
|
-
* Generate words that have right context of input word
|
|
126
|
-
* @param {String} word The input word
|
|
127
|
-
* @param {Boolean} transformToArray Specify if true then return type array of words otherwise array of objects include extra details
|
|
128
|
-
* @param {String} partOfSpeech Optional param to specify the part-Of-Speech of returned words 'n' for nouns, 'v' for verbs, 'adj' for adjectives and 'adv' for adverbs
|
|
129
|
-
* @param {String} topics Optional param to specify which category of the returned words belong to
|
|
130
|
-
* @param {String} startWith Optional param to specify what returned words should start with
|
|
131
|
-
* @param {String} endWith Optional param to specify what returned words should end with
|
|
132
|
-
* @param {String} max Optional param to specify number of returned words
|
|
133
|
-
*/
|
|
134
|
-
const generateWordHasRightContext = async (
|
|
135
|
-
word,
|
|
136
|
-
transformToArray = false,
|
|
137
|
-
partOfSpeech,
|
|
138
|
-
topics,
|
|
139
|
-
startWith,
|
|
140
|
-
endWith,
|
|
141
|
-
max
|
|
142
|
-
) => {
|
|
143
|
-
try {
|
|
144
|
-
const optionalParams = wordOptionalParams(topics, startWith, endWith, max);
|
|
145
|
-
let response = await axios.get(
|
|
146
|
-
`https://api.datamuse.com/words?rc=${word}&${optionalParams}`
|
|
147
|
-
);
|
|
148
|
-
return decorateWords(partOfSpeech, transformToArray, response);
|
|
149
|
-
} catch (err) {
|
|
150
|
-
console.error(err);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
9
|
module.exports = {
|
|
154
10
|
generateWordMeansLike,
|
|
155
11
|
generateWordSoundsLike,
|
package/logo-color.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
File without changes
|