Profanity Detection and Cleaning API
APIエンドポイント: https://events-front.mixeder.net/v2/wordetect/
API概要
Profanity Detection and Cleaning APIは、テキストから不適切な単語を検出し、指定の文字やパターンで置換する機能を提供します。ユーザーは、簡単なAPIコールで不適切な表現の除去や検出を行うことができます。以下は具体的な利用手順とサンプルコードです。
APIの使い方
1. API キーの提供方法
APIを利用するには、有効なAPIキーを以下のいずれかの方法で渡してください。
GETパラメータ:
?key=<API_KEY>
POSTパラメータ:
api-key=<API_KEY>
HTTPヘッダー:
api-key: <API_KEY>
パラメータ一覧
パラメータ名
型
必須
説明
key
string
必須
APIキー。GET/POSTまたはヘッダーで提供可能。
text
string
必須
不適切単語を検出・置換する対象テキスト。
add
string
任意
カンマ区切りで追加する不適切単語リスト。
fill_text
string
任意
置換時に使用する文字列(デフォルト: *
)。
fill_char
string
任意
置換時、単語長に応じて使う文字(例: #
)。
method
string
任意
実行モード: json
/ xml
/ plain
/ containsprofanity
モードの説明
containsprofanity
テキスト内に不適切な単語があるかどうかを検出します。
戻り値:
true
/false
(JSON形式)
json
入力テキストと置換後のクリーンなテキストをJSONで返します。
xml
テキストの置換結果をXML形式で返します。
plain
置換後のクリーンなテキストをプレーンテキスト形式で返します。
サンプルコード
1. JSON形式のクリーンテキスト取得
リクエスト
curl "https://events-front.mixeder.net/v2/wordetect/?key=YOUR_API_KEY&text=This is a bad word&method=json"
レスポンス
{
"original": "This is a bad word",
"cleaned": "This is a *** word"
}
2. XML形式での出力
リクエスト
curl "https://events-front.mixeder.net/v2/wordetect/?key=YOUR_API_KEY&text=This is ugly&method=xml"
レスポンス
<?xml version="1.0" encoding="UTF-8"?>
<response>
<original>This is bad</original>
<cleaned>This is ****</cleaned>
</response>
3. プレーンテキスト形式の出力
リクエスト
curl "https://events-front.mixeder.net/v2/wordetect/?key=YOUR_API_KEY&text=Bad example&method=plain"
レスポンス
*** example
4. 不適切単語検出 (containsprofanity モード)
リクエスト
curl "https://events-front.mixeder.net/v2/wordetect/?key=YOUR_API_KEY&text=Bad words here&method=containsprofanity"
レスポンス
"true"
5. カスタムの追加単語と置換文字の指定
リクエスト
curl "https://events-front.mixeder.net/v2/wordetect/?key=YOUR_API_KEY&text=Special bad words&add=special&fill_char=#&method=json"
レスポンス
{
"original": "Special bad words",
"cleaned": "####### bad words"
}
6. HTTPヘッダーでのAPIキー提供例
PHPサンプルコード
$apiUrl = "https://events-front.mixeder.net/v2/wordetect/";
$text = "This is inappropriate content.";
$headers = [
"api-key: YOUR_API_KEY"
];
$options = [
'http' => [
'header' => implode("\r\n", $headers),
'method' => 'GET',
'content' => http_build_query(['text' => $text, 'method' => 'json'])
]
];
$context = stream_context_create($options);
$response = file_get_contents($apiUrl, false, $context);
echo $response;
7. POSTメソッドの利用例
リクエスト
curl -X POST "https://events-front.mixeder.net/v2/wordetect/" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "api-key=YOUR_API_KEY" \
-d "text=Some bad words here" \
-d "method=json"
レスポンス
{
"original": "Some bad words here",
"cleaned": "Some *** words here"
}
エラーハンドリング
1. APIキーが未提供の場合
"API Key not provided."
2. 無効なAPIキーの場合
"API key is wrong"
不適切単語の管理
基本の不適切単語リストはMIXEDERによってリストされたベース学習リストから取得されます。
カスタム追加単語は、
add
パラメータで指定します。 例:&add=dummy,offensive
まとめ
このAPIは、不適切な表現の検出およびフィルタリングを効率的に行います。多彩な出力形式やカスタム単語の追加機能により、柔軟な対応が可能です。ぜひ、Profanity Detection and Cleaning APIを活用して、ユーザーフレンドリーなテキスト管理を実現してください。
最終更新
役に立ちましたか?