回答編集履歴
3
s
answer
CHANGED
@@ -13,4 +13,18 @@
|
|
13
13
|
|
14
14
|
上記のサイトをみたら、`.tokenType`を使ってました。
|
15
15
|
|
16
|
-
サイトのコードをコピーして貼り付けてエラーが出るでしょうか?
|
16
|
+
サイトのコードをコピーして貼り付けてエラーが出るでしょうか?
|
17
|
+
|
18
|
+
```swift
|
19
|
+
import UIKit
|
20
|
+
|
21
|
+
let text = "I have a beautiful pen."
|
22
|
+
let tagger = NSLinguisticTagger(tagSchemes: NSLinguisticTagger.availableTagSchemes(forLanguage: "en"), options: 0)
|
23
|
+
|
24
|
+
tagger.string = text
|
25
|
+
tagger.enumerateTags(in: NSRange(location: 0, length: text.characters.count), scheme: .tokenType, options: []) { tag, tokenRange, sentenceRange, _ in
|
26
|
+
|
27
|
+
let subString = (text as NSString).substring(with: tokenRange)
|
28
|
+
print("(subString) : (tag?.rawValue ?? "")")
|
29
|
+
}
|
30
|
+
```
|
2
まs
answer
CHANGED
@@ -13,7 +13,4 @@
|
|
13
13
|
|
14
14
|
上記のサイトをみたら、`.tokenType`を使ってました。
|
15
15
|
|
16
|
-
|
17
|
-
```swift
|
18
|
-
func enumerateTags(in range: NSRange, scheme tagScheme: NSLinguisticTagScheme, options opts: NSLinguisticTagger.Options = [], using block: (NSLinguisticTag?, NSRange, NSRange, UnsafeMutablePointer<ObjCBool>) -> Swift.Void)
|
19
|
-
```
|
16
|
+
サイトのコードをコピーして貼り付けてエラーが出るでしょうか?
|
1
s
answer
CHANGED
@@ -5,4 +5,15 @@
|
|
5
5
|
```swift
|
6
6
|
tagger.enumerateTags(in: <#T##NSRange#>, scheme: <#T##NSLinguisticTagScheme#>, options: <#T##NSLinguisticTagger.Options#>, using: <#T##(NSLinguisticTag?, NSRange, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void#>)
|
7
7
|
|
8
|
+
```
|
9
|
+
回答追記
|
10
|
+
---
|
11
|
+
|
12
|
+
[【Swift4】形態素解析をやってみる | NSLinguisticTagger](http://www.cl9.info/entry/2017/09/21/144557)
|
13
|
+
|
14
|
+
上記のサイトをみたら、`.tokenType`を使ってました。
|
15
|
+
|
16
|
+
????のメソッドを使うようですね。
|
17
|
+
```swift
|
18
|
+
func enumerateTags(in range: NSRange, scheme tagScheme: NSLinguisticTagScheme, options opts: NSLinguisticTagger.Options = [], using block: (NSLinguisticTag?, NSRange, NSRange, UnsafeMutablePointer<ObjCBool>) -> Swift.Void)
|
8
19
|
```
|