Linguagem de intenção NlpCraft IDL

Este artigo é uma continuação do artigo “ Projetando intents com Apache NlpCraft ” e contém uma descrição detalhada dos recursos da linguagem de definição de intent NlpCraft IDL, criada para uso em projetos de PNL baseados no sistema Apache NlpCraft . O suporte NlpCraft IDL foi adicionado ao sistema desde a versão 0.7.5 .   





A nova versão da linguagem de definição de intenções declarativas, chamada NlpCraft IDL (NlpCraft Intents Definition Language), simplificou muito o processo de trabalhar com intenções em mecanismos de diálogo e busca criados com base no projeto Apache NlpCraft e ao mesmo tempo expandiu os recursos do sistema.  





NlpCraft IDL é uma linguagem declarativa que permite criar definições de intenção para uso em modelos Apache NlpCraft.





Vamos começar com exemplos que demonstram as capacidades gerais da linguagem, fornecer as explicações necessárias e, em seguida, descrever as construções da linguagem um pouco mais formalmente. 





, , 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 . .





  • , NlpCraft IDL   . .





  • . .  





  • , . URL import. , IDE (, , Intellij Idea , ). , . : 1, 2.  





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





. , IDE . import fragment .  





“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

Fragment terms, .





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 = { .. }
      
      



, customFlow(), , , boolean. 





Meta

. JSON.





Ordered flag

. false. - terms .  





, , NlpCraft IDL, java based . ? , , - . 





NlpCraft IDL.





  • . DSL . . 





  • NlpCraft IDL , IDL , , .





  • . . , DSL .  





  • java based . Apache NlpCraft . NlpCraft IDL .





Espero que você tenha conseguido uma primeira ideia dos recursos da linguagem de intenção NlpCraft IDL e os tipos de problemas que podem ser resolvidos com sua ajuda. Aqui você encontrará uma descrição detalhada do idioma e seus recursos. Exemplos adicionais de modelos criados em java, kotlin, groovy e scala, usando NlpCraft IDL para definir intents, estão disponíveis no github do projeto.








All Articles