Skip to content

Commit ef62da7

Browse files
committed
initializing Project
0 parents  commit ef62da7

File tree

14 files changed

+7052
-0
lines changed

14 files changed

+7052
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true,
6+
"node": true
7+
},
8+
"extends": [
9+
"airbnb-base"
10+
],
11+
"parserOptions": {
12+
"ecmaVersion": "latest"
13+
},
14+
"rules": {
15+
"eqeqeq": "off",
16+
"no-promise-executor-return": "off",
17+
"no-param-reassign": "off",
18+
"no-unused-vars": "off",
19+
"no-plusplus": "off",
20+
"no-console": "off"
21+
}
22+
}

.gitattributes

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Common settings that generally should always be used with your language specific settings
2+
3+
# Auto detect text files and perform LF normalization
4+
* text=auto
5+
6+
#
7+
# The above will handle all files NOT found below
8+
#
9+
10+
# Documents
11+
*.bibtex text diff=bibtex
12+
*.doc diff=astextplain
13+
*.DOC diff=astextplain
14+
*.docx diff=astextplain
15+
*.DOCX diff=astextplain
16+
*.dot diff=astextplain
17+
*.DOT diff=astextplain
18+
*.pdf diff=astextplain
19+
*.PDF diff=astextplain
20+
*.rtf diff=astextplain
21+
*.RTF diff=astextplain
22+
*.md text diff=markdown
23+
*.mdx text diff=markdown
24+
*.tex text diff=tex
25+
*.adoc text
26+
*.textile text
27+
*.mustache text
28+
*.csv text
29+
*.tab text
30+
*.tsv text
31+
*.txt text
32+
*.sql text
33+
34+
# Graphics
35+
*.png binary
36+
*.jpg binary
37+
*.jpeg binary
38+
*.gif binary
39+
*.tif binary
40+
*.tiff binary
41+
*.ico binary
42+
# SVG treated as text by default.
43+
*.svg text
44+
# If you want to treat it as binary,
45+
# use the following line instead.
46+
# *.svg binary
47+
*.eps binary
48+
49+
# Scripts
50+
*.bash text eol=lf
51+
*.fish text eol=lf
52+
*.sh text eol=lf
53+
*.zsh text eol=lf
54+
# These are explicitly windows files and should use crlf
55+
*.bat text eol=crlf
56+
*.cmd text eol=crlf
57+
*.ps1 text eol=crlf
58+
59+
# Serialisation
60+
*.json text
61+
*.toml text
62+
*.xml text
63+
*.yaml text
64+
*.yml text
65+
66+
# Archives
67+
*.7z binary
68+
*.gz binary
69+
*.tar binary
70+
*.tgz binary
71+
*.zip binary
72+
73+
# Text files where line endings should be preserved
74+
*.patch -text
75+
76+
#
77+
# Exclude files from exporting
78+
#
79+
80+
.gitattributes export-ignore
81+
.gitignore export-ignore
82+
.gitkeep export-ignore

