Skip to content

Commit

Permalink
fix the problem of parsing sample with CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Jul 17, 2024
1 parent 97d912d commit 3c9a661
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
30 changes: 20 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/components/project/UploadDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ export default defineComponent({
checkSentIdsErrors(fileContent: string, sampleName: string) {
const sentIds: any[] = [];
this.formatError = false;
const sentences = fileContent.split(/\n\n/).filter((sentence) => sentence);
const sentences = fileContent.replace(/[\r]/g, "").split(/\n\n/).filter((sentence) => sentence);
for (const sentence of sentences) {
this.checkSentFormatError(sentence, sampleName)
if (this.formatError) return;
if (sentenceConllToJson(sentence)['metaJson']['sent_id']) {
const sentId = sentenceConllToJson(sentence)['metaJson']['sent_id'];
Expand All @@ -235,7 +236,16 @@ export default defineComponent({
}
if (sentences.length !== sentIds.length) this.samplesWithoutSentIds.push(sampleName);
},
checkSentFormatError(sentence: string, sampleName: string) {
if (/\n\s*\n\S/.test(sentence)) {
notifyError({ error: `${sampleName} contains empty line that doesn't start with a digit or # ` });
this.formatError = true;
}
if (Object.values(sentenceConllToJson(sentence)['metaJson']).some((metaVal) => metaVal == undefined)) {
notifyError({ error: `${sampleName} contains sentence with empty metadata value` });
this.formatError = true;
}
},
triggerFormatErrors() {
this.samplesWithoutSentIds.forEach((sampleName) => {
this.warningMessage += `"${sampleName}" has sentences without sent_id.\n`;
Expand Down

0 comments on commit 3c9a661

Please sign in to comment.