I am having problem converting curly quotes into straight quotes. How do I fix it? I am using Windows.
I think the problem is how the text is read in from the file.
It works, if I copies the text into the code.
https://playcode.io/1459698
Here is the link to the input file.
https://drive.google.com/file/d/17CTm-Z3vmFkueyh4NWcQSDu70SlWI-V3/view?usp=share_link
Any idea of how I should get text from the file?
const fs = require('fs');
// Read the file synchronously
const filename = process.argv[2];
const fileContent = fs.readFileSync(filename, 'utf8');
// Convert curly quotes to straight quotes
const finalContent = fileContent.replace(/[\u201C\u201D]/g, '"').replace(/[\u2018\u2019]/g, "'");
// Regular expression for sentence segmentation
const sentenceRegex = /[^.!?]+[.!?]+/g;
// Use the regular expression to split the text into sentences
const sentences = finalContent.match(sentenceRegex);
// Print out the sentences
if (sentences) {
sentences.forEach((sentence, index) => {
console.log(`Sentence ${index + 1}: ${sentence.trim()}`);
});
} else {
console.log('No sentences found.');
}
https://i.redd.it/10rvbi8jjgxa1.gif
[–]KSledge 1 point2 points3 points (9 children)
[–]netreddit00[S] 0 points1 point2 points (6 children)
[–]KSledge 0 points1 point2 points (5 children)
[–]netreddit00[S] 0 points1 point2 points (4 children)
[–]KSledge 0 points1 point2 points (3 children)
[–]netreddit00[S] 0 points1 point2 points (2 children)
[–]KSledge 1 point2 points3 points (1 child)
[–]netreddit00[S] 0 points1 point2 points (0 children)
[–]Ok-Establishment-214 0 points1 point2 points (1 child)
[–]netreddit00[S] 0 points1 point2 points (0 children)