コード例 #1
0
ファイル: udp_dump.py プロジェクト: qjay612/sigmakee
def process_options(optlist):
    """
    Process options.
    """
    global output_streams
    global bin_output
    global print_data
    global print_str
    global print_hex

    for opt, arg in optlist:
        if opt == "-h":
            print __doc__
            sys.exit()
        elif opt == "-v" or opt == "--verbose":
            pylib_io.Verbose = 1
        elif opt == "-f":
            fp = pylib_io.flexopen(arg, "wb")
            output_streams.append(fp)
        elif opt == "-b":
            bin_output = pylin_io.flexopen(arg, "w")
        elif opt == "-d":
            print_data = True
        elif opt == "-s":
            print_str = True
        elif opt == "-H":
            print_hex = True
        else:
            print __doc__
            usage_error("Unknown option")
コード例 #2
0
def process_options(optlist):
    """
    Process options.
    """
    global output_streams
    global bin_output
    global print_data
    global print_str
    global print_hex
    
    for opt, arg in optlist:
        if opt == "-h":
            print __doc__
            sys.exit()
        elif opt == "-v" or opt == "--verbose":
            pylib_io.Verbose = 1
        elif opt=="-f":
            fp = pylib_io.flexopen(arg, "wb")
            output_streams.append(fp)
        elif opt=="-b":
            bin_output = pylin_io.flexopen(arg, "w")
        elif opt == "-d":
            print_data = True
        elif opt == "-s":
            print_str = True
        elif opt == "-H":
            print_hex = True
        else:
            print __doc__
            usage_error("Unknown option")
コード例 #3
0
ファイル: pylib_eprot.py プロジェクト: xiaoxiangfu/sigmakee
 def parse(self, directory=""):
     filename = os.path.join(directory, self.protname())
     self.filename = filename
     try:
         fp = pylib_io.flexopen(filename, "r")
     except IOError, err:
         return False
コード例 #4
0
ファイル: pylib_eprot.py プロジェクト: martisch/eprover_dev
 def parse(self, directory=""):
     filename = os.path.join(directory, self.protname())
     self.filename = filename
     try:
         fp = pylib_io.flexopen(filename, "r")
     except IOError,err:
         return False
コード例 #5
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)
コード例 #6
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)            
コード例 #7
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)
コード例 #8
0
ファイル: pylib_eprot.py プロジェクト: martisch/eprover_dev
 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
コード例 #9
0
ファイル: pylib_eprot.py プロジェクト: xiaoxiangfu/sigmakee
 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
コード例 #10
0
ファイル: pylib_dimacs.py プロジェクト: qjay612/sigmakee
 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))
コード例 #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, ":");
         if len(tmp) == 4:
             del(tmp[0])
         tmp = map(string.strip, tmp)
         self.append((tmp[0], tmp[1], tmp[2]))
コード例 #12
0
ファイル: include_mapper.py プロジェクト: kylepjohnson/sigma
def find_tptp_file(filename, refdir=None):
    """
    Find a TPTP file and open it. Return filepointer, directory of
    file, or none of opening fails.
    """

    if os.path.isabs(filename) or filename == "-":        
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except Exception, inst:
            print inst
            return None
コード例 #13
0
def find_tptp_file(filename, refdir=None):
    """
    Find a TPTP file and open it. Return filepointer, directory of
    file, or none of opening fails.
    """

    if os.path.isabs(filename) or filename == "-":        
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except Exception, inst:
            print inst
            return None
コード例 #14
0
ファイル: pylib_eprot.py プロジェクト: martisch/eprover_dev
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)
コード例 #15
0
ファイル: pylib_eprot.py プロジェクト: xiaoxiangfu/sigmakee
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)
コード例 #16
0
def read_res_file(filename):
    """
    Try to open and read the named file. Return the contents if
    successful and the file contains the string
    '### Job complete ###', None otherwise.
    """
    try:
        fp = pylib_io.flexopen(filename, "r")
    except IOError:
        return None
    res = fp.read()

    mo = res_complete_marker.search(res)
    if mo:
        return res
    return None
コード例 #17
0
ファイル: pylib_dimacs.py プロジェクト: masashi-y/eprover
 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))
コード例 #18
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))
コード例 #19
0
ファイル: pylib_eprot.py プロジェクト: xiaoxiangfu/sigmakee
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)
コード例 #20
0
ファイル: pylib_eprot.py プロジェクト: martisch/eprover_dev
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)
コード例 #21
0
ファイル: tptp_analyse.py プロジェクト: kylepjohnson/sigma
    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)
コード例 #22
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)
コード例 #23
0
ファイル: pylib_dimacs.py プロジェクト: masashi-y/eprover
            if outfile == "":
                sys.exit("-o needs non-empty argument")
        elif option.startswith("-b"):
            batch_app = option[2:]
            if batch_app == "":
                sys.exit("-b needs non-empty argument")
        else:
            sys.exit("Unknown option " + option)

    if outfile and batch_app:
        sys.exit("Options -o and -b are incompatible")

    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")
コード例 #24
0
ファイル: wo.py プロジェクト: kylepjohnson/sigma
import sys
import re
import string
import pylib_io

def id(string):
    return string

def firstfield(str):
    parts = string.split(str)
    if(len(parts)>0):
        return parts[0]
    return ""


