Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

NLtagger not filtering words such as "And, to, a, in"

what am I not understanding here. in short the view loads text from the jsons descriptions and then should filter out the words. and return and display a list of most used words, debugging shows words being identified by the code but does not filter them out

    private func loadWordCounts() {
        DispatchQueue.global(qos: .background).async {
            let fileManager = FileManager.default
            guard let documentsDirectory = try? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) else { return }

            let descriptions = loadDescriptions(fileManager: fileManager, documentsDirectory: documentsDirectory)

            var counts = countWords(in: descriptions)

            let tagsToRemove: Set<NLTag> = [
                .verb,
                .pronoun,
                .determiner,
                .particle,
                .preposition,
                .conjunction,
                .interjection,
                .classifier
            ]

            for (word, _) in counts {
                let tagger = NLTagger(tagSchemes: [.lexicalClass])
                tagger.string = word

                let (tag, _) = tagger.tag(at: word.startIndex, unit: .word, scheme: .lexicalClass)

                if let unwrappedTag = tag, tagsToRemove.contains(unwrappedTag) {
                    counts[word] = 0
                }
            }

            DispatchQueue.main.async {
                self.wordCounts = counts
            }
        }
    }
NLtagger not filtering words such as "And, to, a, in"
 
 
Q