2 Replies
      Latest reply on Apr 22, 2020 9:11 PM by KevinCoble
      KevinCoble Level 1 Level 1 (0 points)

        I have found a single example in Objective-C, but have been unable to convert to work in swift.  I keep getting memory violation errors deep inside the routine, several stack layers deeper than my code.

        • Re: Does anyone have a NSLinguisticTagger.possibleTags example in swift
          OOPer Level 8 Level 8 (6,125 points)

          A simple example.

          let tagger = NSLinguisticTagger(tagSchemes: [.lexicalClass], options: 0)
          tagger.string = "This is the sample sentence."
          var score: NSArray? = nil
          let result = tagger.possibleTags(at: 10, scheme: NSLinguisticTagScheme.lexicalClass.rawValue, tokenRange: nil, sentenceRange: nil, scores: &score)
          print(result, score)
          
          
            • Re: Does anyone have a NSLinguisticTagger.possibleTags example in swift
              KevinCoble Level 1 Level 1 (0 points)

              Thank you.  The code works.

               

              The main difference I see from what I was trying is the tagSchemes on tagger creation.  I was using NSLinguisticTagger.availableTagSchemes(forLanguage: "en"), which worked great when I am using the enumerateTags function, but seems to be a problem when using possibleTags.

               

              enumerateTags is great at tokenization, but is fairly poor in tagging parts-of-speech in a sentence correctly, so I was looking to get the possible tags for each word to incorporate an older parser algorithm I created 10 years ago to parse the sentences using hints from enumerateTags to speed things up.

               

              Thanks again.