Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AI-Powered Automated Paper Matching #357

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions backend/paper_matching/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require('express');
const { getPaperRecommendations } = require('./paperMatcher');
const router = express.Router();

router.get('/recommendations', async (req, res) => {
const userId = req.user.id; // Assuming user ID is available in the request
try {
const recommendations = await getPaperRecommendations(userId);
res.status(200).json(recommendations);
} catch (error) {
res.status(500).send('Internal Server Error');
}
});

module.exports = router;
47 changes: 47 additions & 0 deletions backend/paper_matching/paperMatcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const natural = require('natural');
const db = require('../config/mysql_connection');

// Function to preprocess text
const preprocessText = (text) => {
return text.toLowerCase().replace(/[^a-z0-9\s]/g, '').trim();
};

// Function to calculate similarity between two texts
const calculateSimilarity = (text1, text2) => {
const tokenizer = new natural.WordTokenizer();
const words1 = tokenizer.tokenize(preprocessText(text1));
const words2 = tokenizer.tokenize(preprocessText(text2));
const tfidf = new natural.TfIdf();

tfidf.addDocument(words1);
tfidf.addDocument(words2);

return tfidf.tfidfs[0][1]; // Similarity score between documents
};

// Function to get paper recommendations for a user
const getPaperRecommendations = async (userId) => {
try {
const userQuery = `SELECT interests FROM info_table WHERE id=?`;
const userProfile = await db.query(userQuery, [userId]);
const userInterests = userProfile[0].interests;

const papersQuery = `SELECT * FROM upload_file_db`;
const papers = await db.query(papersQuery);

const recommendations = papers.map(paper => {
const similarity = calculateSimilarity(userInterests, paper.filename); // Assuming filename contains relevant information
return { paper, similarity };
});

// Sort papers based on similarity score
recommendations.sort((a, b) => b.similarity - a.similarity);

return recommendations.slice(0, 5); // Return top 5 recommendations
} catch (error) {
console.error("Error fetching paper recommendations:", error);
throw error;
}
};

module.exports = { getPaperRecommendations };
1 change: 0 additions & 1 deletion config/mysql_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function initializeConnection() {
db.getConnection((err, connection) => {
if (err) {
console.error("Error connecting to the database:", err.message);
// Add any error tracking system call here (e.g., Sentry, Logstash)
} else {
console.log("Successfully connected to the database with ID:", connection.threadId);
connection.release(); // Release connection after success
Expand Down
21 changes: 16 additions & 5 deletions file_upload/form_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const info = (req, res) => {
const course = req.body.course.trim();
const year = req.body.year;
const dept = req.body.dept.trim();
const interests = req.body.interests ? req.body.interests.trim() : null; // Extract interests

db.getConnection(async (err, connection) => {
if (err) throw err;
Expand All @@ -43,8 +44,8 @@ const info = (req, res) => {
}

// Proceed to insert the data if the email does not exist
const sql = "INSERT INTO info_table VALUES (?,?,?,?,?,?,?)";
const sqlInsert = mysql.format(sql, [userid,name,email,col_name,state,year,course]);
const sql = "INSERT INTO info_table VALUES (?,?,?,?,?,?,?,?)"; // Add interests to the insert statement
const sqlInsert = mysql.format(sql, [userid, name, email, col_name, state, year, course, interests]); // Include interests

await connection.query(sqlInsert, async (err, result) => {
if (err) {
Expand All @@ -69,20 +70,30 @@ const check = (req, res) => {
const userid = decodedtoken.user;
db.getConnection(async (err, connection) => {
if (err) throw err;
const search = "SELECT * FROM info_table where id=?";
const search = "SELECT * FROM info_table WHERE id=?";
const searchquery = mysql.format(search, [userid]);
await connection.query(searchquery, async (err, result) => {
if (err) throw err;
if (result.length != 0) {
console.log("info checked");
res.sendStatus(201);
// Optionally, you can return the interests here as well
res.status(200).json({
name: result[0].name,
email: result[0].email,
col_name: result[0].col_name,
state: result[0].state,
year: result[0].year,
course: result[0].course,
interests: result[0].interests // Include interests in the response
});
connection.release();
} else {
connection.release();
res.sendStatus(404); // Respond with 404 if no user info found
}
});
});
};

// exporting info
module.exports = { info, check };
module.exports = { info, check };
2 changes: 2 additions & 0 deletions login-system/dbServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { stk_display } = require("../backend/stk_profile");
const { logout } = require("./logout");
const { setcriteria, evaluate } = require("../stakeholder/evaluation");
const { allot, DisplayPapers } = require("../stakeholder/allotment");
const paperMatchingApi = require('../paper_matching/api');
const { Dis_fac_papers, fac_signup, fac_login, dis_mail, giverating } = require("../stakeholder/faculty");
const app = express();

Expand Down Expand Up @@ -153,6 +154,7 @@ app.get("/stk_profile_detail", stk_display);

// starting the app on port
const port = process.env.PORT || 3000;
app.use('/api/paper_matching', paperMatchingApi);
app.listen(port, () =>
console.log(`Server Started on port http://localhost:${port}`)
);
Loading