An ordinary swift package, have a bunch looping of calculating TFIDF and of course to ranking words. This package work only with iOS v12 and later because it use tokenizer.
Take a peek
Just install like usual, using swift package manager
https://github.com/aziyan99/SwiftTfIdfin the search form (top-right)
- Choose the first one
How to use
Use it like usual, no magic here (magic will be add in the future :v)
- import the package
- Instance it
let tfIdf = SwiftTfIdf(text: String, stopWords: [String], topN: Int). text is the raw text that need to be ranking, stopWords the stop words (array of String), and topN how much the top words that want to get.
- Call the
.finalCount()function to get the results
let results = tfIdf.finalCount(). The funcion will returning array of dictionary
[(key: String, value: Float)]with
keyis the words and
valueis ranking value.
How it works
The calculation happend base on looping and sequentials, splitting the text to a bunch of array of sentences and words, calculate the tf, calculate the df and the tfidf, sorting the results, and ranking it. That means the more words that are processed the longer the execution time. An example of implementation will be adding soon.
- Writing the test case
- Adjust & improving the looping performance
- Restructuring the code
- Improve time complexity
- Adding logo (maybe will make it cool :v)
The Swift TF-IDF is open-sourced software licensed under the MIT license.