diff --git a/developer/js/source/lexical-model-compiler/lexical-model-compiler.ts b/developer/js/source/lexical-model-compiler/lexical-model-compiler.ts index 2797701efa..6e9cdf2676 100644 --- a/developer/js/source/lexical-model-compiler/lexical-model-compiler.ts +++ b/developer/js/source/lexical-model-compiler/lexical-model-compiler.ts @@ -9,7 +9,7 @@ import * as ts from "typescript"; import * as fs from "fs"; import * as path from "path"; import { createTrieDataStructure } from "./build-trie"; -import { ModelPseudoclosure } from "./model-pseudoclosure"; +import { ModelDefinitions } from "./model-definitions"; import {decorateWithJoin} from "./join-word-breaker-decorator"; import {decorateWithScriptOverrides} from "./script-overrides-decorator"; @@ -50,28 +50,28 @@ export default class LexicalModelCompiler { // file, rather than the current working directory. let filenames = modelSource.sources.map(filename => path.join(sourcePath, filename)); - let pseudoclosure = new ModelPseudoclosure(modelSource); + let definitions = new ModelDefinitions(modelSource); - func += pseudoclosure.compilePseudoclosure(); + func += definitions.compileDefinitions(); // Needs the actual searchTermToKey closure... // Which needs the actual applyCasing closure as well. func += `LMLayerWorker.loadModel(new models.TrieModel(${ - createTrieDataStructure(filenames, pseudoclosure.searchTermToKey) + createTrieDataStructure(filenames, definitions.searchTermToKey) }, {\n`; let wordBreakerSourceCode = compileWordBreaker(normalizeWordBreakerSpec(modelSource.wordBreaker)); func += ` wordBreaker: ${wordBreakerSourceCode},\n`; // START - the lexical mapping option block - func += ` searchTermToKey: ${pseudoclosure.compileSearchTermToKey()},\n`; + func += ` searchTermToKey: ${definitions.compileSearchTermToKey()},\n`; if(modelSource.languageUsesCasing != null) { func += ` languageUsesCasing: ${modelSource.languageUsesCasing},\n`; } // else leave undefined. if(modelSource.languageUsesCasing) { - func += ` applyCasing: ${pseudoclosure.compileApplyCasing()},\n`; + func += ` applyCasing: ${definitions.compileApplyCasing()},\n`; } // END - the lexical mapping option block. diff --git a/developer/js/source/lexical-model-compiler/model-pseudoclosure.ts b/developer/js/source/lexical-model-compiler/model-definitions.ts similarity index 95% rename from developer/js/source/lexical-model-compiler/model-pseudoclosure.ts rename to developer/js/source/lexical-model-compiler/model-definitions.ts index 83d5ff4f2d..a031a65a31 100644 --- a/developer/js/source/lexical-model-compiler/model-pseudoclosure.ts +++ b/developer/js/source/lexical-model-compiler/model-definitions.ts @@ -12,7 +12,7 @@ import { defaultApplyCasing, * will very closely match the organizational patterns of this class in order to * facilitate the maintenance of this approach. */ -export class ModelPseudoclosure { +export class ModelDefinitions { static readonly COMPILED_NAME = 'definitions'; /** * A closure fully implementing the model's defined `applyCasing` behavior with @@ -124,9 +124,8 @@ export class ModelPseudoclosure { * This should be written to the file within the same IIFE as the model but BEFORE * the model itself, as the model will need to refer to the definitions herein. */ - compilePseudoclosure(): string { + compileDefinitions(): string { let defn: string = ''; - let PSEUDOCLOSURE = ModelPseudoclosure.COMPILED_NAME; defn += `let ${PSEUDOCLOSURE} = {\n` // ---------------------- @@ -201,8 +200,6 @@ export class ModelPseudoclosure { * compiled pseudoclosure. */ compileSearchTermToKey(): string { - let PSEUDOCLOSURE = ModelPseudoclosure.COMPILED_NAME; - // Simply point the model to the constructed closure defined by `compilePseudoclosure`. // See "START - compiled closures" section. return `${PSEUDOCLOSURE}.searchTermToKey`; @@ -212,11 +209,11 @@ export class ModelPseudoclosure { * Compiles the model-options entry for `applyCasing` in reference to the * compiled pseudoclosure. */ - compileApplyCasing(): string { - let PSEUDOCLOSURE = ModelPseudoclosure.COMPILED_NAME; - - // Simply point the model to the constructed closure defined by `compilePseudoclosure`. + compileApplyCasing(): string {// Simply point the model to the constructed closure defined by `compilePseudoclosure`. // See "START - compiled closures" section. return `${PSEUDOCLOSURE}.applyCasing`; } -} \ No newline at end of file +} + +// Because it references the class field, this line must come afterward. +const PSEUDOCLOSURE = ModelDefinitions.COMPILED_NAME; \ No newline at end of file diff --git a/developer/js/tests/test-model-pseudoclosure.ts b/developer/js/tests/test-model-definitions.ts similarity index 95% rename from developer/js/tests/test-model-pseudoclosure.ts rename to developer/js/tests/test-model-definitions.ts index 2a94f647f2..5ed1ea4673 100644 --- a/developer/js/tests/test-model-pseudoclosure.ts +++ b/developer/js/tests/test-model-definitions.ts @@ -1,6 +1,6 @@ import 'mocha'; import { assert } from 'chai'; -import { ModelPseudoclosure } from '../dist/lexical-model-compiler/model-pseudoclosure'; +import { ModelDefinitions } from '../dist/lexical-model-compiler/model-definitions'; describe('Model definition pseudoclosures', function () { describe('14.0 defaults', function() { @@ -13,7 +13,7 @@ describe('Model definition pseudoclosures', function () { format: 'trie-1.0' }; - let pseudoclosure = new ModelPseudoclosure(modelSource); + let pseudoclosure = new ModelDefinitions(modelSource); const testCases: [string, string, string][] = [ // Note: not written the Turkish way. Turns out 'İ'.toLowerCase() decomposes the result, @@ -61,7 +61,7 @@ describe('Model definition pseudoclosures', function () { format: 'trie-1.0' }; - let pseudoclosure = new ModelPseudoclosure(modelSource); + let pseudoclosure = new ModelDefinitions(modelSource); const testCases: [string, string][] = [ // Note: not written the Turkish way. Turns out 'İ'.toLowerCase() decomposes the result, @@ -99,7 +99,7 @@ describe('Model definition pseudoclosures', function () { format: 'trie-1.0' }; - let pseudoclosure = new ModelPseudoclosure(modelSource); + let pseudoclosure = new ModelDefinitions(modelSource); const testCases: [string, string][] = [ // Note: not written the Turkish way. Turns out 'İ'.toLowerCase() decomposes the result, @@ -163,7 +163,7 @@ describe('Model definition pseudoclosures', function () { format: 'trie-1.0' }; - let pseudoclosure = new ModelPseudoclosure(modelSource); + let pseudoclosure = new ModelDefinitions(modelSource); const testCases: [string, string, string][] = [ ['İstanbul', 'istanbul', 'istanbul'],