mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-06 14:07:32 +00:00
change(developer/compilers): ModelPseudoclosure -> ModelDefinitions
This commit is contained in:
parent
67e08be599
commit
60113a3147
3 changed files with 18 additions and 21 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Because it references the class field, this line must come afterward.
|
||||
const PSEUDOCLOSURE = ModelDefinitions.COMPILED_NAME;
|
||||
|
|
@ -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'],
|
||||
Loading…
Add table
Reference in a new issue