機械翻訳について

エージェントのレスポンス文字数スクリプトの検証

このスクリプトは、Twitterチャネルに対するエージェントのレスポンスが280文字以下かどうかを検証します。

このスクリプトを検証ルールとしてメッセージ・オブジェクト(サービス・リクエスト・オブジェクトの子)に追加する必要があります。 Twitterレスポンスが280文字を超える場合にエージェントに表示される検証メッセージも追加する必要があります。

次のコードを例として使用します:

if(ChannelId == null){ 
    return true; 
}
def channelVO = newView('ChannelVO')
channelVO.appendViewCriteria("ChannelId = '${ChannelId}'")
channelVO.executeQuery()
def networkType = null
if(channelVO.hasNext())
{ 
    def channelRow = channelVO.next(); 
    networkType = channelRow.getAttribute("NetworkTypeCd") 
}
if(networkType == null || networkType != 'TWITTER') { 
    return true
}
String MessageContent = MessageContent.toString()
Long channelId = ChannelId
Long charCount = MessageContent.length();
String pattern = ~/(http|https):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*/
if(null == MessageContent)
return true;
String message = MessageContent.toString()
String[] tokens = message.split(" ")
for(int i=0;i<tokens.size();i++){
    if(tokens[i].matches(pattern )) {
        //this is an url
        Long urlLength = tokens[i].length()
        if(urlLength > 23)   { 
            charCount = charCount - (urlLength -23) 
        }
        else    { 
            charCount = charCount + (23- urlLength) 
        }
    }
}
if(charCount > 280)
    return false
else
    return true