obscenity / DataSet
Holds phrases (groups of patterns and whitelisted terms), optionally associating metadata with them.
Name | Description |
---|---|
MetadataType |
Metadata type for phrases. Note that the metadata type is implicitly nullable. |
• new DataSet<MetadataType
>()
Name |
---|
MetadataType |
▸ addAll(other
): DataSet
<MetadataType
>
Adds all the phrases from the dataset provided to this one.
Example
const customDataset = new DataSet().addAll(englishDataset);
Name | Type | Description |
---|---|---|
other |
DataSet <MetadataType > |
Other dataset. |
DataSet
<MetadataType
>
▸ addPhrase(fn
): DataSet
<MetadataType
>
Adds a phrase to this dataset.
Example
const data = new DataSet<{ originalWord: string }>()
.addPhrase((phrase) => phrase.setMetadata({ originalWord: 'fuck' })
.addPattern(pattern`fuck`)
.addPattern(pattern`f[?]ck`)
.addWhitelistedTerm('Afck'))
.build();
Name | Type | Description |
---|---|---|
fn |
(builder : PhraseBuilder <MetadataType >) => PhraseBuilder <MetadataType > |
A function that takes a [[PhraseBuilder]], adds patterns/whitelisted terms/metadata to it, and returns it. |
DataSet
<MetadataType
>
▸ build(): Pick
<RegExpMatcherOptions
, "blacklistedTerms"
| "whitelistedTerms"
>
Returns the dataset in a format suitable for usage with the [[RegExpMatcher]].
Example
// With the RegExpMatcher:
const matcher = new RegExpMatcher({
...dataset.build(),
// additional options here
});
Pick
<RegExpMatcherOptions
, "blacklistedTerms"
| "whitelistedTerms"
>
▸ getPayloadWithPhraseMetadata(payload
): MatchPayloadWithPhraseMetadata
<MetadataType
>
Retrieves the phrase metadata associated with a pattern and returns a copy of the match payload with said metadata attached to it.
Example
const matches = matcher.getAllMatches(input);
const matchesWithPhraseMetadata = matches.map((match) => dataset.getPayloadWithPhraseMetadata(match));
// Now we can access the 'phraseMetadata' property:
const phraseMetadata = matchesWithPhraseMetadata[0].phraseMetadata;
Name | Type | Description |
---|---|---|
payload |
MatchPayload |
Original match payload. |
MatchPayloadWithPhraseMetadata
<MetadataType
>
▸ removePhrasesIf(predicate
): DataSet
<MetadataType
>
Removes phrases that match the predicate given.
Example
const customDataset = new DataSet<{ originalWord: string }>()
.addAll(englishDataset)
.removePhrasesIf((phrase) => phrase.metadata.originalWord === 'fuck');
Name | Type | Description |
---|---|---|
predicate |
(phrase : PhraseContainer <MetadataType >) => boolean |
A predicate that determines whether or not a phrase should be removed. Return true to remove, false to keep. |
DataSet
<MetadataType
>