50222
|
1 |
# Title: HOL/Tools/Sledgehammer/MaSh/src/readData.py
|
|
2 |
# Author: Daniel Kuehlwein, ICIS, Radboud University Nijmegen
|
|
3 |
# Copyright 2012
|
|
4 |
#
|
|
5 |
# All functions to read the Isabelle output.
|
|
6 |
|
50220
|
7 |
'''
|
|
8 |
All functions to read the Isabelle output.
|
|
9 |
|
|
10 |
Created on July 9, 2012
|
|
11 |
|
|
12 |
@author: Daniel Kuehlwein
|
|
13 |
'''
|
|
14 |
|
|
15 |
import sys,logging
|
|
16 |
|
50827
|
17 |
def create_feature_dict(nameIdDict,idNameDict,maxNameId,featureIdDict,maxFeatureId,featureCountDict,inputFile):
|
50388
|
18 |
logger = logging.getLogger('create_feature_dict')
|
50220
|
19 |
featureDict = {}
|
50388
|
20 |
IS = open(inputFile,'r')
|
50220
|
21 |
for line in IS:
|
|
22 |
line = line.split(':')
|
50388
|
23 |
name = line[0]
|
50220
|
24 |
# Name Id
|
|
25 |
if nameIdDict.has_key(name):
|
|
26 |
logger.warning('%s appears twice in the feature file. Aborting.',name)
|
|
27 |
sys.exit(-1)
|
|
28 |
else:
|
|
29 |
nameIdDict[name] = maxNameId
|
|
30 |
idNameDict[maxNameId] = name
|
|
31 |
nameId = maxNameId
|
50388
|
32 |
maxNameId += 1
|
50220
|
33 |
# Feature Ids
|
50388
|
34 |
featureNames = [f.strip() for f in line[1].split()]
|
50827
|
35 |
features = []
|
50220
|
36 |
for fn in featureNames:
|
50827
|
37 |
weight = 1.0
|
50388
|
38 |
tmp = fn.split('=')
|
|
39 |
if len(tmp) == 2:
|
50827
|
40 |
fn = tmp[0]
|
|
41 |
weight = float(tmp[1])
|
|
42 |
if not featureIdDict.has_key(fn):
|
|
43 |
featureIdDict[fn] = maxFeatureId
|
|
44 |
featureCountDict[maxFeatureId] = 0
|
|
45 |
maxFeatureId += 1
|
|
46 |
fId = featureIdDict[fn]
|
|
47 |
features.append((fId,weight))
|
|
48 |
featureCountDict[fId] += 1
|
50220
|
49 |
# Store results
|
50388
|
50 |
featureDict[nameId] = features
|
50220
|
51 |
IS.close()
|
50827
|
52 |
return featureDict,maxNameId,maxFeatureId,featureCountDict
|
50388
|
53 |
|
50220
|
54 |
def create_dependencies_dict(nameIdDict,inputFile):
|
|
55 |
logger = logging.getLogger('create_dependencies_dict')
|
|
56 |
dependenciesDict = {}
|
|
57 |
IS = open(inputFile,'r')
|
|
58 |
for line in IS:
|
|
59 |
line = line.split(':')
|
50388
|
60 |
name = line[0]
|
50220
|
61 |
# Name Id
|
|
62 |
if not nameIdDict.has_key(name):
|
|
63 |
logger.warning('%s is missing in nameIdDict. Aborting.',name)
|
|
64 |
sys.exit(-1)
|
|
65 |
|
|
66 |
nameId = nameIdDict[name]
|
50388
|
67 |
dependenciesIds = [nameIdDict[f.strip()] for f in line[1].split()]
|
50220
|
68 |
# Store results, add p proves p
|
|
69 |
dependenciesDict[nameId] = [nameId] + dependenciesIds
|
|
70 |
IS.close()
|
|
71 |
return dependenciesDict
|
|
72 |
|
|
73 |
def create_accessible_dict(nameIdDict,idNameDict,maxNameId,inputFile):
|
|
74 |
logger = logging.getLogger('create_accessible_dict')
|
|
75 |
accessibleDict = {}
|
|
76 |
IS = open(inputFile,'r')
|
|
77 |
for line in IS:
|
|
78 |
line = line.split(':')
|
50388
|
79 |
name = line[0]
|
50220
|
80 |
# Name Id
|
|
81 |
if not nameIdDict.has_key(name):
|
|
82 |
logger.warning('%s is missing in nameIdDict. Adding it as theory.',name)
|
|
83 |
nameIdDict[name] = maxNameId
|
|
84 |
idNameDict[maxNameId] = name
|
|
85 |
nameId = maxNameId
|
50388
|
86 |
maxNameId += 1
|
50220
|
87 |
else:
|
|
88 |
nameId = nameIdDict[name]
|
|
89 |
accessibleStrings = line[1].split()
|
|
90 |
accessibleDict[nameId] = [nameIdDict[a.strip()] for a in accessibleStrings]
|
|
91 |
IS.close()
|
|
92 |
return accessibleDict,maxNameId
|