Commit 4ed171a2 authored by HashaniJayasinghe's avatar HashaniJayasinghe

finalized code of the component

parent f33417ec
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading 20news dataset. This may take a few minutes.\n",
"Downloading dataset from https://ndownloader.figshare.com/files/5975967 (14 MB)\n"
]
},
{
"data": {
"text/plain": [
"['alt.atheism',\n",
" 'comp.graphics',\n",
" 'comp.os.ms-windows.misc',\n",
" 'comp.sys.ibm.pc.hardware',\n",
" 'comp.sys.mac.hardware',\n",
" 'comp.windows.x',\n",
" 'misc.forsale',\n",
" 'rec.autos',\n",
" 'rec.motorcycles',\n",
" 'rec.sport.baseball',\n",
" 'rec.sport.hockey',\n",
" 'sci.crypt',\n",
" 'sci.electronics',\n",
" 'sci.med',\n",
" 'sci.space',\n",
" 'soc.religion.christian',\n",
" 'talk.politics.guns',\n",
" 'talk.politics.mideast',\n",
" 'talk.politics.misc',\n",
" 'talk.religion.misc']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Loading the necessary lobraries\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns; sns.set()\n",
"from sklearn.datasets import fetch_20newsgroups\n",
"data = fetch_20newsgroups()\n",
"data.target_names"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"From: dfo@vttoulu.tko.vtt.fi (Foxvog Douglas)\n",
"Subject: Re: Rewording the Second Amendment (ideas)\n",
"Organization: VTT\n",
"Lines: 58\n",
"\n",
"In article <1r1eu1$4t@transfer.stratus.com> cdt@sw.stratus.com (C. D. Tavares) writes:\n",
">In article <1993Apr20.083057.16899@ousrvr.oulu.fi>, dfo@vttoulu.tko.vtt.fi (Foxvog Douglas) writes:\n",
">> In article <1qv87v$4j3@transfer.stratus.com> cdt@sw.stratus.com (C. D. Tavares) writes:\n",
">> >In article <C5n3GI.F8F@ulowell.ulowell.edu>, jrutledg@cs.ulowell.edu (John Lawrence Rutledge) writes:\n",
">\n",
">> >> The massive destructive power of many modern weapons, makes the\n",
">> >> cost of an accidental or crimial usage of these weapons to great.\n",
">> >> The weapons of mass destruction need to be in the control of\n",
">> >> the government only. Individual access would result in the\n",
">> >> needless deaths of millions. This makes the right of the people\n",
">> >> to keep and bear many modern weapons non-existant.\n",
"\n",
">> >Thanks for stating where you're coming from. Needless to say, I\n",
">> >disagree on every count.\n",
"\n",
">> You believe that individuals should have the right to own weapons of\n",
">> mass destruction? I find it hard to believe that you would support a \n",
">> neighbor's right to keep nuclear weapons, biological weapons, and nerve\n",
">> gas on his/her property. \n",
"\n",
">> If we cannot even agree on keeping weapons of mass destruction out of\n",
">> the hands of individuals, can there be any hope for us?\n",
"\n",
">I don't sign any blank checks.\n",
"\n",
"Of course. The term must be rigidly defined in any bill.\n",
"\n",
">When Doug Foxvog says \"weapons of mass destruction,\" he means CBW and\n",
">nukes. When Sarah Brady says \"weapons of mass destruction\" she means\n",
">Street Sweeper shotguns and semi-automatic SKS rifles. \n",
"\n",
"I doubt she uses this term for that. You are using a quote allegedly\n",
"from her, can you back it up?\n",
"\n",
">When John\n",
">Lawrence Rutledge says \"weapons of mass destruction,\" and then immediately\n",
">follows it with:\n",
"\n",
">>> The US has thousands of people killed each year by handguns,\n",
">>> this number can easily be reduced by putting reasonable restrictions\n",
">>> on them.\n",
"\n",
">...what does Rutledge mean by the term?\n",
"\n",
"I read the article as presenting first an argument about weapons of mass\n",
"destruction (as commonly understood) and then switching to other topics.\n",
"The first point evidently was to show that not all weapons should be\n",
"allowed, and then the later analysis was, given this understanding, to\n",
"consider another class.\n",
"\n",
">cdt@rocket.sw.stratus.com --If you believe that I speak for my company,\n",
">OR cdt@vos.stratus.com write today for my special Investors' Packet...\n",
"\n",
"\n",
"\n",
"-- \n",
"doug foxvog\n",
"douglas.foxvog@vtt.fi\n",
"\n"
]
}
],
"source": [
"# defining all the categories\n",
"categories = ['alt.atheism','comp.graphics','comp.os.ms-windows.misc','comp.sys.ibm.pc.hardware','comp.sys.mac.hardware',\n",
" 'comp.windows.x','misc.forsale','rec.autos','rec.motorcycles','rec.sport.baseball','rec.sport.hockey','sci.crypt',\n",
" 'sci.electronics','sci.med','sci.space','soc.religion.christian','talk.politics.guns','talk.politics.mideast',\n",
" 'talk.politics.misc','talk.religion.misc']\n",
"\n",
"# Training the data on these categories\n",
"train = fetch_20newsgroups(subset='train', categories=categories)\n",
"# Testing data\n",
"test = fetch_20newsgroups(subset='test', categories=categories)\n",
"\n",
"print(train.data[5])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Terrestrial plants obtain water from soil for photosynthesis. Water in the soil is
absorbed through root hairs by osmosis. The absorbed water then travels into
root xylem through cortex and endodermis. From there water is transported into
mesophyll cells of leaves via the xylem of stem and the veins of leaves. The network
of veins in the leaves distribute water throughout the leaf.
\ No newline at end of file
The highest proportion of the body mass of living organisms is composed of water
which is an inorganic compound. 2/3 rd of the body weight of most of oranisms is
by water. water is an essential medium for the maintenance of living matter. The
table below, shows the specific properties of water and contribution of them to the
maintenance of life.
import MySQLdb
host = "localhost"
user = "root"
pwd = "MySQL_123@root"
db = "eduhelp"
port = 3306
def connection():
try:
conn = MySQLdb.connect(host=host, user=user, password=pwd, db=db)
return conn
except Exception as error:
print('MYSQL DB connection failed '+str(error))
const express = require("express");
const app = express();
const cors = require("cors");
const PORT = 3001;
app.use(express.json());
app.use(cors());
const uploadRoute = require("./routes/upload");
app.use("/upload", uploadRoute);
app.listen(PORT, () => {
console.log(`Server Running on Port ${PORT}...`);
});
This diff is collapsed.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devStart": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"fs": "0.0.1-security",
"line-reader": "^0.4.0",
"multer": "^1.4.3",
"mysql": "^2.18.1",
"mysql2": "^2.2.2",
"nodemon": "^2.0.4",
"path": "^0.12.7",
"sequelize": "^6.3.5",
"sequelize-cli": "^6.2.0"
}
}
import sys
import argparse
from question_generator import QuestionGenerator
import os
current_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
def add_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--sentence', type=str, help="The sentence for which questions are to be generated.")
parser.add_argument('-t', '--question_type', type=str, default=['Wh', 'Are', 'Who', 'Do'], choices=['Wh', 'Are', 'Who', 'Do', 'All'], help='The types of questions to be generated.')
return parser.parse_args()
def createQuestions(inputText):
# args = add_arguments()
# if not args.s:
# sys.stdout.write('No input given\n')
# sys.exit()
q = QuestionGenerator()
question_list = q.generate_question(inputText)
qList = []
aList = []
shortAList = []
for row in question_list:
if row['Q'].startswith('Does') or row['Q'].startswith('Do'):
break
else:
q = row['Q']
a = row['A']
a_no = ''
q_no = ''
# remove punctuation from the string
for char in a:
if char not in punctuations:
a_no += char
for char in q:
if char not in punctuations:
q_no += char
splitA = a_no.split(" ")
shortA = ""
for a in splitA:
if a not in q_no:
shortA += a + " "
qList.append(row['Q'])
aList.append(row['A'])
shortAList.append(shortA)
return qList,aList,shortAList
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "MySQL_123@root",
database : 'eduhelp'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
\ No newline at end of file
const { spawn } = require("child_process");
const express = require("express");
const route = express.Router();
const multer = require('multer')
const path = require('path')
const fs = require('fs');
var mysql = require('mysql2');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "MySQL_123@root",
database : 'eduhelp'
});
const storage = multer.diskStorage({
destination: "./Docs",
filename: (req, file,cb) => {
cb(null, file.originalname)
}
})
const upload = multer({
storage: storage
}).single('doc')
const docFolder = './Docs';
const docFolderN = './Docs/notices';
const docFolder10 = './Docs/grade10';
const docFolder11 = './Docs/grade11';
route.post('/doc', upload,(req, res) => {
console.log(req.file.originalname)
// await sleep(10);
var content = ""
fs.readFile(docFolder+"/10_sceince.txt", { encoding: 'utf8' } , (err, data) => {
if (err) {
console.error(err)
return
}
content = data
})
const { spawn } = require('child_process');
const pyProg = spawn('python', ['categorize.py', req.file.originalname, content]);
pyProg.stdout.on('data', function(data) {
console.log(data.toString());
// res.write(data);
// res.end('end');
});
res.send("success");
})
route.post('/getDocs', (req, res) =>{
var id = req.body.id;
var path;
if(id == 1){
path = docFolderN
}else if(id == 10){
path = docFolder10
}else{
path = docFolder11
}
var files_list = []
fs.readdir(path, (err, files) => {
files.forEach(file => {
files_list.push(file.split('.')[0])
});
console.log(files_list)
res.send(files_list);
});
})
route.post('/getDocsData', (req, res) =>{
var id = req.body.id;
var folder = req.body.folder;
var path;
if(folder == 1){
path = docFolderN
}else if(folder == 10){
path = docFolder10
}else{
path = docFolder11
}
fs.readFile(path+'/'+req.body.id+'.txt', { encoding: 'utf8' } , (err, data) => {
if (err) {
console.error(err)
return
}
res.send(data);
})
})
route.post('/login', function(request, response) {
var username = request.body.uname;
var password = request.body.pwd;
if (username && password) {
con.query('SELECT utype FROM users WHERE uname = ? AND pwd = ?', [username, password], function(error, results, fields) {
if (results.length > 0) {
response.send(results);
} else {
response.send('Incorrect Username and/or Password!');
}
response.end();
});
} else {
response.send('Please enter Username and Password!');
response.end();
}
});
module.exports = route;
\ No newline at end of file
File added
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment