日本語の校正を支援する API があることを知り、早速 Notes で試してみました。
なおAPIを使うには事前にアプリケーションIDの登録をして「アプリケーションID」を取得します。※アプリケーションIDは「Client ID」と書かれている場合もあるようです
ざっくり言うと、校正する文章を含む json を url へ post すると、校正の結果を json で返してくれます。
さっそく本題です。
Notesアプリのフォームへ、テキスト型で2つの編集可能フィールド(Bodyとkosei)を追加して、フォームのアクションボタンには次のコードを追加しました。
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim ss As New NotesSession
Dim target_text As String
Dim req As NotesHTTPRequest
Dim nav As NotesJSONNavigator
Dim elm As NotesJSONElement
Dim obj As NotesJSONObject
Dim arr As NotesJSONArray
Dim req_param As String
Dim id As String
Dim appid As String
Dim url As String
Dim result As String
id = Format$(Now, "yyyymmdd-hhnnss")
appid = "your application (client) id"
url = "https://jlp.yahooapis.jp/KouseiService/V2/kousei"
target_text = ws.CurrentDocument.FieldGetText( "Body" )
req_param = |
{
"id": "| & id & |",
"jsonrpc": "2.0",
"method": "jlp.kouseiservice.kousei",
"params": {
"q": "| & target_text & |"
}
}
|
Set req = ss.CreateHTTPRequest
req.PreferJSONNavigator = True
Call req.SetHeaderField( "Content-Type", "application/json" )
Call req.SetHeaderField( "User-Agent", "Yahoo AppID: " & appid )
Set nav = req.Post( url, req_param )
If Instr( req.ResponseCode, "200" ) = 0 Then
Print req.ResponseCode & ", " & nav.GetElementByPointer( "/Error/Message" ).Value
Exit Sub
End If
result = ""
Set arr = nav.GetElementByPointer( "/result/suggestions" ).Value
Set elm = arr.GetFirstElement
While Not elm Is Nothing
Set obj = elm.Value
result = result _
& "オフセット: " & obj.GetElementByName( "offset" ).Value _
& " から " & obj.GetElementByName( "length" ).Value _
& " 文字:「" & obj.GetElementByName( "word" ).Value _
& "」 => 「" & obj.GetElementByName( "suggestion" ).Value _
& "」、【" & obj.GetElementByName( "rule" ).Value _
& "】 " & obj.GetElementByName( "note" ).Value _
& Chr(10)
Set elm = arr.GetNextElement()
Wend
Call ws.CurrentDocument.FieldSetText( "kosei", result )
End Subフォームの Body フィールドへ「セキュリティー,食べれる」とタイプしてアクションボタンをクリックしてみます。



0 件のコメント:
コメントを投稿