Esempio n. 1
0
 def parse(self, file):
     if not self.silent:        
         sys.stderr.write("Parsing "+file+".\n")
     f = pylib_io.flexopen(file,'r')
     l = f.readlines()
     pylib_io.flexclose(f)
     self.name = file
     for line in l:
         self.insert_line(line)
Esempio n. 2
0
 def parse(self, file):
     f = pylib_io.flexopen(file,'r')
     l = f.readlines()
     pylib_io.flexclose(f)
     for line in l:
         if line[0] == "#":
             continue
         ex = ml_example(line, self.classadmin)
         self.append(ex)            
Esempio n. 3
0
 def parse(self, file):
     f = pylib_io.flexopen(file, 'r')
     l = f.readlines()
     pylib_io.flexclose(f)
     for line in l:
         if line[0] == "#":
             continue
         ex = ml_example(line, self.classadmin)
         self.append(ex)
Esempio n. 4
0
 def sync(self):
     """
     Safe the protocol to the associated disk file (if any and if
     necessary).
     """
     if self.filename and not self.synced:
         pylib_io.verbout("Syncing "+self.filename)
         fp = pylib_io.flexopen(self.filename, "w")
         fp.write(self.__str__())
         pylib_io.flexclose(fp)
         self.synced = True
Esempio n. 5
0
 def sync(self):
     """
     Safe the protocol to the associated disk file (if any and if
     necessary).
     """
     if self.filename and not self.synced:
         pylib_io.verbout("Syncing " + self.filename)
         fp = pylib_io.flexopen(self.filename, "w")
         fp.write(self.__str__())
         pylib_io.flexclose(fp)
         self.synced = True
Esempio n. 6
0
 def dimacs_parse(self, file):
     fp = pylib_io.flexopen(file, "r")
     l = fp.readlines()
     pylib_io.flexclose(fp)
     l = [i for i in l if not (i.startswith("%") or i.startswith("#") or i.startswith("c") or i == "\n")]
     if l[-1].startswith("0"):
         if fix_broken_dimacs:
             del (l[-1])
         else:
             sys.stderr.write("Warning: Problem ends in empty " + "clause. Use --fix-broken-dimacs to suppress it")
     for i in l[1:]:
         self.add_clause(prop_clause(i))
Esempio n. 7
0
 def parse(self, file):
     f = pylib_io.flexopen(file,"r")
     l = f.readlines()
     pylib_io.flexclose(f)
     for i in l:
         if i.startswith("#"):
             continue
         tmp = string.split(i, ":");
         if len(tmp) == 4:
             del(tmp[0])
         tmp = map(string.strip, tmp)
         self.append((tmp[0], tmp[1], tmp[2]))
Esempio n. 8
0
def parse_espec_string(specstr, sourcename=None, resdict = None, joblist = None):
    """
    Parse a E spec file. 
    \param specstr        is the actual configuration text,
                          interpreted as a sequence of newline-
                          separated lines.
    \param sourcename     is a descriptive name of the source, used
                          for error messages.
    \return               Dictionary of key/value pairs and list of
                          problems. 
    """
    if not sourcename:
        sourcename = "E specification string starting with "+inpstr[:20]
    if resdict == None:
        resdict = {}
    if joblist == None:
        joblist = list([])

    spec_list = specstr.split("\n")
    lineno = 0
    for line in spec_list:
        lineno = lineno+1
        comment = line.split("#")
        line = comment[0]
        line = line.strip()
        if not line:
            continue

        try:
            (key, value) = line.split(":", 1)
            
            key = key.strip()
            value = value.strip()
            if key == "Include":
                try:
                    fp = pylib_io.flexopen(value, "r")
                    newstr = fp.read()
                    pylib_io.flexclose(fp)
                    resdict, joblist =\
                             parse_espec_string(newstr,\
                                                "Included file "+value,\
                                                resdict, joblist)
                except IOError:
                    pass # have to put logging in
            else:
                resdict[key] = value
        except ValueError:
            joblist.append(line)
        
    return (resdict, joblist)
Esempio n. 9
0
def parse_espec_string(specstr, sourcename=None, resdict=None, joblist=None):
    """
    Parse a E spec file. 
    \param specstr        is the actual configuration text,
                          interpreted as a sequence of newline-
                          separated lines.
    \param sourcename     is a descriptive name of the source, used
                          for error messages.
    \return               Dictionary of key/value pairs and list of
                          problems. 
    """
    if not sourcename:
        sourcename = "E specification string starting with " + inpstr[:20]
    if resdict == None:
        resdict = {}
    if joblist == None:
        joblist = list([])

    spec_list = specstr.split("\n")
    lineno = 0
    for line in spec_list:
        lineno = lineno + 1
        comment = line.split("#")
        line = comment[0]
        line = line.strip()
        if not line:
            continue

        try:
            (key, value) = line.split(":", 1)

            key = key.strip()
            value = value.strip()
            if key == "Include":
                try:
                    fp = pylib_io.flexopen(value, "r")
                    newstr = fp.read()
                    pylib_io.flexclose(fp)
                    resdict, joblist =\
                             parse_espec_string(newstr,\
                                                "Included file "+value,\
                                                resdict, joblist)
                except IOError:
                    pass  # have to put logging in
            else:
                resdict[key] = value
        except ValueError:
            joblist.append(line)

    return (resdict, joblist)
