// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . jetbrains . python . code Insight . ml completion Ċ Ċ import Ġcom . intellij . code Insight . completion . Completion Location Ċ import Ġcom . intellij . code Insight . completion . ml . Context Features Ċ import Ġcom . intellij . code Insight . completion . ml . Element Feature Provider Ċ import Ġcom . intellij . code Insight . completion . ml . ML Feature Value Ċ import Ġcom . intellij . code Insight . lookup . Lookup Element Ċ import Ġcom . jetbrains . python . code Insight . ml completion . prev 2 calls . Py Prev Calls Completion Features Ċ import Ġcom . jetbrains . python . psi . Py Parameter Ċ Ċ class ĠPy Element Feature Provider Ġ: ĠElement Feature Provider Ġ{ ĊĠ Ġoverride Ġfun ĠgetName (): ĠString Ġ= Ġ" python " ĊĊĠ Ġoverride Ġfun Ġcalculate Features ( element : ĠLookup Element , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation : ĠCompletion Location , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontext Features : ĠContext Features ): ĠMap < String , ĠML Feature Value > Ġ{ ĊĠĠĠ Ġval Ġresult Ġ= ĠHashMap < String , ĠML Feature Value >() ĊĊĠĠĠ Ġval Ġlookup String Ġ= Ġelement . lookup String ĊĠĠĠ Ġval Ġlocation Psi Ġ= Ġlocation . completion Parameters . position ĊĠĠĠ Ġval Ġlookup Psi Element Ġ= Ġelement . psi Element ĊĊĠĠĠ ĠPy Completion Features . get Py Lookup Element Info ( element )?. let Ġ{ Ġinfo Ġ-> ĊĠĠĠĠĠ Ġresult [" kind "] Ġ= ĠML Feature Value . categorical ( info . kind ) ĊĠĠĠĠĠ Ġresult [" is _ builtins "] Ġ= ĠML Feature Value . binary ( info . is Built ins ) ĊĠĠĠĠĠ ĠPy Completion Features . getNumberOf Occ urrences In Scope ( info . kind , Ġcontext Features , Ġlookup String )?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġresult [" number _ of _ occ urrences _ in _ scope "] Ġ= ĠML Feature Value . num erical ( it ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠPy Completion Features . get Builtin Pop ularity Feature ( lookup String , Ġinfo . is Built ins )?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġresult [" builtin _ pop ularity "] Ġ= ĠML Feature Value . num erical ( it ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPy Completion Features . getKey word Id ( lookup String )?. let Ġ{ ĊĠĠĠĠĠ Ġresult [" keyword _ id "] Ġ= ĠML Feature Value . num erical ( it ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġresult [" is _ dict _ key "] Ġ= ĠML Feature Value . binary ( Py Completion Features . is Dict Key ( element )) ĊĠĠĠ Ġresult [" is _ t akes _ parameter _ self "] Ġ= ĠML Feature Value . binary ( Py Completion Features . is T akes Parameter Self ( element )) ĊĠĠĠ Ġresult [" underscore _ type "] Ġ= ĠML Feature Value . categorical ( Py Completion Features . getElement Name Un ders core Type ( lookup String )) ĊĠĠĠ Ġresult [" number _ of _ tokens "] Ġ= ĠML Feature Value . num erical ( Py Names Matching Ml Completion Features . getNum Tokens Feature ( lookup String )) ĊĠĠĠ Ġresult [" element _ is _ py _ file "] Ġ= ĠML Feature Value . binary ( Py Completion Features . is Psi Element Is Py File ( element )) ĊĠĠĠ Ġresult [" element _ is _ psi _ directory "] Ġ= ĠML Feature Value . binary ( Py Completion Features . is Psi Element Is Psi Directory ( element )) ĊĊĠĠĠ Ġresult . put All ( Py Completion Features . getElement Psi Location Features ( element , Ġlocation )) ĊĊĠĠĠ ĠPy Completion Features . getElement Module Completion Features ( element )?. let Ġ{ Ġwith ( it ) Ġ{ ĊĠĠĠĠĠĠĠ Ġresult [" element _ module _ is _ std _ lib "] Ġ= ĠML Feature Value . binary ( is From Std Lib ) ĊĠĠĠĠĠĠĠ Ġresult [" can _ find _ element _ module "] Ġ= ĠML Feature Value . binary ( can Find Module ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPy Import Completion Features . get Import Pop ularity Feature ( location Psi , Ġlookup String )?. let Ġ{ ĊĠĠĠĠĠ Ġresult [" import _ pop ularity "] Ġ= ĠML Feature Value . num erical ( it ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPy Import Completion Features . getElement Import Path Features ( element , Ġlocation )?. let Ġ{ Ġwith Ġ( it ) Ġ{ ĊĠĠĠĠĠ Ġresult [" is _ imported "] Ġ= ĠML Feature Value . binary ( is Imported ) ĊĠĠĠĠĠ Ġresult [" num _ components _ in _ import _ path "] Ġ= ĠML Feature Value . num erical ( num Components ) ĊĠĠĠĠĠ Ġresult [" num _ private _ components _ in _ import _ path "] Ġ= ĠML Feature Value . num erical ( num Private Components ) ĊĠĠĠ Ġ}} ĊĊĠĠĠ ĠPy Names Matching Ml Completion Features . get Py Fun Class File Body Matching Features ( context Features , Ġelement . lookup String )?. let Ġ{ Ġwith ( it ) Ġ{ ĊĠĠĠĠĠ Ġresult [" scope _ num _ names "] Ġ= ĠML Feature Value . num erical ( num Scope Names ) ĊĠĠĠĠĠ Ġresult [" scope _ num _ different _ names "] Ġ= ĠML Feature Value . num erical ( num Scope Different Names ) ĊĠĠĠĠĠ Ġresult [" scope _ num _ matches "] Ġ= ĠML Feature Value . num erical ( sum Matches ) ĊĠĠĠĠĠ Ġresult [" scope _ num _ tokens _ matches "] Ġ= ĠML Feature Value . num erical ( sum Tokens Matches ) ĊĠĠĠ Ġ}} ĊĊĠĠĠ ĠPy Names Matching Ml Completion Features . get Py Same Line Matching Features ( context Features , Ġelement . lookup String )?. let Ġ{ Ġwith ( it ) Ġ{ ĊĠĠĠĠĠ Ġresult [" same _ line _ num _ names "] Ġ= ĠML Feature Value . num erical ( num Scope Names ) ĊĠĠĠĠĠ Ġresult [" same _ line _ num _ different _ names "] Ġ= ĠML Feature Value . num erical ( num Scope Different Names ) ĊĠĠĠĠĠ Ġresult [" same _ line _ num _ matches "] Ġ= ĠML Feature Value . num erical ( sum Matches ) ĊĠĠĠĠĠ Ġresult [" same _ line _ num _ tokens _ matches "] Ġ= ĠML Feature Value . num erical ( sum Tokens Matches ) ĊĠĠĠ Ġ}} ĊĊĠĠĠ ĠPy Names Matching Ml Completion Features . get Matching With Receiver Features ( context Features , Ġelement )?. let Ġ{ Ġwith ( it ) Ġ{ ĊĠĠĠĠĠ Ġresult [" receiver _ name _ matches "] Ġ= ĠML Feature Value . binary ( matches With Receiver ) ĊĠĠĠĠĠ Ġresult [" receiver _ num _ matched _ tokens "] Ġ= ĠML Feature Value . num erical ( num Matched Tokens ) ĊĠĠĠĠĠ Ġresult [" receiver _ tokens _ num "] Ġ= ĠML Feature Value . num erical ( receiver Tokens Num ) ĊĠĠĠ Ġ}} ĊĊĠĠĠ Ġresult . put All ( Py Names Matching Ml Completion Features . get Matching With En closing Method Features ( context Features , Ġelement )) ĊĊĠĠĠ Ġif Ġ( lookup String . endsWith (" Warning ")) Ġresult [" is _ warning "] Ġ= ĠML Feature Value . binary ( true ) ĊĠĠĠ Ġif Ġ( lookup String . endsWith (" Error ")) Ġresult [" is _ error "] Ġ= ĠML Feature Value . binary ( true ) ĊĠĠĠ Ġif Ġ( lookup String . endsWith (" Exception ")) Ġresult [" is _ exception "] Ġ= ĠML Feature Value . binary ( true ) ĊĠĠĠ Ġif Ġ( lookup String . endsWith (" s ")) Ġresult [" ends _ with _ s "] Ġ= ĠML Feature Value . binary ( true ) ĊĠĠĠ Ġif Ġ( lookup Psi Element Ġis ĠPy Parameter Ġ&& Ġlookup Psi Element . is Self ) Ġresult [" is _ self "] Ġ= ĠML Feature Value . binary ( true ) ĊĊĠĠĠ Ġcontext Features . getUser Data ( Py Prev Calls Completion Features . PREV _ CALL S _ CONTEXT _ INFO _ KEY )?. let Ġ{ Ġcontext Info Ġ-> ĊĠĠĠĠĠ ĠPy Prev Calls Completion Features . getResult ( lookup String , Ġcontext Info )?. let Ġ{ Ġwith Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġprimary Weight Ġ!= Ġnull Ġ-> Ġresult [" prev _ 2 _ calls _ primary _ weight "] Ġ= ĠML Feature Value . num erical ( primary Weight !! ) ĊĠĠĠĠĠĠĠĠĠ Ġweight One Call Ġ!= Ġnull Ġ-> Ġresult [" prev _ 2 _ calls _ weight _ one _ call "] Ġ= ĠML Feature Value . num erical ( weight One Call !! ) ĊĠĠĠĠĠĠĠĠĠ Ġweight Secondary Two Calls Ġ!= Ġnull Ġ-> Ġresult [" prev _ 2 _ calls _ weight _ secondary _ two _ calls "] Ġ= ĠML Feature Value . num erical ( weight Secondary Two Calls !! ) ĊĠĠĠĠĠĠĠĠĠ Ġweight Empty Prev Calls Ġ!= Ġnull Ġ-> Ġresult [" prev _ 2 _ calls _ weight _ empty _ prev _ calls "] Ġ= ĠML Feature Value . num erical ( weight Empty Prev Calls !! ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġresult ĊĠ Ġ} Ċ }