// Ġ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 . ml . Completion Environment Ċ import Ġcom . intellij . code Insight . completion . ml . Context Feature Provider Ċ import Ġcom . intellij . code Insight . completion . ml . ML Feature Value Ċ import Ġcom . jetbrains . python . psi . types . Type Eval Context Ċ Ċ class ĠPy Context Feature Provider Ġ: ĠContext Feature Provider Ġ{ ĊĠ Ġoverride Ġfun ĠgetName (): ĠString Ġ= Ġ" python " ĊĊĠ Ġoverride Ġfun Ġcalculate Features ( environment : ĠCompletion Environment ): ĠMap < String , ĠML Feature Value > Ġ{ ĊĠĠĠ Ġval Ġresult Ġ= ĠHashMap < String , ĠML Feature Value >() ĊĠĠĠ Ġval Ġposition Ġ= Ġenvironment . parameters . position ĊĠĠĠ Ġval Ġtype Eval Context Ġ= ĠType Eval Context . code Insight Fallback ( position . project ) ĊĊĠĠĠ Ġresult [" is _ in _ condition "] Ġ= ĠML Feature Value . binary ( Py Completion Features . isIn Condition ( position )) ĊĠĠĠ Ġresult [" is _ after _ if _ statement _ without _ else _ branch "] Ġ= ĠML Feature Value . binary ( Py Completion Features . is After If Statement Without Else Branch ( position )) ĊĠĠĠ Ġresult [" is _ in _ for _ statement "] Ġ= ĠML Feature Value . binary ( Py Completion Features . isIn For Statement ( position )) ĊĠĠĠ Ġresult [" num _ of _ prev _ qual ifiers "] Ġ= ĠML Feature Value . num erical ( Py Completion Features . getNumberOf Qual ifiers In Exp res ion Feature ( position )) ĊĊĠĠĠ Ġval Ġne ighbours K ws Ġ= ĠPy Completion Features . get Prev Ne ighbours Keyword Ids ( position ) ĊĠĠĠ Ġif Ġ( ne ighbours K ws . size Ġ> Ġ 0 ) Ġresult [" prev _ ne ighbour _ keyword _ 1 "] Ġ= ĠML Feature Value . num erical ( ne ighbours K ws [ 0 ]) ĊĠĠĠ Ġif Ġ( ne ighbours K ws . size Ġ> Ġ 1 ) Ġresult [" prev _ ne ighbour _ keyword _ 2 "] Ġ= ĠML Feature Value . num erical ( ne ighbours K ws [ 1 ]) ĊĊĠĠĠ Ġval Ġsame Line K ws Ġ= ĠPy Completion Features . get Prev Keywords Ids InThe Same Line ( position ) ĊĠĠĠ Ġif Ġ( same Line K ws . size Ġ> Ġ 0 ) Ġresult [" prev _ same _ line _ keyword _ 1 "] Ġ= ĠML Feature Value . num erical ( same Line K ws [ 0 ]) ĊĠĠĠ Ġif Ġ( same Line K ws . size Ġ> Ġ 1 ) Ġresult [" prev _ same _ line _ keyword _ 2 "] Ġ= ĠML Feature Value . num erical ( same Line K ws [ 1 ]) ĊĊĠĠĠ Ġval Ġsame Column K ws Ġ= ĠPy Completion Features . get Prev Keywords Ids InThe Same Column ( position ) ĊĠĠĠ Ġif Ġ( same Column K ws . size Ġ> Ġ 0 ) Ġresult [" prev _ same _ column _ keyword _ 1 "] Ġ= ĠML Feature Value . num erical ( same Column K ws [ 0 ]) ĊĠĠĠ Ġif Ġ( same Column K ws . size Ġ> Ġ 1 ) Ġresult [" prev _ same _ column _ keyword _ 2 "] Ġ= ĠML Feature Value . num erical ( same Column K ws [ 1 ]) ĊĊĠĠĠ Ġwith Ġ( Py Arguments Completion Features . getContext Argument Features ( position )) Ġ{ ĊĠĠĠĠĠ Ġresult [" is _ in _ arguments "] Ġ= ĠML Feature Value . binary ( isIn Arguments ) ĊĠĠĠĠĠ Ġresult [" is _ direct ly _ in _ arguments _ context "] Ġ= ĠML Feature Value . binary ( is Direct ly In Argument Context ) ĊĠĠĠĠĠ Ġresult [" is _ into _ keyword _ arg "] Ġ= ĠML Feature Value . binary ( is Into Keyword Argument ) ĊĠĠĠĠĠ Ġresult [" have _ named _ arg _ left "] Ġ= ĠML Feature Value . binary ( have Named Arg Left ) ĊĠĠĠĠĠ Ġresult [" have _ named _ arg _ right "] Ġ= ĠML Feature Value . binary ( have Named Arg Right ) ĊĠĠĠĠĠ Ġargument Index ?. let Ġ{ Ġresult [" argument _ index "] Ġ= ĠML Feature Value . num erical ( it ) Ġ} ĊĠĠĠĠĠ Ġarguments Size ?. let Ġ{ Ġresult [" number _ of _ arguments _ already "] Ġ= ĠML Feature Value . num erical ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPy Receiver Ml Completion Features . calculate Receiver Element Info ( environment , Ġtype Eval Context ) ĊĠĠĠ ĠPy Names Matching Ml Completion Features . calculate Fun Body Names ( environment ) ĊĊĠĠĠ ĠPy Names Matching Ml Completion Features . calculate Same Line Left Names ( environment ). let Ġ{ Ġnames Ġ-> ĊĠĠĠĠĠ Ġresult [" have _ opening _ round _ bracket "] Ġ= ĠML Feature Value . binary ( Py Parent heses Features . have Opening Round Bracket ( names )) ĊĠĠĠĠĠ Ġresult [" have _ opening _ square _ bracket "] Ġ= ĠML Feature Value . binary ( Py Parent heses Features . have Opening Square Bracket ( names )) ĊĠĠĠĠĠ Ġresult [" have _ opening _ brace "] Ġ= ĠML Feature Value . binary ( Py Parent heses Features . have Opening Brace ( names )) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPy Class Completion Features . getClass Completion Features ( environment )?. let Ġ{ Ġwith ( it ) Ġ{ ĊĠĠĠĠĠ Ġresult [" diff _ lines _ with _ class _ def "] Ġ= ĠML Feature Value . num erical ( diff Lines With Class Def ) ĊĠĠĠĠĠ Ġresult [" containing _ class _ have _ constructor "] Ġ= ĠML Feature Value . binary ( class Have Constructor ) ĊĠĠĠ Ġ}} ĊĊĠĠĠ Ġreturn Ġresult ĊĠ Ġ} Ċ }