Пример #1
0
    def match(self):

        if len(self.models) < 2:
            self.error('Match requires two programs!')

        elif len(self.models) > 2:
            self.debug('Match requires two programs, ignoring the rest!')

        M = Matching(ignoreio=self.ignoreio,
                     ignoreret=self.ignoreret,
                     verbose=self.verbose,
                     bijective=self.bijective)

        m = M.match_programs(self.models[0],
                             self.models[1],
                             self.inter,
                             ins=self.ins,
                             args=self.args,
                             entryfnc=self.entryfnc)
        print 'm', m
        if m:
            self.debug('Match: %s', pprint.pformat(m[1]))
            print 'Match!'
        else:
            print 'No match!'
Пример #2
0
 def match(self):
     matching = Matching()
     m = matching.match_programs(self.models[0],
                                 self.models[1],
                                 self.interpreter,
                                 ins=[self.inputs],
                                 entryfnc=self.entry_function)
     if m:
         return True
     else:
         return False
Пример #3
0
def matching_helper(f1,
                    f2,
                    lang,
                    ins=None,
                    args=None,
                    entryfnc="main",
                    datadir="data"):
    f1 = get_full_data_filename(f1, reldir=datadir)
    f2 = get_full_data_filename(f2, reldir=datadir)

    parser = getlangparser(lang)
    inter = getlanginter(lang)

    m1 = parse_file(f1, parser)
    m2 = parse_file(f2, parser)

    M = Matching(ignoreio=not ins, ignoreret=not args)
    return not not M.match_programs(
        m1, m2, inter, ins=ins, args=args, entryfnc=entryfnc)
Пример #4
0
    def cluster(self):
        M = Matching()
        C = Clustering(M)
        existing = []
        shutil.rmtree(self.clusters_dir, ignore_errors=True)
        os.mkdir(self.clusters_dir)
        for f in glob.glob(os.path.join(self.clusters_dir, "*." + self.lang)):
            model = self.process_source(f)
            existing.append(model)
        # print("Found %d existing clusters" % (len(existing)))

        new, mod = C.cluster(self.models,
                             self.interpreter,
                             ins=[self.inputs],
                             entryfnc=self.entry_function,
                             existing=existing)

        print("Done, %d new clusters, %d modified clusters" %
              (len(new), len(mod)))

        cluster_files = []
        # Add new clusters
        for f in new:
            f.new_name = os.path.join(self.clusters_dir, f.new_name)
            print("NEW:", f.name, "->", f.new_name)
            cluster_files.append(f.new_name)

            # Copy the source file
            if os.path.exists(f.new_name):
                print("Filename '%s' already exists!")
            shutil.copyfile(f.name, f.new_name)

            # Dump expressions
            f.name = f.new_name
            self.dump_expressions(f)

        # Write modifications for the modified clusters
        for f in mod:
            print("MOD:", f.name)
            self.dump_expressions(f)
        return cluster_files
Пример #5
0
    def cluster(self):
        if len(self.models) < 1:
            self.error('Clustering requires at least one program!')

        if not os.path.isdir(self.clusterdir):
            self.error("Clustering directory '%s' does not exist!", self.clusterdir)

        M = Matching(ignoreio=self.ignoreio, ignoreret=self.ignoreret,
                     verbose=self.verbose, bijective=self.bijective)
        C = Clustering(M)

        existing = []
        for f in glob.glob(os.path.join(self.clusterdir, "*." + self.lang)):
            model = self.process_source(f)
            existing.append(model)
        print("Found %d existing clusters" % (len(existing)))
                    
        new, mod = C.cluster(self.models, self.inter,
                             ins=self.ins, args=self.args,
                             entryfnc=self.entryfnc, existing=existing)

        print("Done, %d new clusters, %d modified clusters" % (len(new), len(mod)))
        
        # Add new clusters
        for f in new:
            f.new_name = os.path.join(self.clusterdir, f.new_name)
            print("NEW:", f.name, "->", f.new_name)

            # Copy the source file
            if os.path.exists(f.new_name):
                self.error("Filename '%s' already exists!")
            shutil.copyfile(f.name, f.new_name)

            # Dump expressions
            f.name = f.new_name
            self.dump_exprs(f)

        # Write modifications for the modified clusters
        for f in mod:
            print("MOD:", f.name)
            self.dump_exprs(f)