def without(file_source, file_remove, abstract_fun):
    source = {}
    lines = file_remove.readlines()
    for line in lines:
        source[abstract_fun(line)] = 1;
    lines = file_source.readlines()
    for line in lines:
        if(not (abstract_fun(line) in source)):
            sys.stdout.write(line)

pylib_io.check_argc(2)
file_source = pylib_io.flexopen(sys.argv[1], "r")
file_remove = pylib_io.flexopen(sys.argv[2], "r")

without(file_source, file_remove, id)
コード例 #25
0
    Find a TPTP file and open it. Return filepointer, directory of
    file, or none of opening fails.
    """

    if os.path.isabs(filename) or filename == "-":        
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except Exception, inst:
            print inst
            return None
    # We don't yet know where to search
    if not refdir:
        # Consider filename relative to local dir
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except:
            pass
    else:
        # We have a reference directory and cannot use local dir
        name = os.path.join(refdir, filename)
        try:
            fp = pylib_io.flexopen(name, "r")
            return (fp, pylib_io.get_directory(name))
        except:
            pass
    # Everything failed, try looking at $TPTP
    refdir = os.getenv("TPTP")
    name = os.path.join(refdir, filename)
    try:
コード例 #26
0
ファイル: fvi_eval.py プロジェクト: kylepjohnson/sigma
    for option, optarg in opts:
        if option == "-h":
            print __doc__
            sys.exit()
        else:
            sys.exit("Unknown option "+ option)

    if not args: 
        print __doc__
        sys.exit("No argument file given")
       

    prots = []

    for i in args:
        fp = pylib_io.flexopen(i, "r")
        print "Parsing: ",i 
        prot = pylib_eprot.eprot(i)
        prot.parse();        
        pylib_io.flexclose(fp)
        prots.append(prot)
        
    
    filter_common_successes(prots)        
    filter_common_search(prots)
    print prots[0].results_no()
    # filter_hard_problems(prots, 4, 1000)
    # print prots[0].results_no()

    #for res in prots[0].results.keys():
    #    print prots[3].result(res).values[12], prots[5].result(res).values[12],\
コード例 #27
0
ファイル: tptp_analyse.py プロジェクト: kylepjohnson/sigma
 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)
コード例 #28
0
ファイル: tptp_analyse.py プロジェクト: kylepjohnson/sigma
            sys.exit()
        elif option == "-v" or option =="--verbose":
            pylib_io.Verbose = 1
        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)
コード例 #29
0
ファイル: pylib_dimacs.py プロジェクト: qjay612/sigmakee
            if outfile == "":
                sys.exit("-o needs non-empty argument")
        elif option.startswith("-b"):
            batch_app = option[2:]
            if batch_app == "":
                sys.exit("-b needs non-empty argument")
        else:
            sys.exit("Unknown option " + option)

    if outfile and batch_app:
        sys.exit("Options -o and -b are incompatible")

    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")
コード例 #30
0
ファイル: wo.py プロジェクト: masashi-y/eprover
import sys
import re
import string
import pylib_io

def id(string):
    return string

def firstfield(str):
    parts = string.split(str)
    if(len(parts)>0):
        return parts[0]
    return ""


def without(file_source, file_remove, abstract_fun):
    source = {}
    lines = file_remove.readlines()
    for line in lines:
        source[abstract_fun(line)] = 1;
    lines = file_source.readlines()
    for line in lines:
        if(not (abstract_fun(line) in source)):
            sys.stdout.write(line)

pylib_io.check_argc(2)
file_source = pylib_io.flexopen(sys.argv[1], "r")
file_remove = pylib_io.flexopen(sys.argv[2], "r")

without(file_source, file_remove, id)
コード例 #31
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)
コード例 #32
0
    for option, optarg in opts:
        if option == "-h":
            print __doc__
            sys.exit()
        else:
            sys.exit("Unknown option " + option)

    if not args:
        print __doc__
        sys.exit("No argument file given")

    prots = []

    for i in args:
        fp = pylib_io.flexopen(i, "r")
        print "Parsing: ", i
        prot = pylib_eprot.eprot(i)
        prot.parse()
        pylib_io.flexclose(fp)
        prots.append(prot)

    filter_common_successes(prots)
    filter_common_search(prots)
    print prots[0].results_no()
    #filter_hard_problems(prots, 4, 5000)
    #print prots[0].results_no()

    #for res in prots[0].results.keys():
    #    print prots[0].result(res).values[2], prots[11].result(res).values[2]
コード例 #33
0
ファイル: hack_uniq.py プロジェクト: zariuq/eprover
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])
コード例 #34
0
ファイル: include_mapper.py プロジェクト: kylepjohnson/sigma
    Find a TPTP file and open it. Return filepointer, directory of
    file, or none of opening fails.
    """

    if os.path.isabs(filename) or filename == "-":        
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except Exception, inst:
            print inst
            return None
    # We don't yet know where to search
    if not refdir:
        # Consider filename relative to local dir
        try:
            fp = pylib_io.flexopen(filename, "r")
            return (fp, pylib_io.get_directory(filename))
        except:
            pass
    else:
        # We have a reference directory and cannot use local dir
        name = os.path.join(refdir, filename)
        try:
            fp = pylib_io.flexopen(name, "r")
            return (fp, pylib_io.get_directory(name))
        except:
            pass
    # Everything failed, try looking at $TPTP
    refdir = os.getenv("TPTP")
    name = os.path.join(refdir, filename)
    try: