teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

s

2018/06/03 12:04

投稿

_Kentarou
_Kentarou

スコア8490

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

2018/06/03 12:04

投稿

_Kentarou
_Kentarou

スコア8490

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

2018/06/03 04:51

投稿

_Kentarou
_Kentarou

スコア8490

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
  ```