Commit 2b09c780 authored by Quentin's avatar Quentin
Browse files

Transformed some functions into async functions

CHanged failHandlers to errorHandlers
Adding functions to handle processes
Fixedan error in SDMC json
parent a02a25e8
...@@ -94,26 +94,24 @@ export default { ...@@ -94,26 +94,24 @@ export default {
} }
}, },
// Post and start the corpus process given the corpus and the pipeline // Post and start the corpus process given the corpus and the pipeline
submitCorpusProcess() { async submitCorpusProcess() {
const data = { const data = {
corpusId: sessionStorage.getItem('corpusId'), corpusId: sessionStorage.getItem('corpusId'),
pipelineId: sessionStorage.getItem('pipelineId'), pipelineId: sessionStorage.getItem('pipelineId'),
userId:'5f60db3f30dee22c7d6f6058' // DUMMY ID userId:'5f60db3f30dee22c7d6f6058' // DUMMY ID
} }
axios.post('/corpusProcesses', data) try {
.then( res => { // Create corpus process
if (res.data.status !== "success") { const res = await axios.post('/corpusProcesses', data);
console.error(res.data.message); const corpusProcessId = res.data.data.corpusProcess._id;
this.errorMessage = res.data.message; // Starts it
} await axios.post(`/corpusProcesses/${corpusProcessId}/start`);
else { this.$router.push('/validation');
this.$router.push('/validation'); }
} catch (error) {
})
.catch( error => {
console.error(error); console.error(error);
this.errorMessage = error; this.errorMessage = error;
}) }
} }
}, },
components: { components: {
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
{ {
"name": "motif_representation", "name": "motif_representation",
"label": "Représentation condensée des motifs", "label": "Représentation condensée des motifs",
"description": null, "description": "Trois types d'extraction vous sont proposées :\n\t\t- Fréquents : retourne tout les motifs qui apparaissent plus que le support minimal.\n\t\t-Fermés : ne retourne pas les sous motifs de même ou plus petite fréquence\n\t\tco- Maximaux : ne retourne aucun sous motifs",
"type": "List-Mono", "type": "List-Mono",
"items": ["Fermés (tous les motifs)", "Fermés (sans sous-motifs de même fréquence)", "items": ["Fréquents (tous les motifs)", "Fermés (sans sous-motifs de même fréquence)",
"Maximaux (en ôtant les sous-motifs)"], "Maximaux (en ôtant les sous-motifs)"],
"default": "Fermés (tous les motifs)" "default": "Fréquents (tous les motifs)"
}, },
{ {
"name": "minimal_gap", "name": "minimal_gap",
...@@ -45,6 +45,22 @@ ...@@ -45,6 +45,22 @@
"items": null, "items": null,
"default": "100" "default": "100"
}, },
{
"name": "minimal_size",
"label": "Taille minimale",
"description": "Nombre minimal de tokens d'un motif extrait",
"type": "Int",
"items": null,
"default": "0"
},
{
"name": "maximal_size",
"label": "Taille maximale",
"description": "Nombre maximal de tokens d'un motif extrait",
"type": "Int",
"items": null,
"default": "5"
},
{ {
"name": "categories", "name": "categories",
"label": "Appartenance d'une ou plusieurs catégories", "label": "Appartenance d'une ou plusieurs catégories",
......
...@@ -13,16 +13,17 @@ const path = require('path'); ...@@ -13,16 +13,17 @@ const path = require('path');
const fs = require('fs'); const fs = require('fs');
// DEBUG: find all corpora // DEBUG: find all corpora
exports.debug_corpus_list = function(req, res) { exports.debug_corpus_list = async function (req, res) {
CorpusModel.find({},(error, corpora) => { try {
if (error) { errorHandler(res, error); } const corpora = await CorpusModel.find({});
else { successHandler(res, { corpora })
successHandler(res, { corpora: corpora } ); }
} catch (error) {
}) errorHandler(res, "debug_corpus_list: " + error);
}
} }
// Add a new corpus // Add a new corpus
exports.corpus_create = function(req,res) { exports.corpus_create = function (req, res) {
console.log("Demande d'ajout d'un corpus:") console.log("Demande d'ajout d'un corpus:")
console.log(req.body); console.log(req.body);
const newCorpus = CorpusModel({ const newCorpus = CorpusModel({
...@@ -45,28 +46,28 @@ exports.corpus_create = function(req,res) { ...@@ -45,28 +46,28 @@ exports.corpus_create = function(req,res) {
if (error) { errorHandler(res, error); } if (error) { errorHandler(res, error); }
else { else {
console.log("Successfully added the corpus") console.log("Successfully added the corpus")
successHandler(res, { corpus: corpus}, 201); successHandler(res, { corpus: corpus }, 201);
} }
}) })
} }
exports.corpus_file_upload = function(req, res) { exports.corpus_file_upload = function (req, res) {
if (!req.files) { if (!req.files) {
failHandler(res, { uploadedFiles: 'No files were found'}); errorHandler(res, 'corpus_file_upload: No files were sent');
} }
else { else {
let userId = req.body.userId; let userId = req.body.userId;
let files = req.files['file[]'] let files = req.files['file[]']
let resData = [] let resData = []
let uploadDirectory = path.join(__dirname, '/../uploads/corpora/', userId); let uploadDirectory = path.join(__dirname, '/../uploads/corpora/', userId);
if (!fs.existsSync(uploadDirectory)) { if (!fs.existsSync(uploadDirectory)) {
fs.mkdirSync(uploadDirectory); fs.mkdirSync(uploadDirectory);
} }
try { try {
if (files.length) { if (files.length) {
files.forEach( file => { files.forEach(file => {
let filePath = path.join(uploadDirectory, file.name); let filePath = path.join(uploadDirectory, file.name);
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
console.log(`File named ${file.name} already exists, replacing it`); console.log(`File named ${file.name} already exists, replacing it`);
...@@ -81,7 +82,7 @@ exports.corpus_file_upload = function(req, res) { ...@@ -81,7 +82,7 @@ exports.corpus_file_upload = function(req, res) {
console.log(`File named ${files.name} already exists, replacing it`); console.log(`File named ${files.name} already exists, replacing it`);
} }
files.mv(filePath); files.mv(filePath);
resData.push({ name: files.name, mimetype: files.mimetype, size: files.size, path: filePath}); resData.push({ name: files.name, mimetype: files.mimetype, size: files.size, path: filePath });
} }
successHandler(res, { uploadedFiles: resData }); successHandler(res, { uploadedFiles: resData });
} }
...@@ -91,51 +92,62 @@ exports.corpus_file_upload = function(req, res) { ...@@ -91,51 +92,62 @@ exports.corpus_file_upload = function(req, res) {
} }
} }
// Get an existing corpus // Get an existing corpus
exports.corpus_get = function(req,res) { exports.corpus_get = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = await CorpusModel.findById(corpusId);
if (!corpus) { if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404); errorHandler(res, `corpus_get: No corpus was found with id: ${corpusId}`, 404)
} }
else { else {
successHandler(res, { corpus: corpus}); successHandler(res, { corpus });
} }
}) }
catch (error) {
errorHandler(res, error);
}
} }
// Modify an existing corpus // Modify an existing corpus
exports.corpus_modify = function(req,res) { exports.corpus_modify = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findByIdAndUpdate(corpusId, req.body, (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = await CorpusModel.findByIdAndUpdate(corpusId, req.body);
if (!corpus) { if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404); errorHandler(res, `corpus_modify: No corpus was found with id: ${corpusId}`, 404);
} }
else { else {
successHandler(res, { corpus: corpus}); successHandler(res, { corpus });
} }
}) }
catch (error) {
errorHandler(res, error);
}
} }
// Delete an existing corpus // Delete an existing corpus
exports.corpus_delete = function(req,res) { exports.corpus_delete = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findByIdAndDelete(corpusId, (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = await CorpusModel.findByIdAndDelete(corpusId)
if (!corpus) { if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404); errorHandler(res, `corpus_delete: No corpus was found with id: ${corpusId}`, 404);
} }
else { else {
successHandler(res, { corpus: null}) successHandler(res, { corpus: null })
} }
}); }
catch (error) {
errorHandler(res, error);
}
} }
// Get a summary of an existing corpus // Get a summary of an existing corpus
exports.corpus_summary = function(req,res) { exports.corpus_summary = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = await CorpusModel.findById(corpusId);
if (!corpus) { if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404) failHandler(res, { corpus: `No corpus was found with id: ${corpusId}` }, 404)
} }
else { else {
// Almost the same than the model, except we only get the number of docs, and not its content. // Almost the same than the model, except we only get the number of docs, and not its content.
...@@ -149,39 +161,71 @@ exports.corpus_summary = function(req,res) { ...@@ -149,39 +161,71 @@ exports.corpus_summary = function(req,res) {
}; };
successHandler(res, { corpusSummary: corpusSummary }); successHandler(res, { corpusSummary: corpusSummary });
} }
}) }
catch (error) {
errorHandler(res, error);
}
}
// Get conllu of each documents in a corpus
// Merge it ?
exports.corpus_documents_get = async function (req,res) {
const corpusId = req.params.corpusId;
try {
const corpus = await CorpusModel.findById(corpusId);
if (!corpus) {
errorHandler(res,`corpus_documents_get: No corpus was found with id: ${corpusId}`, 404);
}
else {
let documentConlluList = []
corpus.documents.forEach(document => {
documentConlluList.push(
{ id: document._id, POStags: document.POStags,
lemmas: document.lemmas, tokens: document.tokens, tokensIdx: document.tokensIdx}
);
})
successHandler(res, { documentsConlluList: documentConlluList });
}
}
catch (error) {
errorHandler(res, error);
}
} }
// Get a specific document in a corpus // Get a specific document in a corpus
exports.corpus_document_get = function(req, res) { exports.corpus_document_get = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = await CorpusModel.findById(corpusId);
if (!corpus) { if (!corpus) {
errorHandler(res, `No corpus was found with id: ${corpusId}`, 404); errorHandler(res, `corpus_document_get: No corpus was found with id: ${corpusId}`, 404);
} }
else { else {
let found = false; let found = false;
const documentId = req.params.documentId; const documentId = req.params.documentId;
corpus.documents.forEach( document => { corpus.documents.forEach(document => {
if (document.id === documentId) { if (document.id === documentId) {
successHandler(res, { corpus: { document : document }}); successHandler(res, { corpus: { document: document } });
found = true; found = true;
} }
}); });
if (found) return; if (!found) {
else {
errorHandler(res, `No document found at this index: ${documentId}`, 404); errorHandler(res, `No document found at this index: ${documentId}`, 404);
} }
} }
}) }
catch (error) {
errorHandler(res, error);
}
} }
// Change a document in a corpus // Change a document in a corpus
exports.corpus_document_modify = function(req, res) { // NOT FINISHED
exports.corpus_document_modify = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, async (error, corpus) => { try {
if (error) { errorHandler(res, error); } const corpus = CorpusModel.findById(corpusId);
if (!corpus) { if (!corpus) {
errorHandler(res, `No corpus was found with id: ${corpusId}`, 404); errorHandler(res, `corpus_document_modify: No corpus was found with id: ${corpusId}`, 404);
} }
else { else {
const documentId = req.params.documentId; const documentId = req.params.documentId;
...@@ -192,7 +236,7 @@ exports.corpus_document_modify = function(req, res) { ...@@ -192,7 +236,7 @@ exports.corpus_document_modify = function(req, res) {
return; return;
} }
let found; let found;
corpus.documents.forEach( document => { corpus.documents.forEach(document => {
if (document.id === documentId) { if (document.id === documentId) {
document = Object.assign(document, conlluCol); document = Object.assign(document, conlluCol);
found = true; found = true;
...@@ -202,7 +246,7 @@ exports.corpus_document_modify = function(req, res) { ...@@ -202,7 +246,7 @@ exports.corpus_document_modify = function(req, res) {
if (found) { if (found) {
try { try {
let savedCorpus = await corpus.save(); let savedCorpus = await corpus.save();
successHandler(res, { message: `Successfully modified the document`}); successHandler(res, { message: `Successfully modified the document` });
} }
catch (error) { catch (error) {
errorHandler(res, error); errorHandler(res, error);
...@@ -212,11 +256,14 @@ exports.corpus_document_modify = function(req, res) { ...@@ -212,11 +256,14 @@ exports.corpus_document_modify = function(req, res) {
errorHandler(res, `No document was found with id: ${documentId}`); errorHandler(res, `No document was found with id: ${documentId}`);
} }
} }
}) }
catch (error) {
return;
}
} }
// Change a document in a corpus // Change a document in a corpus
exports.corpus_document_basic_process_add = async function(req, res) { exports.corpus_document_basic_process_add = async function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
const documentId = req.params.documentId; const documentId = req.params.documentId;
const basicProcessConlluCols = req.body; const basicProcessConlluCols = req.body;
...@@ -231,7 +278,7 @@ exports.corpus_document_basic_process_add = async function(req, res) { ...@@ -231,7 +278,7 @@ exports.corpus_document_basic_process_add = async function(req, res) {
return; return;
} }
let isDocumentFound; let isDocumentFound;
corpus.documents.forEach( document => { corpus.documents.forEach(document => {
if (document.id === documentId) { if (document.id === documentId) {
document = Object.assign(document, basicProcessConlluCols); document = Object.assign(document, basicProcessConlluCols);
isDocumentFound = true; isDocumentFound = true;
...@@ -243,17 +290,15 @@ exports.corpus_document_basic_process_add = async function(req, res) { ...@@ -243,17 +290,15 @@ exports.corpus_document_basic_process_add = async function(req, res) {
return; return;
} }
let savedCorpus = await corpus.save(); let savedCorpus = await corpus.save();
successHandler(res, { message: `Successfully modified the document`}); successHandler(res, { message: `Successfully modified the document` });
} }
catch (error) { catch (error) {
errorHandler(res, error); errorHandler(res, error);
} }
} }
// Get a specific report from a document in a corpus // Get a specific report from a document in a corpus
exports.corpus_document_report_get = function(req, res) { exports.corpus_document_report_get = function (req, res) {
const corpusId = req.params.corpusId; const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => { CorpusModel.findById(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); } if (error) { errorHandler(res, error); }
...@@ -265,12 +310,12 @@ exports.corpus_document_report_get = function(req, res) { ...@@ -265,12 +310,12 @@ exports.corpus_document_report_get = function(req, res) {
const document = corpus.documents[documentId]; const document = corpus.documents[documentId];
if (!document) { if (!document) {
failHandler(res, { corpus: { document: `No document found at this index: ${documentId}`}}, 404); failHandler(res, { corpus: { document: `No document found at this index: ${documentId}` } }, 404);
} }
else { else {
// Get the report here // Get the report here
// const report = document.report[...]; // const report = document.report[...];
successHandler(res, { corpus: { document: document}}); successHandler(res, { corpus: { document: document } });
} }
} }
}) })
......
...@@ -2,25 +2,24 @@ ...@@ -2,25 +2,24 @@
// Corpus Process Controller file // Corpus Process Controller file
// *** // ***
const CorpusProcessModel = require('../models/CorpusProcess.js')['CorpusProcessModel']; const { CorpusProcessModel } = require('../models/CorpusProcess.js');
const PipelineModel = require('../models/Pipeline.js');
const CorpusProcess = require('../models/CorpusProcess.js'); const CorpusProcess = require('../models/CorpusProcess.js');
const responseHelper = require('./lib/responseHelper'); const { errorHandler, successHandler } = require('./lib/responseHelper');
const errorHandler = responseHelper.errorHandler; const moduleHelper = require('./lib/moduleHelper.js');
const successHandler = responseHelper.successHandler;
const failHandler = responseHelper.failHandler; // For eg. "User not found" is a fail, not an error
// DEBUG: find all corpus processes // DEBUG: find all corpus processes
exports.debug_corpus_process_list = function(req, res) { exports.debug_corpus_process_list = function (req, res) {
CorpusProcessModel.find({},(error, corpusProcesses) => { CorpusProcessModel.find({}, (error, corpusProcesses) => {
if (error) { errorHandler(res, error); } if (error) { errorHandler(res, error); }
else { else {
successHandler(res, { corpusProcesses: corpusProcesses } ); successHandler(res, { corpusProcesses: corpusProcesses });
} }
}) })
} }
// Add a new corpus process // Add a new corpus process
exports.corpus_process_create = function(req,res) { exports.corpus_process_create = function (req, res) {
const newCorpusProcess = CorpusProcessModel({ const newCorpusProcess = CorpusProcessModel({
corpusId: req.body.corpusId, corpusId: req.body.corpusId,
pipelineId: req.body.pipelineId, pipelineId: req.body.pipelineId,
...@@ -30,87 +29,170 @@ exports.corpus_process_create = function(req,res) { ...@@ -30,87 +29,170 @@ exports.corpus_process_create = function(req,res) {
newCorpusProcess.save((error, corpusProcess) => { newCorpusProcess.save((error, corpusProcess) => {
if (error) { errorHandler(res, error); } if (error) { errorHandler(res, error); }
else { else {
successHandler(res, { corpusProcess: corpusProcess}, 201); successHandler(res, { corpusProcess: corpusProcess }, 201);
} }
}) })
} }
// Get an existing corpus process // Get an existing corpus process
exports.corpus_process_get = function(req,res) { exports.corpus_process_get = async function (req, res) {
const corpusProcessId = req.params.corpusProcessId; const corpusProcessId = req.params.corpusProcessId;
CorpusProcessModel.findById(corpusProcessId, (error, corpusProcess) => { try {
if (error) { errorHandler(res, error); }