This repository has been archived by the owner on Apr 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
168 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ src/dist | |
Project_Default.xml | ||
package-lock.json | ||
.idea | ||
scripts/filter-data/.temp |
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
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,25 @@ | ||
// 导出过滤词库 | ||
// https://github.com/fighting41love/funNLP/tree/master/data/%E6%95%8F%E6%84%9F%E8%AF%8D%E5%BA%93 | ||
const {execSync} = require('child_process') | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
|
||
// 如果临时git文件夹不存在 就拉取 | ||
const zip = 'scripts/filter-data/data.zip' | ||
const temp = 'scripts/filter-data/.temp' | ||
fs.emptyDirSync(temp) | ||
fs.mkdirsSync(temp) | ||
execSync(`unzip ${zip} -d ${temp} -x __MACOSX/*> /dev/null 2>&1`, {stdio: 'inherit'}) | ||
|
||
const words = [] | ||
const files = fs.readdirSync(temp) | ||
files.forEach((it) => { | ||
const file = `${temp}/${it}` | ||
const itemWords = fs.readFileSync(file, 'utf-8').split('\n') | ||
words.push.apply(words, itemWords) | ||
console.log('添加过滤词数 ', itemWords.length) | ||
}) | ||
console.log('加载完成,过滤词数共%d条', words.length) | ||
|
||
// sqlite | ||
fs.writeFileSync('src/main/filter/keywords.txt', Buffer.from(words.join('\n')).toString('base64')) |
Binary file not shown.
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,21 @@ | ||
filepath=256x256.png | ||
iconset=.icns.iconset | ||
|
||
cd build/icons | ||
if [ ! -d $iconset ];then | ||
mkdir $iconset | ||
fi | ||
|
||
sips -z 16 16 $filepath --out $iconset/icon_16x16.png | ||
sips -z 32 32 $filepath --out $iconset/icon_16x16@2x.png | ||
sips -z 32 32 $filepath --out $iconset/icon_32x32.png | ||
sips -z 64 64 $filepath --out $iconset/icon_32x32@2x.png | ||
sips -z 128 128 $filepath --out $iconset/icon_128x128.png | ||
sips -z 256 256 $filepath --out $iconset/icon_128x128@2x.png | ||
sips -z 256 256 $filepath --out $iconset/icon_256x256.png | ||
sips -z 512 512 $filepath --out $iconset/icon_256x256@2x.png | ||
sips -z 512 512 $filepath --out $iconset/icon_512x512.png | ||
sips -z 1024 1024 $filepath --out $iconset/icon_512x512@2x.png | ||
|
||
iconutil -c icns $iconset -o icon.icns | ||
icotool -c $iconset/icon_256x256.png -o icon.ico |
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
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,87 @@ | ||
// https://github.com/aojiaotage/text-censor | ||
|
||
const path = require('path') | ||
const fs = require('fs') | ||
const iconv = require('iconv-lite') | ||
|
||
const map = {} | ||
|
||
function initialize () { | ||
const original = Buffer.from(fs.readFileSync(path.resolve(__dirname, './keywords.txt'), 'utf-8'), 'base64') | ||
const words = original.toString().split('\n') | ||
words.forEach((line) => { | ||
if (line) { | ||
addWord(line) | ||
} | ||
}) | ||
} | ||
|
||
function addWord (word) { | ||
let parent = map | ||
|
||
for (let i = 0; i < word.length; i++) { | ||
if (!parent[word[i]]) parent[word[i]] = {} | ||
parent = parent[word[i]] | ||
} | ||
parent.isEnd = true | ||
} | ||
|
||
function isFilter (s, cb) { | ||
let parent = map | ||
|
||
for (let i = 0; i < s.length; i++) { | ||
if (s[i] === '*') { | ||
continue | ||
} | ||
|
||
let found = false | ||
let skip = 0 | ||
let sWord = '' | ||
|
||
for (let j = i; j < s.length; j++) { | ||
if (!parent[s[j]]) { | ||
found = false | ||
skip = j - i | ||
parent = map | ||
break | ||
} | ||
|
||
sWord = sWord + s[j] | ||
if (parent[s[j]].isEnd) { | ||
found = true | ||
skip = j - i | ||
break | ||
} | ||
parent = parent[s[j]] | ||
} | ||
|
||
if (skip > 1) { | ||
i += skip - 1 | ||
} | ||
|
||
if (!found) { | ||
continue | ||
} | ||
|
||
let stars = '*' | ||
for (let k = 0; k < skip; k++) { | ||
stars = stars + '*' | ||
} | ||
|
||
let reg = new RegExp(sWord, 'g') | ||
if (reg.test(s)) { | ||
return true | ||
} | ||
// s = s.replace(reg, stars) | ||
} | ||
|
||
if (typeof cb === 'function') { | ||
cb(null, s) | ||
} | ||
|
||
return false | ||
} | ||
|
||
module.exports = { | ||
initialize, isFilter | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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