Skip to content
Permalink
Browse files

Add i18n to references to UI Element properties

  • Loading branch information...
thiagodp committed Jul 12, 2019
1 parent 10af772 commit 71262e5457f482cf71134bb025f2c64775271f4e
@@ -423,6 +423,22 @@ describe( 'NLP', () => {
recogUIPropertyRef( ' {F:A|value} ', 'F:A|value' );
} );

it( 'with property that contain spaces', () => {
recogUIPropertyRef( '{D:A|comprimento mínimo}', 'D:A|comprimento mínimo' );
} );

it( 'with spaces in the left', () => {
recogUIPropertyRef( '{ D:A|comprimento mínimo}', 'D:A|comprimento mínimo' );
} );

it( 'with spaces in the right', () => {
recogUIPropertyRef( '{D:A|comprimento mínimo }', 'D:A|comprimento mínimo' );
} );

it( 'with spaces around', () => {
recogUIPropertyRef( '{ D:A|comprimento mínimo }', 'D:A|comprimento mínimo' );
} );

} );

describe( 'does not recognize', () => {
@@ -439,9 +455,9 @@ describe( 'NLP', () => {
recogUIPropertyRef( ' { |value} ', null );
} );

it( 'with an unsupported property', () => {
recogUIPropertyRef( ' {A|foo} ', null );
} );
// it( 'with an unsupported property', () => {
// recogUIPropertyRef( ' {A|foo} ', null );
// } );

} );

@@ -2,7 +2,7 @@ import { Location } from "concordialang-types";

