node-tfidf
Calc TF-IDF string for Nodejs
Term Frequency–Inverse Document Frequency (tf-idf) is implemented to determine how important a word (or words) is to a document relative to a corpus. The following example will add four documents to a corpus and determine the weight of the word "node" and then the weight of the word "ruby" in each document.
Install
npm install node-tfidf
Example
var TfIdf = ;var tfidf = ; tfidf;tfidf;tfidf;tfidf;tfidf; console;tfidf; console;tfidf;
The above outputs:
UIT =====================
document #0 is 0
document #1 is 0
document #2 is 0
document #3 is 0
document #4 is 1.91629073187415
ĐHQG-HCM =====================
document #0 is 2.4462871026284194
document #1 is 0
document #2 is 2.4462871026284194
document #3 is 2.4462871026284194
document #4 is 0
applied to individual documents
The following example measures the term "node" in the first and second documents.
console;console;
load documents from files on disk.
tfidf;tfidf;
Multiple terms
Multiple terms can be measured as well, with their weights being added into a single measure value.
console;tfidf;
The above outputs:
Thông tin =====================
document #0 is 5
document #1 is 2
document #2 is 4
document #3 is 4
document #4 is 0
perform your own tokenization
The examples above all use strings, which case to automatically tokenize the input. If you wish to perform your own tokenization or other kinds of processing, you can do so, then pass in the resultant arrays later.
var TfIdf = ;var tfidf = ; tfidf;tfidf;tfidf;tfidf; tfidf;
How to contribute
- Fork the project on Github
- Create a topic branch for your changes
- Ensure that you provide documentation and test coverage for your changes (patches won’t be accepted without)
- Create a pull request on Github (these are also a great place to start a conversation around a patch as early as possible)
License
MIT License
Copyright (c) 2015 Van-Duyet Le
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.