PCART  v1.4
Automated Repair of Python API Parameter Compatibility Issues
fuzzyMatch.py
Go to the documentation of this file.
1 
10 
11 
12 
13 
15 class fuzzyMatch:
16 
18  def __init__(self):
19 
21  self.aliasalias=''
22 
23 
37  def fmatch(self,callAPI,libAPIs):
38  ans=[]
39  cnamelst=callAPI.split('.')
40  lst=[]
41  #对库API进行预处理
42  for libAPI in libAPIs:
43  dname=libAPI.split('(')[0] #此处丢掉参数,只保留函数名
44  dnamelst=dname.split('.')
45  if cnamelst[-1]==dnamelst[-1]: #先按最后一个名字确定对应关系,若相同则将其保存
46  lst.append(libAPI)
47  #模糊匹配找到的结果包含两种,同名的+同名的重载
48  if len(lst)>0:
49  ans=lst
50  return ans
51  #如果没找到,则再判断是否为python内置api
52  buildIns=[]
53  for it in dir(str)+dir(list)+dir(dict):
54  if it[0]!='_':
55  buildIns.append(it)
56  if cnamelst[-1] in buildIns and len(cnamelst)!=2:
57  return []
58 
59  #否则认为该API可能是库中的一个别名
60  self.aliasalias=callAPI
61  return ans
Static mapping class for lib API definitions 库API定义静态匹配类
Definition: fuzzyMatch.py:15
def fmatch(self, callAPI, libAPIs)
Fuzzy match the called API against the library API definitions 将调用API与库API定义进行模糊匹配
Definition: fuzzyMatch.py:37
def __init__(self)
Initialize the fuzzy matcher 初始化模糊匹配器
Definition: fuzzyMatch.py:18
alias
The alias name used when no direct match is found 未找到直接匹配时使用的别名
Definition: fuzzyMatch.py:21