Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Styro457 committed Nov 12, 2023
1 parent 9355e01 commit f0cab6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions scripts/apis/datamuse.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
function getRelatedWords(word, topics, firstLetter, lastLetter, limit, frequencyLimit, minLenght) {
return new Promise((resolve) => {
let url = "https://api.datamuse.com/words?ml=" + word + "&max=" + limit + "&md=df";

//Add topics to the api input if they are specified
if(topics !== null && topics.length > 0) {
let topicsString = topics[0];
for (let i = 1; i < Math.max(topics.length, 5); i++) {
topicsString = topicsString + "," + topics[i];
}
url = url + "&topics=" + topicsString;
}

//Get the api response
fetch("https://api.datamuse.com/words?ml=" + word + "&max=" + limit + "&md=df").then(response => {
return response.json()
}).then(data => {
Expand Down
6 changes: 5 additions & 1 deletion scripts/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ function checkWords(i) {
}

async function addResultsForKeyword(keywordsRaw) {
const keywords = keywordsRaw.split(/[\s,]+/);;
//Split the raw input into words. The words should be separated by commas
const keywords = keywordsRaw.split(/[\s,]+/);
console.log(keywords);

// Generate related words both with and without the other words set as topics
for(let i = 0; i < keywords.length; i++) {
await getRelatedWords(
keywords[i],
Expand All @@ -79,6 +82,7 @@ async function addResultsForKeyword(keywordsRaw) {
globalWords = globalWords.concat(words);
});
}

console.log(globalWords);
const seen = {};
globalWords = globalWords.filter(function(item) {
Expand Down

0 comments on commit f0cab6a

Please sign in to comment.