import { UIPropertyReferenceReplacer } from '../../modules/testscenario/UIPropertyReferenceReplacer';
import { Step, EntityValueType } from '../../modules/ast';
import { SimpleCompiler } from "../../modules/util";
import { SimpleCompiler, UIPropertyReferenceExtractor } from "../../modules/util";
import { AugmentedSpec } from "../../modules/req";
import { LocatedException } from "../../modules/error/LocatedException";
import { GenContext } from "../../modules/testscenario/PreTestCaseGenerator";
@@ -16,6 +16,7 @@ describe( 'UIPropertyReferenceReplacer', () => {

function chk( line: string, key: string, value: any, expected: string ): void {

const extractor = new UIPropertyReferenceExtractor();
const replacer = new UIPropertyReferenceReplacer(); // immutable

const compiler = new SimpleCompiler( 'en' );
@@ -38,7 +39,9 @@ describe( 'UIPropertyReferenceReplacer', () => {
uieVarToValue.set( key, value );

let step: Step = doc.feature.scenarios[ 0 ].variants[ 0 ].sentences[ 1 ]; // Then...
const sentence = replacer.replaceUIPropertyReferencesByTheirValue( step, uieVarToValue, ctx );
let references = extractor.extractReferences( step.nlpResult.entities, step.location.line );

const sentence = replacer.replaceUIPropertyReferencesByTheirValue( step, references, uieVarToValue, ctx );
expect( sentence ).toEqual( expected );
}

@@ -22,7 +22,7 @@ describe( 'UIPropertyReferenceExtractor', () => {
const nlp = makeTrainedNLP();
const result: NLPResult = nlp.recognize( 'en', text );
const replacer = new UIPropertyReferenceExtractor();
return replacer.extractReferences( result, line );
return replacer.extractReferences( result.entities, line );
}

describe( 'extractReferences', () => {
@@ -69,11 +69,11 @@ describe( 'UIPropertyReferenceExtractor', () => {
expect( references[ 2 ].property ).toEqual( 'maxvalue' );
} );

it( 'does not extract a not valid property', () => {
const references: UIPropertyReference[] = extractReferences(
'When I drag {Foo|bar}, {Bar|foo} to {Foo}' );
expect( references ).toHaveLength( 0 );
} );
// it( 'does not extract a not valid property', () => {
// const references: UIPropertyReference[] = extractReferences(
// 'When I drag {Foo|bar}, {Bar|foo} to {Foo}' );
// expect( references ).toHaveLength( 0 );
// } );

it( 'extraction has the right column number - in the end', () => {
const references: UIPropertyReference[] = extractReferences(
@@ -206,12 +206,12 @@
"id": [ "id", "identification", "identificator" ],
"type": [ "type" ],
"editable": [ "editable" ],
"datatype": [ "data type", "datatype" ],
"datatype": [ "datatype", "data type" ],
"value": [ "value" ],
"minlength": [ "min length", "minimum length", "minlength" ],
"maxlength": [ "max length", "maximum length", "maxlength" ],
"minvalue": [ "min value", "minimum value", "minvalue" ],
"maxvalue": [ "max value", "maximum value", "maxvalue" ],
"minlength": [ "minlength", "min length", "minimum length" ],
"maxlength": [ "maxlength", "max length", "maximum length" ],
"minvalue": [ "minvalue", "min value", "minimum value" ],
"maxvalue": [ "maxvalue", "max value", "maximum value" ],
"format": [ "format" ],
"required": [ "required", "mandatory", "obligatory", "necessary" ]
},
@@ -206,12 +206,12 @@
"id": [ "id", "identification", "identificator" ],
"type": [ "type" ],
"editable": [ "editable" ],
"datatype": [ "data type", "datatype" ],
"datatype": [ "datatype", "data type" ],
"value": [ "value" ],
"minlength": [ "min length", "minimum length", "minlength" ],
"maxlength": [ "max length", "maximum length", "maxlength" ],
"minvalue": [ "min value", "minimum value", "minvalue" ],
"maxvalue": [ "max value", "maximum value", "maxvalue" ],
"minlength": [ "minlength", "min length", "minimum length" ],
"maxlength": [ "maxlength", "max length", "maximum length" ],
"minvalue": [ "minvalue", "min value", "minimum value" ],
"maxvalue": [ "maxvalue", "max value", "maximum value" ],
"format": [ "format" ],
"required": [ "required", "mandatory", "obligatory", "necessary" ]
},
@@ -53,14 +53,14 @@ class Lexer {
this._lexers = [];
this._lexersMap = new Map(); // iterable in insertion order
this._lastLexer = null;
this._subLexers = [];
this._tagSubLexers = [];
this._inLongString = false;
this._mustRecognizeAsText = false;
const dictionary = this.loadDictionary(_defaultLanguage); // may throw Error
if (!dictionary) {
throw new Error('Cannot load a dictionary for the language: ' + _defaultLanguage);
}
this._subLexers = [
this._tagSubLexers = [
new TagLexer_1.TagSubLexer(ast_1.ReservedTags.IGNORE, dictionary.tagIgnore),
new TagLexer_1.TagSubLexer(ast_1.ReservedTags.GENERATED, dictionary.tagGenerated),
new TagLexer_1.TagSubLexer(ast_1.ReservedTags.FAIL, dictionary.tagFail),
@@ -74,7 +74,7 @@ class Lexer {
this._lexers = [
new LongStringLexer_1.LongStringLexer(),
new LanguageLexer_1.LanguageLexer(dictionary.language),
new TagLexer_1.TagLexer(this._subLexers),
new TagLexer_1.TagLexer(this._tagSubLexers),
new ImportLexer_1.ImportLexer(dictionary.import),
new FeatureLexer_1.FeatureLexer(dictionary.feature),
new BackgroundLexer_1.BackgroundLexer(dictionary.background),
@@ -266,7 +266,7 @@ class Lexer {
this.updateKeywordBasedLexer(lexer, dict);
}
}
for (let subLexer of this._subLexers) {
for (let subLexer of this._tagSubLexers) {
this.updateKeywordBasedLexer(subLexer, dict);
}
return dict;
@@ -1,10 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Bravey = require("../../lib/bravey"); // .js file
const enumUtil = require("enum-util");
const ValueTypeDetector_1 = require("../util/ValueTypeDetector");
const nlp_1 = require("../nlp");
const UIPropertyTypes_1 = require("../ast/UIPropertyTypes");
/**
* Natural Language Processor
*
@@ -217,13 +215,12 @@ class EntityRecognizerMaker {
* @return Bravey.EntityRecognizer
*/
makeUIPropertyReference(entityName) {
const values = enumUtil.getValues(UIPropertyTypes_1.UIPropertyTypes);
var valueRec = new Bravey.RegexEntityRecognizer(entityName, 10);
const regexStr = '\\{[a-zA-ZÀ-ÖØ-öø-ÿ]+\\:?[a-zA-ZÀ-ÖØ-öø-ÿ]*\\|(' + values.join('|') + ')\\}';
const regexStr = '\\{[ ]*[a-zA-ZÀ-ÖØ-öø-ÿ]+[a-zA-ZÀ-ÖØ-öø-ÿ ]*\\:?[a-zA-ZÀ-ÖØ-öø-ÿ ]*\\|[a-zA-ZÀ-ÖØ-öø-ÿ ]+\\}';
const regex = new RegExp(regexStr, "g");
valueRec.addMatch(regex, function (match) {
const value = match[0] || '';
return value.substring(1, value.length - 1); // exclude { and }
return value.substring(1, value.length - 1).trim(); // exclude { and } and trim
}, 100 // priority
);
return valueRec;
@@ -18,7 +18,6 @@ const SyntaxRules_1 = require("./SyntaxRules");
class UIPropertyRecognizer {
constructor(_nlp) {
this._nlp = _nlp;
this._valueTypeDetector = new ValueTypeDetector_1.ValueTypeDetector();
this._syntaxRules = this.buildSyntaxRules();
}
nlp() {

This file was deleted.

0 comments on commit 71262e5

Please sign in to comment.
You can’t perform that action at this time.