提交 386dfd73 编写于 作者: sinat_25235033's avatar sinat_25235033

use the franc instaed of languageDetect

上级 326a99ef
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
......@@ -2927,6 +2927,11 @@
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
"dev": true
},
"collapse-white-space": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-1.0.6.tgz",
"integrity": "sha512-jEovNnrhMuqyCcjfEJA56v0Xq8SkIoPKDyaHahwo3POf4qcSXqMYuwNcOTzp74vTsR9Tn08z4MxWqAhcekogkQ=="
},
"collect-v8-coverage": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz",
......@@ -4178,6 +4183,14 @@
"map-cache": "^0.2.2"
}
},
"franc-min": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/franc-min/-/franc-min-5.0.0.tgz",
"integrity": "sha512-xy7Iq7uNflbvNU+bkyYWtP+BOHWZle7kT9GM84gEV14b7/7sgq7M7Flf6v1XRflHAuHoshBMveWA6Q+kEXYeHQ==",
"requires": {
"trigram-utils": "^1.0.0"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
......@@ -7756,6 +7769,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"n-gram": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/n-gram/-/n-gram-1.1.2.tgz",
"integrity": "sha512-mBTpWKp0NHdujHmxrskPg2jc108mjyMmVxHN1rZGK/ogTLi9O0debDIXlQPqotNELdNmVGtL4jr7SCig+4OWvQ=="
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
......@@ -9328,6 +9346,21 @@
"punycode": "^2.1.0"
}
},
"trigram-utils": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/trigram-utils/-/trigram-utils-1.0.3.tgz",
"integrity": "sha512-UAhS1Ll21FtClVIzIN0I/SmGnJ+D08BOxX7Dl1penV8raC0ksf2dJkhNI6kU1Mj3uT86Bul12iMvxXquXSYSng==",
"requires": {
"collapse-white-space": "^1.0.0",
"n-gram": "^1.0.0",
"trim": "0.0.1"
}
},
"trim": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz",
"integrity": "sha1-WFhUf2spB1fulczMZm+1AITEYN0="
},
"ts-jest": {
"version": "24.3.0",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.3.0.tgz",
......
......@@ -4,6 +4,8 @@ import * as webhook from '@octokit/webhooks'
import LanguageDetect from 'languagedetect'
import translate from '@k3rn31p4nic/google-translate-api'
let franc = require('franc-min')
async function run(): Promise<void> {
try {
if (
......@@ -72,14 +74,17 @@ async function run(): Promise<void> {
}
function detectIsEnglish(body: string): boolean | true {
const lngDetector = new LanguageDetect()
const detectResult = lngDetector.detect(body, 1)
if (detectResult === undefined || detectResult === null || detectResult.length !== 1) {
core.warning(`Can not detect the comment body: ${body}`)
// const lngDetector = new LanguageDetect()
// const detectResult = lngDetector.detect(body, 1)
const detectResult = franc(body)
if (detectResult === 'und'
|| detectResult === undefined
|| detectResult === null) {
core.warning(`Can not detect the undetermined comment body: ${body}`)
return false
}
core.info(`Detect comment body language result is: ${detectResult[0][0]}, similar sorce: ${detectResult[0][1]}`)
return detectResult.length === 1 && detectResult[0][0] === 'english'
core.info(`Detect comment body language result is: ${detectResult}`)
return detectResult === 'eng'
}
async function translateCommentBody(body: string, issue_user: string): Promise<string> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册