Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support special chars in intent name when parsing lu with antlr #1058

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions packages/lu/src/parser/lufile/LUFileLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ fragment X: 'x' | 'X';
fragment Y: 'y' | 'Y';
fragment Z: 'z' | 'Z';

fragment LETTER: 'a'..'z' | 'A'..'Z';
fragment NUMBER: '0'..'9';

fragment WHITESPACE
: ' '|'\t'|'\ufeff'|'\u00a0'
;
Expand Down Expand Up @@ -169,11 +166,7 @@ NEWLINE_IN_NAME
;

IDENTIFIER
: (LETTER | NUMBER | '_') (LETTER | NUMBER | '-' | '_')*
;

DOT
: '.'
: ~[ \t\r\n]+
;

mode LIST_BODY_MODE;
Expand Down
2 changes: 1 addition & 1 deletion packages/lu/src/parser/lufile/LUFileParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nestedIntentName
;

nameIdentifier
: IDENTIFIER (DOT IDENTIFIER)*
: IDENTIFIER
;

nestedIntentBodyDefinition
Expand Down
7 changes: 1 addition & 6 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.interp

Large diffs are not rendered by default.

940 changes: 464 additions & 476 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.js

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ NEW_ENTITY_IDENTIFIER=26
NEW_ENTITY_IDENTIFIER_WITH_WS=27
NEWLINE_IN_NAME=28
IDENTIFIER=29
DOT=30
ESCAPE_CHARACTER=31
EXPRESSION=32
TEXT=33
NEWLINE_IN_ENTITY=34
COMPOSITE_ENTITY=35
REGEX_ENTITY=36
ENTITY_TEXT=37
COLON_MARK=38
NEWLINE_IN_QNA=39
QNA_TEXT=40
ESCAPE_CHARACTER=30
EXPRESSION=31
TEXT=32
NEWLINE_IN_ENTITY=33
COMPOSITE_ENTITY=34
REGEX_ENTITY=35
ENTITY_TEXT=36
COLON_MARK=37
NEWLINE_IN_QNA=38
QNA_TEXT=39
'$'=9
'@'=10
'='=18
','=19
'.'=30
':'=38
':'=37
4 changes: 1 addition & 3 deletions packages/lu/src/parser/lufile/generated/LUFileParser.interp

Large diffs are not rendered by default.

1,504 changes: 733 additions & 771 deletions packages/lu/src/parser/lufile/generated/LUFileParser.js

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions packages/lu/src/parser/lufile/generated/LUFileParser.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ NEW_ENTITY_IDENTIFIER=26
NEW_ENTITY_IDENTIFIER_WITH_WS=27
NEWLINE_IN_NAME=28
IDENTIFIER=29
DOT=30
ESCAPE_CHARACTER=31
EXPRESSION=32
TEXT=33
NEWLINE_IN_ENTITY=34
COMPOSITE_ENTITY=35
REGEX_ENTITY=36
ENTITY_TEXT=37
COLON_MARK=38
NEWLINE_IN_QNA=39
QNA_TEXT=40
ESCAPE_CHARACTER=30
EXPRESSION=31
TEXT=32
NEWLINE_IN_ENTITY=33
COMPOSITE_ENTITY=34
REGEX_ENTITY=35
ENTITY_TEXT=36
COLON_MARK=37
NEWLINE_IN_QNA=38
QNA_TEXT=39
'$'=9
'@'=10
'='=18
','=19
'.'=30
':'=38
':'=37
14 changes: 14 additions & 0 deletions packages/lu/test/parser/lufile/parseFileContents.parseFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,4 +1076,18 @@ describe('parseFile correctly parses utterances', function () {
})
.catch(err => done(err))
})

it ('Correctly parses intent name with special chars', function(done){
let testLU = `
# test'á
- Hello world
`;
parseFile.parseFile(testLU)
.then(res => {
assert.equal(res.LUISJsonStructure.intents.length, 1);
assert.equal(res.LUISJsonStructure.intents[0].name, "test'á");
done();
})
.catch(err => done(err))
})
})
7 changes: 7 additions & 0 deletions packages/luis/test/commands/luis/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ describe('luis:convert', () => {
let parsedObjects = await parseJsonFiles('./../../../results/root41.json', './../../fixtures/verified/merge_intents_disabled.json')
expect(parsedObjects[0]).to.deep.equal(parsedObjects[1])
})

test
.stdout()
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/testcases/intent_name_with_special_chars.json')}`, '--out', './results/root36.lu',])
.it('luis:convert lu file with special chars in intent name', async () => {
expect(await compareLuFiles('./../../../results/root36.lu', './../../fixtures/verified/intent_name_with_special_chars.lu')).to.be.true
})
})


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"luis_schema_version": "7.0.0",
"intents": [
{
"name": "intent_name_with_á_and_'_chars",
"features": []
},
{
"name": "None",
"features": []
}
],
"entities": [],
"hierarchicals": [],
"composites": [],
"closedLists": [],
"prebuiltEntities": [],
"utterances": [
{
"text": "test",
"intent": "intent_name_with_á_and_'_chars",
"entities": []
}
],
"versionId": "0.1",
"name": "intent_name_with_special_chars",
"desc": "",
"culture": "en-us",
"tokenizerVersion": "1.0.0",
"patternAnyEntities": [],
"regex_entities": [],
"phraselists": [],
"regex_features": [],
"patterns": [],
"settings": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

> LUIS application information
> !# @app.name = intent_name_with_special_chars
> !# @app.versionId = 0.1
> !# @app.culture = en-us
> !# @app.luis_schema_version = 7.0.0
> !# @app.tokenizerVersion = 1.0.0


> # Intent definitions

# intent_name_with_á_and_'_chars
- test


# None


> # Entity definitions


> # PREBUILT Entity definitions


> # Phrase list definitions


> # List entities

> # RegEx entities