Documentation
¶
Index ¶
- type Bacot
- type CraftManConfig
- type DictWords
- type Dictionary
- func (d *Dictionary) AddFalsePositive(words ...string)
- func (d *Dictionary) AddWords(words ...string)
- func (d *Dictionary) Contains(word string) bool
- func (d *Dictionary) DelWords(words ...string)
- func (d *Dictionary) GetDict() DictWords
- func (d *Dictionary) GetWordsLen() []int
- func (d *Dictionary) IsContainLen(n int) bool
- func (d *Dictionary) IsFalsePositive(s string) bool
- func (d *Dictionary) IsStopWord(s string) bool
- func (d *Dictionary) Majority() int
- func (d *Dictionary) Max() int
- func (d *Dictionary) Min() int
- type ModalScan
- func (ms *ModalScan) Affix(v bool) *ModalScan
- func (ms *ModalScan) ClearSpace() *ModalScan
- func (ms *ModalScan) Collect(v bool) *ModalScan
- func (ms *ModalScan) GetText() string
- func (ms *ModalScan) RecursiveScan() *ScanResult
- func (ms *ModalScan) ReplaceWhiteSpace() *ModalScan
- func (ms *ModalScan) SanitizeEmoji() *ModalScan
- func (ms *ModalScan) SanitizeNewLine() *ModalScan
- func (ms *ModalScan) SanitizeReadSign() *ModalScan
- func (ms *ModalScan) Scan() *ScanResult
- func (ms *ModalScan) TrimSpace() *ModalScan
- func (ms *ModalScan) UnstackChar() *ModalScan
- func (ms *ModalScan) WithLeetSpeak() *ModalScan
- type ModalScanConfig
- type SanitizeOrder
- type ScanResult
- func (sr *ScanResult) Censor() string
- func (sr *ScanResult) Count() int
- func (sr *ScanResult) Extract() []string
- func (sr *ScanResult) First() string
- func (sr *ScanResult) Generator() *WordIndexGenerator
- func (sr *ScanResult) GetText() string
- func (sr *ScanResult) IsProfane() bool
- func (sr *ScanResult) Last() string
- type WordIndex
- type WordIndexGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bacot ¶
type Bacot struct {
// modal scanning
Dict *Dictionary
// contains filtered or unexported fields
}
func (*Bacot) AddFalsePositive ¶ added in v1.2.0
func (*Bacot) Config ¶ added in v1.2.0
func (b *Bacot) Config(config *ModalScanConfig) *Bacot
Config
func (*Bacot) Text ¶
Text() menjalankan pipeline preprocessing default:
Emoji → ReplaceWhiteSpace → SanitizeReadSign → ReplaceWhiteSpace → UnstackChar → Affix(true)
Urutan ini penting karena:
- Emoji dihapus dulu biar ga jadi noise
- Tanda baca diganti spasi biar tokenisasi akurat
- Unstack dilakukan setelah leet speak (default leet tidak aktif, perlu manual)
- Affix detection aktif default, bisa dimatikan dengan Affix(false)
Config() bisa override pipeline ini. Lihat ModalScanConfig.Order.
type CraftManConfig ¶ added in v1.2.0
type CraftManConfig struct {
PrefixNasalFusion bool
}
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
func NewDictionary ¶
func NewDictionary() *Dictionary
func (*Dictionary) AddFalsePositive ¶ added in v1.2.2
func (d *Dictionary) AddFalsePositive(words ...string)
func (*Dictionary) AddWords ¶
func (d *Dictionary) AddWords(words ...string)
func (*Dictionary) Contains ¶
func (d *Dictionary) Contains(word string) bool
func (*Dictionary) DelWords ¶
func (d *Dictionary) DelWords(words ...string)
func (*Dictionary) GetDict ¶
func (d *Dictionary) GetDict() DictWords
func (*Dictionary) GetWordsLen ¶
func (d *Dictionary) GetWordsLen() []int
func (*Dictionary) IsContainLen ¶
func (d *Dictionary) IsContainLen(n int) bool
func (*Dictionary) IsFalsePositive ¶ added in v1.2.0
func (d *Dictionary) IsFalsePositive(s string) bool
func (*Dictionary) IsStopWord ¶
func (d *Dictionary) IsStopWord(s string) bool
func (*Dictionary) Majority ¶ added in v1.2.2
func (d *Dictionary) Majority() int
func (*Dictionary) Max ¶
func (d *Dictionary) Max() int
func (*Dictionary) Min ¶
func (d *Dictionary) Min() int
type ModalScan ¶
type ModalScan struct {
// contains filtered or unexported fields
}
func (*ModalScan) ClearSpace ¶ added in v1.2.0
func (*ModalScan) RecursiveScan ¶
func (ms *ModalScan) RecursiveScan() *ScanResult
RecursiveScan() mencari kata kotor di dalam substring token. Berguna untuk kasus seperti "xbabi" di mana kata kotor menempel dengan karakter lain. RecursiveScan akan sliding window dari setiap posisi l di dalam token dan mencocokkan dengan dictionary.
Kompleksitas: O(token_length × dict_word_lengths). Untuk token normal (<20 char) sangat cepat. Untuk token sangat panjang (10K char) perlu diwaspadai.
func (*ModalScan) ReplaceWhiteSpace ¶ added in v1.2.0
func (*ModalScan) SanitizeEmoji ¶ added in v1.2.0
func (*ModalScan) SanitizeNewLine ¶ added in v1.2.0
func (*ModalScan) SanitizeReadSign ¶ added in v1.2.0
func (*ModalScan) Scan ¶
func (ms *ModalScan) Scan() *ScanResult
Scan() menggunakan strategi token-based (split by spasi), bukan substring search. Ini mengurangi false positive: "kelas" tidak akan terdeteksi sebagai "elas" karena token exact match.
Optimasi: length histogram pre-filter — jika tidak ada kata di dictionary dengan panjang yang sama, token langsung skip. Ini menghindari map lookup yang tidak perlu.
func (*ModalScan) UnstackChar ¶
func (*ModalScan) WithLeetSpeak ¶
Leet mengandung angka jika case nya := "babi123" -> "babiire" -> "babire" dengan affix "babire" tidak dianggap kata kotor karena "babi" + sukukata, beda makna maka jika lolos di leetspeak, scan kedua kali yang tanpa sanitasi leetspeak
kesimpulan: jika input mengandung elemen leetspeak dan lolos scan scan ulang dengan mematikan leet
type ModalScanConfig ¶ added in v1.2.0
type ModalScanConfig struct {
Affix bool
Collect bool
Order []SanitizeOrder
}
type SanitizeOrder ¶ added in v1.2.0
type SanitizeOrder int
const ( SanitizeNewLine SanitizeOrder = iota ClearSpace WithLeetSpeak UnstackChar // new TrimSpace ReplaceWhiteSpace SanitizeReadSign )
type ScanResult ¶
type ScanResult struct {
// contains filtered or unexported fields
}
ScanResult adalah hasil dari proses scanning. Ia menyimpan dua versi teks:
- text: teks asli input (preserve huruf besar/kecil)
- praScanText: teks setelah preprocessing (lowercased + sanitized)
WordIndex menyimpan posisi start/end tiap kata kotor yang ditemukan, memungkinkan operasi seperti Censor() tanpa perlu scanning ulang.
func (*ScanResult) Censor ¶
func (sr *ScanResult) Censor() string
Censor() mengganti character kata kotor dengan '*'. Arsitektur: menggunakan precomputed WordIndex dari Scan().
Strategi:
- Replace langsung di []rune praScanText menggunakan WordIndex (O(1) per kata, tanpa perlu scanning ulang).
- Jika teks asli punya huruf besar/kecil, petakan kembali dari teks asli ke teks yang sudah dicensor.
- Jika teks sudah lowercase semua, tidak perlu mapping.
func (*ScanResult) Count ¶
func (sr *ScanResult) Count() int
func (*ScanResult) Extract ¶
func (sr *ScanResult) Extract() []string
func (*ScanResult) First ¶
func (sr *ScanResult) First() string
func (*ScanResult) Generator ¶
func (sr *ScanResult) Generator() *WordIndexGenerator
func (*ScanResult) GetText ¶
func (sr *ScanResult) GetText() string
func (*ScanResult) IsProfane ¶
func (sr *ScanResult) IsProfane() bool
func (*ScanResult) Last ¶
func (sr *ScanResult) Last() string
type WordIndexGenerator ¶
type WordIndexGenerator struct {
// contains filtered or unexported fields
}
func (*WordIndexGenerator) Yield ¶
func (wig *WordIndexGenerator) Yield() *WordIndex