I just started learning Node.js
and can't figure out how to load data from a local CSV file and use wink Naive Bayes Text Classifier to learn the data.
I can load the data from local CSV file using this or this example. But the problem is that I do not know how to load wink
's Naive Bayes library to client side JS. Is there a way to include node's modules (like wink
) in the script that I wrote below?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Naive Bayes</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="./papaparse.min.js"></script>
</head>
<body>
<input type="file" id="csv-file" name="files"/>
</body>
<script>
// REF: https://www.joyofdata.de/blog/parsing-local-csv-file-with-javascript-papa-parse/
// http://archive.is/ySSC8
var data;
function handleFileSelect(evt) {
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
data = results;
}
});
}
$(document).ready(function(){
$("#csv-file").change(handleFileSelect);
});
</script>
</html>