This article is a continuation of the article “ Designing intents with Apache NlpCraft ” and contains a detailed description of the capabilities of the NlpCraft IDL intent definition language, created for use in NLP projects based on the Apache NlpCraft system . NlpCraft IDL support has been added to the system since version 0.7.5 .
The new version of the declarative intents definition language, called NlpCraft IDL (NlpCraft Intents Definition Language), greatly simplified the process of working with intents in dialog and search engines built on the basis of the Apache NlpCraft project and at the same time expanded the capabilities of the system.
NlpCraft IDL is a declarative language that allows you to create intent definitions for use in Apache NlpCraft models .
Let's start with examples that demonstrate the general capabilities of the language, provide the necessary explanations, and then describe the constructions of the language a little more formally.
, , NLP , .
, NlpCraft IDL
intent=xa
flow="^(?:login)(^:logout)*$"
meta={'enabled': true}
term(a)={!(tok_id()) != "z"}[1,3]
term(b)={
meta_intent('enabled') == true &&
month() == 1
}
term(c)~{
@tokId = tok_id()
@usrTypes = meta_model('user_types')
(tokId == 'order' || tokId == 'order_cancel') &&
has_all(@usrTypes, list(1, 2, 3) &&
abs(meta_tok('order:size')) > 10
)
}
:
- “xa”.
terms. Term - , , .
(a) - “z”, ( term =) .
(b) - - ”enabled” . , - month().
(c) - ( term ~) “order” “order_cancel”. , . , .
Flow. , , “login”, “logout”. , . .
Meta. , , .
intent=xb
flow=/#flowModelMethod/
ordered=true
term(a)=/org.mypackage.MyClass#termMethod/?
fragment(frag)
:
- “xb”.
term (”a”, , “?“, ), - org.mypackage.MyClass#termMethod.
Fragment “frag” terms , , terms. “frag” import.
Flow , flowModelMethod.
.
NlpCraft IDL
flow, fragment, import, intent, meta, ordered, term, true, false, null.
intent, flow, fragment, meta, ordered, term - .
fragment terms, .
import - fragment, intent import.
true, false, null - , .
NlpCraft IDL
, :
import
fragment
intent
“import” URL .
: import('http://mysite.com/nlp/idls/external.idl)
“fragment” terms. Terms .
fragment:
fragment=buzz term~{tok_id() == 'x:alarm'}
fragment c ‘a’ ‘b’:
fragment=p1
term={
meta_frag('a') &&
has_any(get(meta_frag('b'), ''), list(1, 2))
}
fragment . ‘a’ ‘b’ .
intent=i1
fragment(p1, {'a': true, 'b': {'': [1, 2, 3]}})
. - , . "timeIntent".
@NCIntentRef("timeIntent")
fun onTimeMatch(
ctx: NCIntentMatch,
@NCIntentTerm("t1") tok: NCToken
): NCResult { ... }
terms
. Term - . term , term. - .
term:
term. .
. . , , “t1”.
term. . term:
:
term(nums)~{tok_id() == 'nlpcraft:num'}
term terms , .
term. . term: .
:
term(nums)={tok_id() == 'nlpcraft:num'}
term(nums)~{true}
term~/org.mypackage.MyClass#termMethod/?
term.
. . :
[M, N] - N M .
* - , [0, ∞]
+ - , [1, ∞]
? - 0 1 , [0, 1]
:
term(nums)={tok_id() == 'nlpcraft:num'}[1,2]
- “nlpcraft:num”.
term(nums)={tok_id() == 'nlpcraft:num'}*
- “nlpcraft:num”.
NlpCraft IDL.
:
- , . : tok_id(), tok_groups(), tok_parent().
NLP - , , , -. : tok_lemma(), tok_is_wordnet(), tok_swear().
, - .. : tok_value(), tok_is_permutated(), tok_is_direct().
- , user agent. : req_tstamp(), req_addr(), req_agent().
- , , .. : meta_model('my:prop'), meta_tok('nlpcraft:num:unit'), meta_user('my:prop').
, NER . , “geo:city“ , .
- , . : user_admin(), comp_name(), user_signup_tstamp().
- , .. : meta_sys('java.home'), now(), day_of_week().
, , .. : lowercase("TeXt"), abs(-1.5), distinct(list(1, 2, 2, 3, 1)).
term - , .
, , :
term(t2)={ @a = meta_model('a') @list = list(1, 2, 3, 4) (@a == 42 || @a == 44) && has_all(@list, list(3, 2)) }
@. .
, NlpCraft IDL term . java, scala, kotlin, groovy java based term. NlpCraft IDL , .
: term(a)=/MyClass#myMethod/
Fragment
Flow
, .
regex, .
: flow="^(?:login)(^:logout)*$"
, , “login”, “logout”.
, , Java-based , term.
:
@NCIntent("intent=x
flow=/com.company.dialog.Flow#customFlow/
term~{tok_id() == 'some_id'}"
)
def onX(): NCResult = { .. }
Meta
. JSON.
Ordered flag
. false. - terms .
, , NlpCraft IDL, java based . ? , , - .
NlpCraft IDL.
. DSL . .
NlpCraft IDL , IDL , , .
. . , DSL .
java based . Apache NlpCraft . NlpCraft IDL .
I hope you were able to get a first idea of the capabilities of the NlpCraft IDL intent language and the types of problems that can be solved using it. Here you will find a detailed description of the language and its capabilities. Additional examples of models created in java, kotlin, groovy and scala, using NlpCraft IDL to define intents, are available in the project github .