搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

profanity_filter

簡單的過濾器,用於檢查並屏蔽字串中的粗俗和淫穢詞語。提供了一個預設的英文詞彙列表(LDNOOBW)。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.7萬
喜歡數
119
Pub 分數
160

安裝套件

flutter pub add profanity_filter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量級的 Flutter/Dart 套件,使用內建的英文詞彙表(LDNOOBW)檢查並屏蔽字串中的粗俗語言。它透過識別和取代冒犯性語言來幫助維護應用程式中的尊重溝通。非常適合用於使用者產生內容審核、即時通訊應用,或任何需要文字過濾的情境。此套件容易整合,並支援多種平台,包括行動裝置、Web 與桌面。

適用情境

  • 使用者評論審核
  • 聊天應用過濾
  • 表單中的內容安全
  • 即時訊息篩選
  • 自動文本清理

主要特色

  • 內建英文粗俗用語清單
  • 簡單的字串檢查與遮蔽
  • 可自訂的詞彙清單
  • 跨平台支援
  • 與 Flutter 的輕鬆整合

適合對象

  • 應用開發者優先考慮內容安全
  • 聊天或社交媒體應用
  • 使用者輸入的審核工具
  • 教育類或適合家庭的應用
  • 具有公開評論區的應用程式

使用建議

  • 預設僅限英文
  • 可能需要自定詞表更新
  • 審查準確性取決於詞表的完整性
  • 未經自訂,不適用於多語言內容
  • 上下文敏感詞可能導致誤報

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

profanity_filter

Dart CI

Pub Version

Simple Dart class to create filters with methods to check and censor strings against profanity. A default English words list is provided (from LDNOOBW on GitHub).

You can also use the filters to filter out a custom set of words, by using the ProfanityFilter.filterOnly() constructor.

Usage

To use this plugin, add profanity_filter as a dependency in your pubspec.yaml file.

Note: The latest version of the package is null-safe. The last package version that wasn't null-safe is 1.0.4

Example
import 'package:profanity_filter/profanity_filter.dart';

void main() {
  //Create the filter with the default constructor.
  //The default constructor uses the default list of words provided by [LDNOOBW on GitHub](
  //https://github.com/LDNOOBW/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words)
  //Other constructors are available, see [README.md](https://pub.dev/packages/profanity_filter).
  final filter = ProfanityFilter();

  //This string contains the profanity 'ass'
  String badString = 'You are an ass';

  //Check for profanity - returns a boolean (true if profanity is present)
  bool hasProfanity = filter.hasProfanity(badString);
  print('The string $badString has profanity: $hasProfanity');

  //Get the profanity used - returns a List<String>
  List<String> wordsFound = filter.getAllProfanity(badString);
  print('The string contains the words: $wordsFound');

  //Censor the string - returns a 'cleaned' string.
  String cleanString = filter.censor(badString);
  print('Censored version of "$badString" is "$cleanString"');
}

Methods

hasProfanity - Detect if a string contains profanity

Use the hasProfanity() method of the filter instance. Pass in the string to be tested.

Example
final filter = ProfanityFilter();
String badString = 'you are an ass';
filter.hasProfanity(badString); //Returns true.
getAllProfanity - Get a list of all profane words found

Use the getAllProfanity() method of the filter instance. Pass in the string to be tested.

Example

final filter = ProfanityFilter();
String badString = 'you are an ass';
List<String> wordsFound = filter.getAllProfanity(badString); //Returns ['ass']
censor - Censor a string (replace profanity with something clean)

Use the censor() method of the filter instance. Pass in the string to be censored.

Example
final filter = ProfanityFilter();
String badString = 'you are an ass';
String cleanString = filter.censor('you are an ass'); //cleanString: 'you are an ***'

Optionally, you can provide your own clean replacement word to the replaceWith named parameter. filter.censor(string, replaceWith:'[censored]') will replace any profanity in string with [censored]

Default Profanity List

The default profanity list is taken from the LDNOOBW list, licensed under a Creative Commons Attribution 4.0 International License.

To create a filter with the default list, use the default constructor ProfanityFilter()

Variations
To include custom words alongside default list

Use ProfanityFilter.filterAdditionally() constructor and pass your list of custom words.

This will use a list which is equivalent to Default List + Custom List

To filter only custom words (default list is ignored)

Use ProfanityFilter.filterOnly() constructor and pass a list containing your custom set of words.

This will use a list which is equivalent to Custom List

To filter with a few exclusions from default list

Use ProfanityFilter.ignore() constructor and pass your list of custom words. Those words will be removed from the default list if they exist there.

This will use a list which is equivalent to Default List - Custom List

所屬分類

原始碼儲存庫

使用此套件的專案