Natural Language

RSS for tag

Analyze natural language text and deduce its language-specific metadata using Natural Language.

Posts under Natural Language tag

45 Posts

Post

Replies

Boosts

Views

Activity

Could string ranges obtained with a MLTokenizer be used outside of the enumerateTokens loop?
With the following function I sometime get "Thread 1: Fatal error: String index is out of bounds" errors at the substring.shuffled() call.  func transform(_ text: String) -> String {         var transformed = text         if #available(macOS 10.14, iOS 12.0, *) {             print("text: \"\(text)\"")             var wordRanges: [Range<String.Index>] = []             let tokenizer = NLTokenizer(unit: .word)             tokenizer.string = transformed             tokenizer.enumerateTokens(in: transformed.startIndex..<transformed.endIndex) { range, _ in                 if transformed[range].count > 3 {                     let subrange = transformed.index(range.lowerBound, offsetBy: 1)..<transformed.index(range.upperBound, offsetBy: -1)                     wordRanges.append(subrange)                 }                 return true             }             wordRanges.reversed().forEach { range in                 let substring = String(transformed[range])                 print("substring: \"\(substring)\"")                 transformed.replaceSubrange(range, with: substring.shuffled())             }         } else {             let range = NSRange(transformed.startIndex..., in: transformed)             let regex = try! NSRegularExpression(pattern: "\\W?\\w(\\w+)\\w\\W?", options: [])             let matches = regex.matches(in: transformed, options: [], range: range)             matches.reversed().forEach { match in                 guard let subrange = Range(match.range(at: 1), in: transformed) else {                     return                 }                 let substring = transformed[subrange]                 transformed.replaceSubrange(subrange, with: substring.shuffled())             }         }         return transformed     } The error appear in a macOS app with some strings but not all. I can't reproduce the error in a playground with the string that triggered the error. When the error occurs, tprinted substrings are not correct. Using Xcode 13.3.
1
0
1.5k
Mar ’22
Can I get sample code for this keynote?
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.
1
0
1.3k
Jan ’22
Can I get sample code for WWDC20 Make apps smarter with Natural Language?
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.
1
0
1.1k
Jan ’22
Could string ranges obtained with a MLTokenizer be used outside of the enumerateTokens loop?
With the following function I sometime get "Thread 1: Fatal error: String index is out of bounds" errors at the substring.shuffled() call.  func transform(_ text: String) -> String {         var transformed = text         if #available(macOS 10.14, iOS 12.0, *) {             print("text: \"\(text)\"")             var wordRanges: [Range<String.Index>] = []             let tokenizer = NLTokenizer(unit: .word)             tokenizer.string = transformed             tokenizer.enumerateTokens(in: transformed.startIndex..<transformed.endIndex) { range, _ in                 if transformed[range].count > 3 {                     let subrange = transformed.index(range.lowerBound, offsetBy: 1)..<transformed.index(range.upperBound, offsetBy: -1)                     wordRanges.append(subrange)                 }                 return true             }             wordRanges.reversed().forEach { range in                 let substring = String(transformed[range])                 print("substring: \"\(substring)\"")                 transformed.replaceSubrange(range, with: substring.shuffled())             }         } else {             let range = NSRange(transformed.startIndex..., in: transformed)             let regex = try! NSRegularExpression(pattern: "\\W?\\w(\\w+)\\w\\W?", options: [])             let matches = regex.matches(in: transformed, options: [], range: range)             matches.reversed().forEach { match in                 guard let subrange = Range(match.range(at: 1), in: transformed) else {                     return                 }                 let substring = transformed[subrange]                 transformed.replaceSubrange(subrange, with: substring.shuffled())             }         }         return transformed     } The error appear in a macOS app with some strings but not all. I can't reproduce the error in a playground with the string that triggered the error. When the error occurs, tprinted substrings are not correct. Using Xcode 13.3.
Replies
1
Boosts
0
Views
1.5k
Activity
Mar ’22
Can I get sample code for this keynote?
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.
Replies
1
Boosts
0
Views
1.3k
Activity
Jan ’22
Can I get sample code for WWDC20 Make apps smarter with Natural Language?
I am a student from a non-English speaking country. I would like to get the sample code from the "Make apps smarter with Natural Language" keynote on dynamic word embeddings and custom sentence embeddings. I can't find relevant examples on google to keep learning about it. I hope the developer community can share the full text of the sample code for the Nosh app and Merch app in the video. Thanks Vivek and Doug.
Replies
1
Boosts
0
Views
1.1k
Activity
Jan ’22