Esempio n. 10
0
 def dimacs_parse(self, file):
     fp = pylib_io.flexopen(file, "r")
     l = fp.readlines()
     pylib_io.flexclose(fp)
     l = [
         i for i in l if not (i.startswith("%") or i.startswith("#")
                              or i.startswith("c") or i == "\n")
     ]
     if l[-1].startswith("0"):
         if fix_broken_dimacs:
             del (l[-1])
         else:
             sys.stderr.write(
                 "Warning: Problem ends in empty " +
                 "clause. Use --fix-broken-dimacs to suppress it")
     for i in l[1:]:
         self.add_clause(prop_clause(i))
Esempio n. 11
0
 def parse(self, file):
     f = pylib_io.flexopen(file,"r")
     l = f.readlines()
     pylib_io.flexclose(f)
     for i in l:
         if i.startswith("#"):
             continue
         tmp = string.split(i, ":");
         name = tmp[0].strip()
         featurestring = (tmp[1].strip())[1:-1]
         features = map(string.strip,string.split(featurestring, ","))
         if len(tmp) == 3: # Old style features
             add_features = tmp[2].strip()
             features.append(add_features[0])
             features.append(add_features[1])
             features.append(add_features[2])
             features.append(add_features[4])
             features.append(add_features[9])
         self.append((name, features))
Esempio n. 12
0
def parse_espec_file(source):
    """
    Parse a E test specifcation file.

    \param source         is either a string (interpreted as a file
                          name) or a file pointer.
    \return               tuple of key/value associations and list of
                          problems.
    """

    if type(source) == type("str"):
        fp = pylib_io.flexopen(source, "r")
        inpstr = fp.read()
        pylib_io.flexclose(fp)
        sourcename = source
    else:
        assert (type(source) == type(sys.stdin))
        inpstr = fp.read()
        sourcename = source.name

    return parse_espec_string(inpstr, sourcename)
Esempio n. 13
0
def parse_espec_file(source):
    """
    Parse a E test specifcation file.

    \param source         is either a string (interpreted as a file
                          name) or a file pointer.
    \return               tuple of key/value associations and list of
                          problems.
    """

    if type(source) == type("str"):
        fp = pylib_io.flexopen(source, "r")
        inpstr = fp.read()
        pylib_io.flexclose(fp)
        sourcename = source            
    else:
        assert(type(source)==type(sys.stdin))
        inpstr = fp.read()
        sourcename = source.name

    return parse_espec_string(inpstr, sourcename)
Esempio n. 14
0
    def __init__(self, filename):
        fp = pylib_io.flexopen(filename, "r")
        desc = fp.readlines(4096)
        pylib_io.flexclose(fp)
        
        self.specsize = 0
        self.atomno   = 0
        self.predno   = 0
        self.funcno   = 0

        if "+" in filename:
            self.fof = True            
        else:
            self.fof = False

        self.filename = filename
        self.name = filename.split("/")[-1]
            
        for i in desc:
            pos = i.find("Number of clauses")
            if pos != -1:
                self.specsize = header_extract_int(i)
            pos = i.find("Number of formulae")
            if pos != -1:
                self.specsize = header_extract_int(i)

            pos = i.find("Number of literals")
            if pos != -1:
                self.atomno = header_extract_int(i)
            pos = i.find("Number of atoms")
            if pos != -1:
                self.atomno = header_extract_int(i)

            pos = i.find("Number of predicates")
            if pos != -1:
                self.predno = header_extract_int(i)
            pos = i.find("Number of functors")
            if pos != -1:
                self.funcno = header_extract_int(i)
