ios – Lemmatizing text works on physical devices, but not Xcode previews, simulators, or tests


Lemmatizing text works on physical devices, but not Xcode previews, simulators, or tests. This code works on physical devices (Mac, iOS 16.4, iOS 17.3) but not on Xcode previews, simulators, or Xcode tests.

import SwiftUI
import NaturalLanguage

struct ContentView: View {
    var body: some View {
        VStack {
            Text(lemmatize())
        }
    }
  
  func lemmatize() -> String {
    let text = "Pumpkins grow slow. Cars are fast."
    
    let tagger = NLTagger(tagSchemes: [.lemma])
    tagger.string = text

    print (tagger.tagSchemes)

    var lemmaText: String = ""
    
    tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .lemma) { tag, range in
      let stemForm = tag?.rawValue ?? String(text[range])
      lemmaText += stemForm
      return true
    }
    
    return lemmaText
  }
}

Given the string “Pumpkins grow slow. Cars are fast.”, I expect -> “pumpkin grow slow. car be fast.”. However, I get the string back unmodified on the simulators (multiple iOS versions). Running on latest Xcode and Sonoma.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img