.gitignore

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
temp
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
.pnpm-debug.log*
11+
temp
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# Snowpack dependency directory (https://snowpack.dev/)
49+
web_modules/
50+
51+
# TypeScript cache
52+
*.tsbuildinfo
53+
54+
# Optional npm cache directory
55+
.npm
56+
57+
# Optional eslint cache
58+
.eslintcache
59+
60+
# Optional stylelint cache
61+
.stylelintcache
62+
63+
# Microbundle cache
64+
.rpt2_cache/
65+
.rts2_cache_cjs/
66+
.rts2_cache_es/
67+
.rts2_cache_umd/
68+
69+
# Optional REPL history
70+
.node_repl_history
71+
72+
# Output of 'npm pack'
73+
*.tgz
74+
75+
# Yarn Integrity file
76+
.yarn-integrity
77+
78+
# dotenv environment variable files
79+
.env
80+
.env.development.local
81+
.env.test.local
82+
.env.production.local
83+
.env.local
84+
85+
# parcel-bundler cache (https://parceljs.org/)
86+
.cache
87+
.parcel-cache
88+
89+
# Next.js build output
90+
.next
91+
out
92+
93+
# Nuxt.js build / generate output
94+
.nuxt
95+
dist
96+
97+
# Gatsby files
98+
.cache/
99+
# Comment in the public line in if your project uses Gatsby and not Next.js
100+
# https://nextjs.org/blog/next-9-1#public-directory-support
101+
# public
102+
103+
# vuepress build output
104+
.vuepress/dist
105+
106+
# vuepress v2.x temp and cache directory
107+
.temp
108+
.cache
109+
110+
# Docusaurus cache and generated files
111+
.docusaurus
112+
113+
# Serverless directories
114+
.serverless/
115+
116+
# FuseBox cache
117+
.fusebox/
118+
119+
# DynamoDB Local files
120+
.dynamodb/
121+
122+
# TernJS port file
123+
.tern-port
124+
125+
# Stores VSCode versions used for testing VSCode extensions
126+
.vscode-test
127+
128+
# yarn v2
129+
.yarn/cache
130+
.yarn/unplugged
131+
.yarn/build-state.yml
132+
.yarn/install-state.gz
133+
.pnp.*
134+
135+
results/*.txt
136+
result_*.txt

.gitpod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tasks:
2+
- init: npm install
3+
command: npm start

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"eslint.format.enable": true,
3+
"files.exclude": {
4+
".gitattributes": true,
5+
".gitpod.yml": true,
6+
"LICENSE": true,
7+
"node_modules": true,
8+
"package-lock.json": true
9+
}
10+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Prateek Singh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

index.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
const MainChat = require("./intents/Main_Chat.json");
2+
const WelcomeChat = require("./intents/Default_Welcome.json");
3+
const FallbackChat = require("./intents/Default_Fallback.json");
4+
const unitConverterChat = require("./intents/unit_converter.json").qus;
5+
6+
const stringSimilarity = require("string-similarity");
7+
const _ = require('lodash');
8+
const { upperCaseFirst } = require("upper-case-first");
9+
const extractValues = require("extract-values");
10+
11+
const cors = require("cors");
12+
const express = require("express");
13+
const compression = require("compression");
14+
const rateLimit = require("express-rate-limit");
15+
const morgan = require("morgan");
16+
17+
const app = express();
18+
const port = process.env.PORT || 3000;
19+
20+
var allQustions = [];
21+
var answer = {};
22+
var humanInput = "how are you";
23+
24+
for (let i = 0; i < MainChat.length; i++) {
25+
for (let j = 0; j < MainChat[i]["qus"].length; j++) {
26+
allQustions.push(MainChat[i]["qus"][j])
27+
}
28+
}
29+
30+
const sendAllQuestions = (req, res) => {
31+
var humanQuestions = [];
32+
33+
allQustions.forEach(qus => {
34+
if (qus.length >= 10) {
35+
if (/^(can|are|may|how|what|when|who|do|where|your|from|is|will|why)/gi.test(qus)) {
36+
humanQuestions.push(upperCaseFirst(qus) + "?");
37+
} else {
38+
humanQuestions.push(upperCaseFirst(qus) + '.');
39+
}
40+
}
41+
});
42+
res.json(_.shuffle(humanQuestions))
43+
}
44+
45+
const sendWelcomeMessage = (req, res) => {
46+
res.json({ responseText: _.sample(WelcomeChat) })
47+
}
48+
49+
const sendAnswer = (req, res) => {
50+
51+
var isFallback = false;
52+
var responseText = 'n/a';
53+
var rating = 0;
54+
var similarQuestion = 'n/a';
55+
var action;
56+
57+
let query = req.query.q;
58+
let humanInput = query.replace(/(\?|\.)$/gm, "v");
59+
let regExforUnitConverter = /(convert|change).{1,2}(\d{1,8})/gm;
60+
61+
if (regExforUnitConverter.test(humanInput)) {
62+
63+
let similarQuestionObj = stringSimilarity.findBestMatch(humanInput, unitConverterChat).bestMatch;
64+
let valuesObj = extractValues(humanInput, similarQuestionObj.target, { delimiters: ["%", "%"] });
65+
66+
const { amount, unit_from, unit_to } = valuesObj;
67+
console.log(amount, unit_from, unit_to);
68+
69+
} else {
70+
71+
let similarQuestionObj = stringSimilarity.findBestMatch(humanInput, allQustions).bestMatch;
72+
let similarQuestionRating = similarQuestionObj.rating;
73+
similarQuestion = similarQuestionObj.target;
74+
75+
if (similarQuestionRating > 0.5) {
76+
for (let i = 0; i < MainChat.length; i++) {
77+
for (let j = 0; j < MainChat[i]["qus"].length; j++) {
78+
if (similarQuestion == MainChat[i]["qus"][j]) {
79+
responseText = _.sample(MainChat[i]["ans"]);
80+
rating = similarQuestionRating;
81+
}
82+
}
83+
}
84+
} else {
85+
responseText = _.sample(FallbackChat);
86+
isFallback = true;
87+
}
88+
}
89+
90+
res.json({
91+
responseText,
92+
rating,
93+
similarQuestion,
94+
isFallback
95+
});
96+
}
97+
98+
app.use(cors());
99+
app.use(compression());
100+
app.use("/api/*", morgan("tiny"));
101+
app.get("/api/allQuestions", sendAllQuestions);
102+
app.get("/api/welcome", sendWelcomeMessage);
103+
app.get("/api/question", sendAnswer);
104+
105+
app.listen(port, () => console.log(`app listening on port ${port}!`));

0 commit comments

Comments
 (0)