Esempio n. 15
0
    def __init__(self, filename):
        fp = pylib_io.flexopen(filename, "r")
        desc = fp.readlines(4096)
        pylib_io.flexclose(fp)
        
        self.specsize = 0
        self.atomno   = 0
        self.predno   = 0
        self.funcno   = 0

        if "+" in filename:
            self.fof = True            
        else:
            self.fof = False

        self.filename = filename
        self.name = filename.split("/")[-1]
            
        for i in desc:
            pos = i.find("Number of clauses")
            if pos != -1:
                self.specsize = header_extract_int(i)
            pos = i.find("Number of formulae")
            if pos != -1:
                self.specsize = header_extract_int(i)

            pos = i.find("Number of literals")
            if pos != -1:
                self.atomno = header_extract_int(i)
            pos = i.find("Number of atoms")
            if pos != -1:
                self.atomno = header_extract_int(i)

            pos = i.find("Number of predicates")
            if pos != -1:
                self.predno = header_extract_int(i)
            pos = i.find("Number of functors")
            if pos != -1:
                self.funcno = header_extract_int(i)
Esempio n. 16
0
if __name__ == '__main__':
    opts, args = getopt.gnu_getopt(sys.argv[1:], "hv", ["Verbose"])
    
    for option, optarg in opts:
        if option == "-h":
            print __doc__
            sys.exit()
        elif option == "-v" or option =="--verbose":
            pylib_io.Verbose = 1
        else:
            sys.exit("Unknown option "+ option)

    if len(args)<1:
        print __doc__
        sys.exit()

    store = {}
        
    for arg in args:
        fp = pylib_io.flexopen(arg, "r")
        for line in fp:
            tmp = line.split("/")
            store[tmp[4]] = line
        pylib_io.flexclose(fp)

    order = store.keys()
    order.sort()
    
    for i in order:
        sys.stdout.write(store[i])
Esempio n. 17
0
    if not outfile:
        outfile = "-"
    if not batch_app:
        out_fp = pylib_io.flexopen(outfile, "w")

    files = pylib_io.get_args()
    if len(files) == 0:
        files.append("-")

    for file in files:
        formula = prop_formula()
        formula.dimacs_parse(file)

        if batch_app:
            out_fp = pylib_io.flexopen(file + "." + batch_app, "w")

        if format == "mathsat":
            out_fp.write(formula.mathsat_str())
            out_fp.write("\n")
        elif format == "tptp2":
            out_fp.write(formula.tptp2_str())
            out_fp.write("\n")
        else:
            out_fp.write(str(formula))

        if batch_app:
            pylib_io.flexclose(out_fp)

    if not batch_app:
        pylib_io.flexclose(out_fp)
Esempio n. 18
0
 def parse_prob_data(self, file):
     fp = pylib_io.flexopen(file, "r")
     for line in fp:
         tmp = problem_desc(line[:-1])
         self.prob_desc[tmp.name] = tmp
     pylib_io.flexclose(fp)
Esempio n. 19
0
 def parse_prob_data(self, file):
     fp = pylib_io.flexopen(file, "r")
     for line in fp:
         tmp = problem_desc(line[:-1])
         self.prob_desc[tmp.name] = tmp
     pylib_io.flexclose(fp)
Esempio n. 20
0
        elif option == "-s":
            parse_data = optarg 
        else:
            sys.exit("Unknown option "+ option)

    if len(args)<1:
        print __doc__
        sys.exit()

    store = tptp_store()
        
    for arg in args:
        fp = pylib_io.flexopen(arg, "r")
        for line in fp:
            store.add(line)
        pylib_io.flexclose(fp)

    if parse_data:
        store.parse_prob_data(parse_data)

    version  = store.stats("<strong>Version</strong>",  store.tptp_name)
    problems = store.stats("<strong>Problems</strong>", store.prob_no)
    fof_prop = store.stats("<strong>FOF prop</strong>", store.fof_proportion)
    ax_size  = store.stats("<strong>Axioms</strong>",   store.ax_no)
    at_size  = store.stats("<strong>Atoms</strong>",    store.ax_no)
    pr_size  = store.stats("<strong>Preds</strong>",    store.pred_no)
    fu_size  = store.stats("<strong>Funcs</strong>",    store.func_no)

    res = zip(version, problems, fof_prop, ax_size, at_size, pr_size, fu_size)

    for line in res:
Esempio n. 21
0
    if not outfile:
        outfile = "-"
    if not batch_app:
        out_fp = pylib_io.flexopen(outfile, "w")

    files = pylib_io.get_args()
    if len(files) == 0:
        files.append("-")

    for file in files:
        formula = prop_formula()
        formula.dimacs_parse(file)

        if batch_app:
            out_fp = pylib_io.flexopen(file + "." + batch_app, "w")

        if format == "mathsat":
            out_fp.write(formula.mathsat_str())
            out_fp.write("\n")
        elif format == "tptp2":
            out_fp.write(formula.tptp2_str())
            out_fp.write("\n")
        else:
            out_fp.write(str(formula))

        if batch_app:
            pylib_io.flexclose(out_fp)

    if not batch_app:
        pylib_io.flexclose(out_fp)