UNPKG

2.36 kBPlain TextView Raw
1/**
2 * @license
3 * Copyright 2021 Google LLC
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {model as jaModel} from './data/models/ja.js';
18import {model as zhHansModel} from './data/models/zh-hans.js';
19import {model as zhHantModel} from './data/models/zh-hant.js';
20import {model as thModel} from './data/models/th.js';
21import {HTMLProcessingParser} from './html_processor.js';
22
23export {Parser} from './parser.js';
24export {HTMLProcessor, HTMLProcessingParser} from './html_processor.js';
25export {jaModel, zhHansModel, zhHantModel};
26
27/**
28 * Loads a parser equipped with the default Japanese model.
29 * @return A parser with the default Japanese model.
30 */
31export const loadDefaultJapaneseParser = () => {
32 return new HTMLProcessingParser(jaModel);
33};
34
35/**
36 * Loads a parser equipped with the default Simplified Chinese model.
37 * @return A parser with the default Simplified Chinese model.
38 */
39export const loadDefaultSimplifiedChineseParser = () => {
40 return new HTMLProcessingParser(zhHansModel);
41};
42
43/**
44 * Loads a parser equipped with the default Traditional Chinese model.
45 * @return A parser with the default Traditional Chinese model.
46 */
47export const loadDefaultTraditionalChineseParser = () => {
48 return new HTMLProcessingParser(zhHantModel);
49};
50
51/**
52 * Loads a parser equipped with the default Thai model.
53 * @returns A parser with the default Thai model.
54 */
55export const loadDefaultThaiParser = () => {
56 return new HTMLProcessingParser(thModel);
57};
58/**
59 * Loads available default parsers.
60 * @return A map between available lang codes and their default parsers.
61 */
62export const loadDefaultParsers = () => {
63 return new Map([
64 ['ja', loadDefaultJapaneseParser()],
65 ['zh-hans', loadDefaultSimplifiedChineseParser()],
66 ['zh-hant', loadDefaultTraditionalChineseParser()],
67 ['th', loadDefaultThaiParser()],
68 ]);
69};