This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Add sentence validator for Cantonese #605
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c86c623
Add yue
laubonghaudoi 3de0832
Add rules
laubonghaudoi 523b79e
Add validation
laubonghaudoi d62b8f3
Add rule
laubonghaudoi 3cb30b8
Fix comments and rules
laubonghaudoi 5d96c76
fix regex
laubonghaudoi cb22212
Update rules
laubonghaudoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Minimum of characters that qualify as a sentence. | ||
const MIN_LENGTH = 3; | ||
|
||
// Maximum of characters allowed per sentence to keep recordings in a manageable duration. | ||
const MAX_LENGTH = 50; | ||
|
||
const INVALIDATIONS = [{ | ||
fn: (sentence) => { | ||
return sentence.length < MIN_LENGTH || sentence.length > MAX_LENGTH; | ||
}, | ||
error: `字數必須要喺 ${MIN_LENGTH} 同 ${MAX_LENGTH} 之間`, | ||
}, { | ||
regex: /[0-9]+/, | ||
error: "句子唔可以包含阿拉伯數字", | ||
}, { | ||
regex: /[<>+*#@%^[\]()/]/, | ||
error: "句子唔可以有特殊符號", | ||
}, { | ||
// 7 or more repeating characters in a row is likely a non-formal spelling or difficult to read. | ||
regex: /(.)\1{6}/, | ||
error: "唔可以有連續 7 個或以上重複字元", | ||
}, { | ||
// Emoji range from https://www.regextester.com/106421 and | ||
// https://stackoverflow.com/questions/10992921/how-to-remove-emoji-code-using-javascript | ||
regex: /(\u00a9|\u00ae|[\u2000-\u3300]|[\u2580-\u27bf]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|[\ue000-\uf8ff])/, | ||
error: "句子唔可以含有 emoji 或者其他特殊 Unicode 符號", | ||
}, { | ||
regex: /[\u5427\u5504\u5436](\s|\u3002|\u002E|$)/, | ||
error: '句子唔可以有官話語氣詞(例如吧、唄、吶)', | ||
}]; | ||
|
||
module.exports = { | ||
INVALIDATIONS, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, did that happen often in Sentence Collector? 7 repeating characters seems like a lot, but I have absolutely no language experience apart from latin-based languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sometimes happens when people dump uncleaned sentences directly crawled from web. For examples sentences with long tailing dots, such as
額........
Such sentences are most likely junk.