forked from HoloClean/holoclean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcparser.py
54 lines (47 loc) · 1.61 KB
/
dcparser.py
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
import logging
import os
import time
from .constraint import DenialConstraint
class Parser:
"""
This class creates interface for parsing denial constraints
"""
def __init__(self, env, dataset):
"""
Constructing parser interface object
:param session: session object
"""
self.env = env
self.ds = dataset
self.dc_strings = []
self.dcs = []
def load_denial_constraints(self, fpath):
"""
Loads denial constraints from line-separated TXT file
:param fpath: filepath to TXT file containing denial constraints
"""
tic = time.clock()
if not self.ds.raw_data:
status = 'No dataset specified'
toc = time.clock()
return status, toc - tic
attrs = self.ds.raw_data.get_attributes()
try:
dc_file = open(fpath, 'r')
status = "OPENED constraints file successfully"
logging.debug(status)
for line in dc_file:
line = line.rstrip()
# Skip empty and comment lines.
if not line or line.startswith('#'):
continue
self.dc_strings.append(line)
self.dcs.append(DenialConstraint(line,attrs))
status = 'DONE Loading DCs from {fname}'.format(fname=os.path.basename(fpath))
except Exception:
logging.error('FAILED to load constraints from file %s', os.path.basename(fpath))
raise
toc = time.clock()
return status, toc - tic
def get_dcs(self):
return self.dcs