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

Saving to file lemmer results #7

Open
ivgenyk opened this issue Dec 19, 2017 · 0 comments
Open

Saving to file lemmer results #7

ivgenyk opened this issue Dec 19, 2017 · 0 comments

Comments

@ivgenyk
Copy link

ivgenyk commented Dec 19, 2017

Hi,
I used lemmer to lemmatize a vector of 20K words and then wanted to save the results to a file. I receive an error saying "Error: EMFILE: too many open files, open 'c:\lemmered.txt'". When I am saving the original tokens vector (same number of words). It seems that it is a problem with the Lemmer.lemmatize function.

Do you know what can be the problem?
I tried many different ways of rewriting this and it seems that there is some part of the lemmer that afflicts the ability to write a file even after it has finished.

var Lemmer = require('lemmer');
const fs = require('fs');
let textFilePath = "C:/Qanta/leadgenPilot/OpenWhisk/sandBox/barc_text[9047].txt";
readFileIK(textFilePath) // this uses readFile as a promise resolving with the data
    .then(data => {
        let tokens = data
            // .substring(1,10000)
            .toLowerCase().split(/\W/g);
        Lemmer.lemmatize(tokens, function (err, wordsArray) {
            if (err) {
                console.log(err)
                throw (err)
            } else {
                let a = wordsArray.toString();
                console.log("lemmered ", wordsArray.length, "now will write to file")
                 fs.writeFile("lemmered.txt", a, (err) => {
                     if (err) {
                         console.log("error writing file ", err)
                     } else {
                        console.log("GREAT SUCCESS")
                    }
                 })
            }
        })
    })
function readFileIK(textFilePath) {
    return new Promise(function (resolve, reject) {
        fs.readFile(textFilePath, 'utf8', function (err, data) {
            if (err)
                reject(err)
            resolve(data)
        })
    })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant