aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2023-12-19 12:44:40 +0900
committerGitHub <noreply@github.com>2023-12-19 03:44:40 +0000
commitc661eafa7d57c32e33e51dd6eb787b97832e97f0 (patch)
tree1a68a563f9f1960d528595d6b33f74cb506bd77e /ext/js/language
parenteb7bf9542c92ea7937d4b4a699ae2d47270da96b (diff)
Add some JSDoc annotations to describe code functionality. (#355)
* lesen-tan initial commit * update README.md * tidy up code * opt for Map<K, V> instead of Object * Document dev/* * add docs for deinflector.js * update deinflector example * Annotate * Revert "Merge branch 'development' of https://github.com/Scrub1492/lesen-tan into development" This reverts commit b92348f702bc031b36f24462adfa940d17f9ecdd, reversing changes made to 3255e6d963281af3533dcf1e893df39032d29fec. * Lint error fix * Lint error fix
Diffstat (limited to 'ext/js/language')
-rw-r--r--ext/js/language/deinflector.js16
-rw-r--r--ext/js/language/dictionary-database.js28
2 files changed, 36 insertions, 8 deletions
diff --git a/ext/js/language/deinflector.js b/ext/js/language/deinflector.js
index 537a4556..90ca79ea 100644
--- a/ext/js/language/deinflector.js
+++ b/ext/js/language/deinflector.js
@@ -16,9 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/**
+ * This class deinflects Japanese terms to its dictionary form.
+ */
export class Deinflector {
/**
* @param {import('deinflector').ReasonsRaw} reasons
+ * @example
+ * const deinflectionReasons = JSON.parse(
+ * readFileSync(path.join('ext/data/deinflect.json')).toString(),
+ * ) as object;
+ * const deinflector = new Deinflector(deinflectionReasons);
*/
constructor(reasons) {
/** @type {import('deinflector').Reason[]} */
@@ -26,8 +34,13 @@ export class Deinflector {
}
/**
- * @param {string} source
+ * Deinflects a Japanese term to all of its possible dictionary forms.
+ * @param {string} source The source term to deinflect.
* @returns {import('translation-internal').Deinflection[]}
+ * @example
+ * const deinflector = new Deinflector(deinflectionReasons);
+ * // [{ term: '食べた', rules: 0, reasons: [] }, { term: '食べる', rules: 1, reasons: ['past'] }, { term: '食ぶ', rules: 2, reasons: ['potential', 'past'] }]
+ * console.log(deinflector.deinflect('食べさせられる'));
*/
deinflect(source) {
const results = [this._createDeinflection(source, 0, [])];
@@ -88,6 +101,7 @@ export class Deinflector {
}
/**
+ * Given a list of rules, return the corresponding deinflection rule flags.
* @param {string[]} rules
* @returns {import('translation-internal').DeinflectionRuleFlags}
*/
diff --git a/ext/js/language/dictionary-database.js b/ext/js/language/dictionary-database.js
index c47e1e90..ce5041c8 100644
--- a/ext/js/language/dictionary-database.js
+++ b/ext/js/language/dictionary-database.js
@@ -19,6 +19,9 @@
import {log, stringReverse} from '../core.js';
import {Database} from '../data/database.js';
+/**
+ * This class represents the dictionary database.
+ */
export class DictionaryDatabase {
constructor() {
/** @type {Database<import('dictionary-database').ObjectStoreName>} */
@@ -141,6 +144,7 @@ export class DictionaryDatabase {
}
/**
+ * Purges the database.
* @returns {Promise<boolean>}
*/
async purge() {
@@ -162,6 +166,7 @@ export class DictionaryDatabase {
}
/**
+ * Deletes a dictionary.
* @param {string} dictionaryName
* @param {number} progressRate
* @param {import('dictionary-database').DeleteDictionaryProgressCallback} onProgress
@@ -225,9 +230,10 @@ export class DictionaryDatabase {
}
/**
- * @param {string[]} termList
- * @param {import('dictionary-database').DictionarySet} dictionaries
- * @param {import('dictionary-database').MatchType} matchType
+ * Find terms in bulk.
+ * @param {string[]} termList The list of terms to find.
+ * @param {import('dictionary-database').DictionarySet} dictionaries Dictionaries to find the terms from.
+ * @param {import('dictionary-database').MatchType} matchType Matching type.
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
findTermsBulk(termList, dictionaries, matchType) {
@@ -259,8 +265,9 @@ export class DictionaryDatabase {
}
/**
- * @param {import('dictionary-database').TermExactRequest[]} termList
- * @param {import('dictionary-database').DictionarySet} dictionaries
+ * Find exact terms in bulk.
+ * @param {import('dictionary-database').TermExactRequest[]} termList The list of terms to find.
+ * @param {import('dictionary-database').DictionarySet} dictionaries Dictionaries to find the term from.
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
findTermsExactBulk(termList, dictionaries) {
@@ -270,6 +277,7 @@ export class DictionaryDatabase {
}
/**
+ * Find terms by sequence in bulk.
* @param {import('dictionary-database').DictionaryAndQueryRequest[]} items
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
@@ -280,6 +288,7 @@ export class DictionaryDatabase {
}
/**
+ * Find term meta in bulk.
* @param {string[]} termList
* @param {import('dictionary-database').DictionarySet} dictionaries
* @returns {Promise<import('dictionary-database').TermMeta[]>}
@@ -291,8 +300,9 @@ export class DictionaryDatabase {
}
/**
- * @param {string[]} kanjiList
- * @param {import('dictionary-database').DictionarySet} dictionaries
+ * Find kanji in bulk.
+ * @param {string[]} kanjiList The list of kanji to find.
+ * @param {import('dictionary-database').DictionarySet} dictionaries Dictionaries to find from.
* @returns {Promise<import('dictionary-database').KanjiEntry[]>}
*/
findKanjiBulk(kanjiList, dictionaries) {
@@ -302,6 +312,7 @@ export class DictionaryDatabase {
}
/**
+ * Find kanji meta in bulk.
* @param {string[]} kanjiList
* @param {import('dictionary-database').DictionarySet} dictionaries
* @returns {Promise<import('dictionary-database').KanjiMeta[]>}
@@ -313,6 +324,7 @@ export class DictionaryDatabase {
}
/**
+ * Find tag meta in bulk.
* @param {import('dictionary-database').DictionaryAndQueryRequest[]} items
* @returns {Promise<(import('dictionary-database').Tag|undefined)[]>}
*/
@@ -323,6 +335,7 @@ export class DictionaryDatabase {
}
/**
+ * Find tag for title.
* @param {string} name
* @param {string} dictionary
* @returns {Promise<?import('dictionary-database').Tag>}
@@ -343,6 +356,7 @@ export class DictionaryDatabase {
}
/**
+ * Get dictionary metadata.
* @returns {Promise<import('dictionary-importer').Summary[]>}
*/
getDictionaryInfo() {