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.
Just install like usual, using swift package manager
File
>Add Packages...
- Paste
https://github.com/aziyan99/SwiftTfIdf
in the search form (top-right) - Choose the first one
SwiftTfIdf
withmain
branch
Use it like usual, no magic here (magic will be add in the future :v)
- import the package
import SwiftTfIdf
- 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 resultslet results = tfIdf.finalCount()
. The funcion will returning array of dictionary[(key: String, value: Float)]
withkey
is the words andvalue
is ranking value.
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)
NaturalLanguage
Foundation
The Swift TF-IDF is open-sourced software licensed under the MIT license.