搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目