The ExtraMath feature is a library that organizes simple mathematical formulas frequently used in the use cases of WelsonJS.
Currently, it supports the following:
Below is an example of utilizing DTM (Document-Term Matrix) and Cosine Similarity using the WelsonJS framework.
var ExtraMath = require("lib/extramath"); var a = "this is an apple"; var b = "this is red apple"; var dtm = new ExtraMath.DTM(); dtm.add(a); dtm.add(b); var mat = dtm.toArray(); console.log("Original sentance"); console.log(a); console.log(b); console.log("Create a DTM(Document-Term Matrix)"); console.log(mat[0].join(' ')); console.log(mat[1].join(' ')); console.log("Measure Cosine Similarity"); console.log('' + ExtraMath.arrayCos(mat[0], mat[1])); console.log('' + ExtraMath.measureSimilarity(a, b));
You can also find this example in the testloader.js
file.