Research Article

Software Defect Prediction via Attention-Based Recurrent Neural Network

Algorithm 2

Encoding ASTs’ string vectors.
Input: ASTs’ string vectors , the fixed length of each vector m;
Output: integer vectors ;
(1)Initialize a list V, a dict and a dict ;
(2)for do
(3)for do
(4)  if not in tokFreq.keys then
(5)   ;
(6)  end
(7)  ;
(8)end
(9)end
(10)Creating a list sorted in descending order of token frequency which contains tuples of each token and its corresponding frequency;
(11)for do
(12);
(13); // establishing a dict of the ordered tokens to map them into integers
(14)end
(15)for do
(16)for do
(17)  ;
(18)end
(19)if then
(20)  Adding 0s into ;
(21)end
(22)else if then
(23)  for do
(24)   ; // finding the index of the lowest token frequency ; // deleting the token
(25)  end
(26)end
(27) Adding into V;
(28)end
(29)return V;