-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
51 lines (50 loc) · 5.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
if (String.prototype.match.toString().includes("[native code]")) {
const email = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/
const url = /[a-z]([a-z]|[0-9]|[+\-.])*:(\/\/((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|:)*@)?(\[((([0-9a-f]{1,4}:){6}([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|::([0-9a-f]{1,4}:){5}([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|([0-9a-f]{1,4})?::([0-9a-f]{1,4}:){4}([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(([0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){3}([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(([0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){2}([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(([0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(([0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:[0-9a-f]{1,4}|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(([0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(([0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\.(([a-z]|[0-9]|[-._~])|[!$&'()*+,;=]|:)+)]|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}|(([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=])*)(:\d*)?(\/((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@]))*)*|\/(((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@]))+(\/((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@]))*)*)?|((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@]))+(\/((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@]))*)*|)(\?((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@])|[\/?])*)?(#((([a-z]|[0-9]|[-._~])|%[0-9a-f][0-9a-f]|[!$&'()*+,;=]|[:@])|[\/?])*)?/i
const 都道府県 = /(北海道|青森県|岩手県|宮城県|秋田県|山形県|福島県|茨城県|栃木県|群馬県|埼玉県|千葉県|東京都|神奈川県|新潟県|富山県|石川県|福井県|山梨県|長野県|岐阜県|静岡県|愛知県|三重県|滋賀県|京都府|大阪府|兵庫県|奈良県|和歌山県|鳥取県|島根県|岡山県|広島県|山口県|徳島県|香川県|愛媛県|高知県|福岡県|佐賀県|長崎県|熊本県|大分県|宮崎県|鹿児島県|沖縄県)/
const ip = /((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/
const fqdn = /([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]*\.)+[a-zA-Z]{2,}/
const 電話番号 = /0[-0-9]{9,12}/
const match = String.prototype.match
String.prototype.match = function (regexp) {
regexp = new RegExp(regexp.source.replaceAll(/\x{email}/.source, email.source), regexp.flags + email.flags)
regexp = new RegExp(regexp.source.replaceAll(/\x{url}/.source, url.source), regexp.flags + url.flags)
regexp = new RegExp(regexp.source.replaceAll(/\x{都道府県}/.source, 都道府県.source), regexp.flags + 都道府県.flags)
regexp = new RegExp(regexp.source.replaceAll(/\x{ip}/.source, ip.source), regexp.flags + ip.flags)
regexp = new RegExp(regexp.source.replaceAll(/\x{fqdn}/.source, fqdn.source), regexp.flags + fqdn.flags)
regexp = new RegExp(regexp.source.replaceAll(/\x{電話番号}/.source, 電話番号.source), regexp.flags + 電話番号.flags)
return match.call(this, regexp)
}
}
var access_tokens
String.prototype.matchAsync = async function (regexp) {
if (!access_tokens) {
access_tokens = await fetch("https://api.ce-cotoha.com/v1/oauth/accesstokens", {
"headers": {
"content-type": "application/json; charset=utf-8",
},
"body": atob('eyJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJjbGllbnRJZCI6Ik1HR1A2TTI2OHp0UG5oa3ZIY2M0cFhkeFNRdVY3S25yIiwiY2xpZW50U2VjcmV0IjoiOFJSQXd4QVFiZWhmT2NhSyJ9'),
"method": "POST"
}).then(r=>r.json())
}
const classes = {
[/\x{日付}/.source]: 'DAT',
[/\x{時間}/.source]: 'TIM',
[/\x{人物}/.source]: 'PSN',
[/\x{場所}/.source]: 'LOC',
[/\x{お金}/.source]: 'MNY',
[/\x{組織}/.source]: 'ORG',
[/\x{アート}/.source]: 'ART',
[/\x{%}/.source]: 'PCT',
[/\x{数}/.source]: 'NUM',
[/\x{その他}/.source]: 'OTH',
}
return fetch("https://api.ce-cotoha.com/api/dev/nlp/v1/ne", {
"headers": {
"authorization": "Bearer " + access_tokens.access_token,
"content-type": "application/json"
},
"body": JSON.stringify({sentence: this}),
"method": "POST"
}).then(r=>r.json()).then(resp => resp.result.filter(r=>r.class===classes[regexp.source]).map(r=>r.form))
}