- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattributeExtraction.py
More file actions
Latest commit
73 lines (67 loc) · 2.61 KB
/
Copy pathattributeExtraction.py
File metadata and controls
73 lines (67 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
__author__='yangchen'
importre
defwordSegment(filePath):
f=open(filePath)
lineList= []
attributeList= []
forlineinf.readlines():
line1=line.strip()
print(line1.__class__)
if((len(line1) !=0) and (line1[-1] ==';')):
lineList.append(line1.split(' '))
if(line1[-2] ==']'orline1[-2] =='"'):
attributeList.append(lineList[-1][0])
else:
attributeList.append(lineList[-1][:-1])
return(lineList, attributeList)
defreadLibrary(path):
f=open(path)
commandList= []
forlinesinf:
commandList.append(lines.strip())
return(commandList)
deffindAllIndex(longStr, subStr):
i=0
l=len(longStr)
s=len(subStr)
offsetList= []
while(i<landlongStr[i:].find(subStr) !=-1):
offsetList.append(i+longStr[i:].find(subStr))
i=offsetList[-1]+s
return(offsetList)
defcommandsMatch(filePath):
commandList=readLibrary('AllCommandersOutput.txt')
occurredCommand= []
f=open(filePath)
count=0
forlinesinf:
count+=1
commandDict1=dict()
commandDict2=dict()
forcommandincommandList:
offsetList=findAllIndex(lines, command)
length=len(command)
if(len(offsetList) >0):
foroffsetinoffsetList:
if(offset==0and (lines[length] ==' 'orlines[length] =='\n')):
if(offsetincommandDict1.keys()):
commandDict1[offset].append(command)
else:
commandDict1[offset] = []
commandDict1[offset].append(command)
elif(offset>0andlines[offset-1] ==' 'and (lines[offset+length] ==' 'orlines[offset+length] =='\n')):
if(len(commandDict2) ==0):
commandDict2[offset] = []
commandDict2[offset].append(command)
else:
if(offsetincommandDict2.keys()):
commandDict2[offset].append(command)
else:
commandDict2[offset] = []
commandDict2[offset].append(command)
#print(count, commandDict1, commandDict2)
forkeysincommandDict1:
occurredCommand.append(commandDict1[keys][-1])
forkeysincommandDict2:
occurredCommand.append(commandDict2[keys][-1])
return(list(set(occurredCommand)))