Thanks for the help, I’ll look into purescript-options
and also try out using String
. I know it’s difficult and probably would take time. I’m hopeful that I’ll eventually get over this hump.
Also there is an example I don’t know how to untangle it in terms of PS.
import { default as jsk } from 'modelscript';
let dataset;
//In JavaScript, by default most I/O Operations are asynchronous, see the notes section for more
ms.loadCSV('/some/file/path.csv')
.then(csvData=>{
dataset = new ms.DataSet(csvData);
console.log({csvData});
/* csvData [{
'Country': 'Brazil',
'Age': '44',
'Salary': '72000',
'Purchased': 'N',
},
...
{
'Country': 'Mexico',
'Age': '27',
'Salary': '48000',
'Purchased': 'Yes',
}] */
})
.catch(console.error);
// or from URL
ms.loadCSV('https://example.com/some/file/path.csv')
I don’t know if it helps, but there is a DataSet
class defined as
DataSet [Class: DataSet]: { //class for manipulating an array of objects (typically from CSV data)
columnMatrix(vectors), //returns a matrix of values by combining column arrays into a matrix
columnArray(columnName, options), // - returns a new array of a selected column from an array of objects, can filter, scale and replace values
columnReplace(columnName, options), // - returns a new array of a selected column from an array of objects and replaces empty values, encodes values and scales values
columnScale(columnName, options), // - returns a new array of scaled values which can be reverse (descaled). The scaling transformations are stored on the DataSet
columnDescale(columnName, options), // - Returns a new array of descaled values
selectColumns(columns, options), //returns a list of objects with only selected columns as properties
labelEncoder(columnName, options), // - returns a new array and label encodes a selected column
labelDecode(columnName, options), // - returns a new array and decodes an encoded column back to the original array values
oneHotEncoder(columnName, options), // - returns a new object of one hot encoded values
columnMatrix(columnName, options), // - returns a matrix of values from multiple columns
columnReducer(newColumnName, options), // - returns a new array of a selected column that is passed a reducer function, this is used to create new columns for aggregate statistics
columnMerge(name, data), // - returns a new column that is merged onto the data set
filterColumn(options), // - filtered rows of data,
fitColumns(options), // - mutates data property of DataSet by replacing multiple columns in a single command
static reverseColumnMatrix(options), // returns an array of objects by applying labels to matrix of columns
static reverseColumnVector(options), // returns an array of objects by applying labels to column vector
}
So there seems to be an asynchronous function call which then takes the output as form of promise and then uses the DataSet class to format the data or something I’m not completely sure of.
Source : https://github.com/repetere/modelscript/blob/master/docs/api.md
Also found the function’s source
export async function loadCSV(filepath, options) {
if (validURL.isUri(filepath)) {
return loadCSVURI(filepath, options);
} else {
return new Promise((resolve, reject) => {
const csvData = [];
const config = Object.assign({ checkType: true, }, options);
csv(config).fromFile(filepath)
.on('json', jsonObj => {
csvData.push(jsonObj);
})
.on('error', err => {
return reject(err);
})
.on('done', error => {
if (error) {
return reject(error);
} else {
return resolve(csvData);
}
});
});
}
}