Adding regex tool
This commit is contained in:
parent
5999aeeb0c
commit
719ab8a02e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
|
tools/ProfanityFilter/src/Words.json
|
26
tools/ProfanityFilter/.vscode/launch.json
vendored
Normal file
26
tools/ProfanityFilter/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Current File",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "${file}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "RegexGenerator",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "RegexGenerator",
|
||||||
|
"projectName": "ProfanityFilter_ceb3bd68",
|
||||||
|
"args": [
|
||||||
|
"ass",
|
||||||
|
"shit"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
7
tools/ProfanityFilter/.vscode/settings.json
vendored
Normal file
7
tools/ProfanityFilter/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
18
tools/ProfanityFilter/README.md
Normal file
18
tools/ProfanityFilter/README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||||
|
|
||||||
|
## Folder Structure
|
||||||
|
|
||||||
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
|
- `src`: the folder to maintain sources
|
||||||
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
|
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||||
|
|
||||||
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
|
## Dependency Management
|
||||||
|
|
||||||
|
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
BIN
tools/ProfanityFilter/bin/ExceptionGenerator.class
Normal file
BIN
tools/ProfanityFilter/bin/ExceptionGenerator.class
Normal file
Binary file not shown.
BIN
tools/ProfanityFilter/bin/RegexGenerator.class
Normal file
BIN
tools/ProfanityFilter/bin/RegexGenerator.class
Normal file
Binary file not shown.
1689
tools/ProfanityFilter/bin/Words.json
Normal file
1689
tools/ProfanityFilter/bin/Words.json
Normal file
File diff suppressed because it is too large
Load Diff
24
tools/ProfanityFilter/src/ExceptionGenerator.java
Normal file
24
tools/ProfanityFilter/src/ExceptionGenerator.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
public class ExceptionGenerator {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//position 0 should be the base word, the rest should be exceptions
|
||||||
|
String base = args[0].toLowerCase();
|
||||||
|
|
||||||
|
String prefixes = "(?<!";
|
||||||
|
String regex = RegexGenerator.regexGenerator(base);
|
||||||
|
String suffixes = "(?!";
|
||||||
|
|
||||||
|
for (int i = 1; i < args.length; i++) {
|
||||||
|
args[i] = "$" + args[i] + "$";
|
||||||
|
for (String str : args[i].toLowerCase().split(base)) {
|
||||||
|
if (str.equals("$")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
str.replaceAll("$", "");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(prefixes + ")" + regex + suffixes + ")");
|
||||||
|
}
|
||||||
|
}
|
75
tools/ProfanityFilter/src/RegexGenerator.java
Normal file
75
tools/ProfanityFilter/src/RegexGenerator.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RegexGenerator {
|
||||||
|
private static Map<Character, String> dictionary;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Map<Character, String> map = new HashMap<>();
|
||||||
|
map.put('a', "[a@*]");
|
||||||
|
map.put('b', "([b38]|\\\\|3)");
|
||||||
|
map.put('c', "[c(k]");
|
||||||
|
map.put('d', "[d]");
|
||||||
|
map.put('e', "[e3*]");
|
||||||
|
map.put('f', "([f]|ph)");
|
||||||
|
map.put('g', "[g]");
|
||||||
|
map.put('h', "[h]");
|
||||||
|
map.put('i', "[il1!*]");
|
||||||
|
map.put('j', "[j]");
|
||||||
|
map.put('k', "[kc]");
|
||||||
|
map.put('l', "[li]");
|
||||||
|
map.put('m', "([m]|rn)");
|
||||||
|
map.put('n', "[n]");
|
||||||
|
map.put('o', "[o0pq*]");
|
||||||
|
map.put('p', "[p]");
|
||||||
|
map.put('q', "[q]");
|
||||||
|
map.put('r', "[r]");
|
||||||
|
map.put('s', "[sz5$]");
|
||||||
|
map.put('t', "[t7+]");
|
||||||
|
map.put('u', "[uv*]");
|
||||||
|
map.put('v', "[v]");
|
||||||
|
map.put('w', "([w]|vv)");
|
||||||
|
map.put('x', "[x]");
|
||||||
|
map.put('y', "[y]");
|
||||||
|
map.put('z', "[z]");
|
||||||
|
map.put(' ', "");
|
||||||
|
map.put('1', "([1]|one)");
|
||||||
|
map.put('2', "([2]|two)");
|
||||||
|
map.put('3', "([3]|three)");
|
||||||
|
map.put('4', "([4]|four)");
|
||||||
|
map.put('5', "([5]|five)");
|
||||||
|
map.put('6', "([6]|six)");
|
||||||
|
map.put('7', "([7]|seven)");
|
||||||
|
map.put('8', "([8]|eight)");
|
||||||
|
map.put('9', "([9]|nine)");
|
||||||
|
map.put('0', "([0]|zero)");
|
||||||
|
dictionary = Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
for (String s : args) {
|
||||||
|
String regex = "(\\\\b|^)";
|
||||||
|
|
||||||
|
for (char c : s.toLowerCase().toCharArray()) {
|
||||||
|
regex += dictionary.get(c) + "+[\\\\s\\\\n\\\\W]*";
|
||||||
|
}
|
||||||
|
|
||||||
|
regex += "(\\\\b|$)";
|
||||||
|
|
||||||
|
System.out.println(regex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String regexGenerator(String str) {
|
||||||
|
String regex = "(\\\\b|^)";
|
||||||
|
|
||||||
|
for (char c : str.toLowerCase().toCharArray()) {
|
||||||
|
regex += dictionary.get(c) + "+[\\\\s\\\\n\\\\W]*";
|
||||||
|
}
|
||||||
|
|
||||||
|
regex += "(\\\\b|$)";
|
||||||
|
|
||||||
|
return regex;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user