UNPKG

@launchmenu/applet-dictionary

Version:
85 lines 6.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WiktionaryPage = void 0; const WikiPage_1 = require("../wiki/WikiPage"); const WikiSection_1 = require("../wiki/WikiSection"); const WiktionaryReferences_1 = require("./baseSections/WiktionaryReferences"); const WiktionarySeeAlso_1 = require("./baseSections/WiktionarySeeAlso"); const WiktionaryUsageNotes_1 = require("./baseSections/WiktionaryUsageNotes"); const WiktionaryLanguage_1 = require("./WiktionaryLanguage"); const WiktionaryAdjective_1 = require("./definitionWordType/WiktionaryAdjective"); const WiktionaryAdverb_1 = require("./definitionWordType/WiktionaryAdverb"); const WiktionaryDeterminer_1 = require("./definitionWordType/WiktionaryDeterminer"); const WiktionaryNoun_1 = require("./definitionWordType/WiktionaryNoun"); const WiktionaryVerb_1 = require("./definitionWordType/WiktionaryVerb"); const WiktionaryPronoun_1 = require("./definitionWordType/WiktionaryPronoun"); const WiktionaryDefinition_1 = require("./WiktionaryDefinition"); class WiktionaryPage extends WikiPage_1.WikiPage { /** @override */ createSection(data) { return new WiktionaryLanguage_1.WiktionaryLanguage(this, data, data.childList.map(section => this.createDefinitionSection(section))); } /** * Creates a section using the appropriate class given the section data * @param data The data of the section * @returns The created section */ createDefinitionSection(data) { let Class = WikiSection_1.WikiSection; // Select an appropriate class given the section name const name = data.name.toLowerCase(); if (name.match(/etymology\s*[0-9]+/)) Class = WiktionaryDefinition_1.WiktionaryDefinition; else if (name == "pronunciation") Class = WikiSection_1.WikiSection; else if (name == "antonyms") Class = WikiSection_1.WikiSection; else if (name == "references") Class = WiktionaryReferences_1.WiktionaryReferences; else if (name == "see also") Class = WiktionarySeeAlso_1.WiktionarySeeAlso; // Word definition sections else if (name == "verb") Class = WiktionaryVerb_1.WiktionaryVerb; else if (name == "adverb") Class = WiktionaryAdverb_1.WiktionaryAdverb; else if (name == "adjective") Class = WiktionaryAdjective_1.WiktionaryAdjective; else if (name == "noun") Class = WiktionaryNoun_1.WiktionaryNoun; else if (name == "pronoun") Class = WiktionaryPronoun_1.WiktionaryPronoun; else if (name == "determiner") Class = WiktionaryDeterminer_1.WiktionaryDeterminer; // Extra per word type else if (name == "derived terms") Class = WikiSection_1.WikiSection; else if (name == "related terms") Class = WikiSection_1.WikiSection; else if (name == "usage notes") Class = WiktionaryUsageNotes_1.WiktionaryUsageNotes; // Instantiate the class return new Class(this, data, data.childList.map(section => this.createDefinitionSection(section))); } /** * Retrieves all the languages and the word's definitions in this language * @param hook The hook to subscribe to changes * @returns All the languages that have a definition for this word */ getLanguages(hook) { return this.getSectionList(hook); } /** * Retrieves the definition of the word for the given language * @param language The language to get the definition for * @param hook The hook to subscribe to changes * @returns The language section if it exists */ getLanguage(language, hook) { var _a; language = language.toLowerCase(); return ((_a = this.getLanguages(hook).find(section => section.getLanguage() == language)) !== null && _a !== void 0 ? _a : null); } } exports.WiktionaryPage = WiktionaryPage; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2l0a2lvbmFyeVBhZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2NyYXBlci93aWt0aW9uYXJ5L1dpdGtpb25hcnlQYWdlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUNBLCtDQUEwQztBQUMxQyxxREFBZ0Q7QUFFaEQsOEVBQXlFO0FBQ3pFLHdFQUFtRTtBQUNuRSw4RUFBeUU7QUFDekUsNkRBQXdEO0FBQ3hELGtGQUE2RTtBQUM3RSw0RUFBdUU7QUFDdkUsb0ZBQStFO0FBQy9FLHdFQUFtRTtBQUNuRSx3RUFBbUU7QUFDbkUsOEVBQXlFO0FBQ3pFLGlFQUE0RDtBQUU1RCxNQUFhLGNBQWUsU0FBUSxtQkFBNEI7SUFDNUQsZ0JBQWdCO0lBQ04sYUFBYSxDQUFDLElBQWtCO1FBQ3RDLE9BQU8sSUFBSSx1Q0FBa0IsQ0FD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