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