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

        self.config = PRACMLNConfig()
        self.config["use_emln"] = self.use_emln.get()
        self.config['mln'] = self.mln_container.selected_file.get().strip(
        ).lstrip('*')
        self.config['emln'] = self.emln_container.selected_file.get().strip(
        ).lstrip('*')
        self.config["db"] = self.db_container.selected_file.get().strip(
        ).lstrip('*')
        self.config["method"] = InferenceMethods.id(
            self.selected_method.get().strip())
        self.config["params"] = self.params.get().strip()
        self.config["queries"] = self.query.get()
        self.config["output_filename"] = self.output_filename.get().strip()
        self.config["cw"] = self.closed_world.get()
        self.config["cw_preds"] = self.cwPreds.get()
        self.config['profile'] = self.profile.get()
        self.config['logic'] = self.selected_logic.get()
        self.config['grammar'] = self.selected_grammar.get()
        self.config['multicore'] = self.multicore.get()
        self.config['save'] = self.save.get()
        self.config['ignore_unknown_preds'] = self.ignore_unknown_preds.get()
        self.config['verbose'] = self.verbose.get()
        self.config['window_loc'] = self.master.winfo_geometry()
        self.config['dir'] = self.dir
        self.project.queryconf = PRACMLNConfig()
        self.project.queryconf.update(self.config.config.copy())
Пример #2
0
    def update_config(self):
        out('update_config')

        self.config = PRACMLNConfig()
        self.config['mln'] = self.mln_container.selected_file.get().strip().lstrip('*')
        self.config["db"] = self.db_container.selected_file.get().strip().lstrip('*')
        self.config["output_filename"] = self.output_filename.get()
        self.config["params"] = self.params.get().strip()
        self.config["method"] = LearningMethods.id(self.selected_method.get().strip())
        self.config["pattern"] = self.pattern.get()
        self.config["use_prior"] = int(self.use_prior.get())
        self.config["prior_mean"] = self.priorMean.get()
        self.config["prior_stdev"] = self.priorStdDev.get()
        self.config["incremental"] = int(self.incremental.get())
        self.config["shuffle"] = int(self.shuffle.get())
        self.config["use_initial_weights"] = int(self.use_initial_weights.get())
        self.config["qpreds"] = self.queryPreds.get().strip()
        self.config["epreds"] = self.evidencePreds.get().strip()
        self.config["discr_preds"] = self.discrPredicates.get()
        self.config['logic'] = self.selected_logic.get()
        self.config['grammar'] = self.selected_grammar.get()
        self.config['multicore'] = self.multicore.get()
        self.config['profile'] = self.profile.get()
        self.config['verbose'] = self.verbose.get()
        self.config['ignore_unknown_preds'] = self.ignore_unknown_preds.get()
        self.config['ignore_zero_weight_formulas'] = self.ignore_zero_weight_formulas.get()
        self.config['save'] = self.save.get()
        self.config["output_filename"] = self.output_filename.get().strip()
        self.project.learnconf = PRACMLNConfig()
        self.project.learnconf.update(self.config.config.copy())
Пример #3
0
def main():
    logger.level = logs.DEBUG

    usage = 'PRACMLN Learning Tool'

    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument("--run", action="store_true", dest="run", default=False, help="run last configuration without showing gui")
    parser.add_argument("-d", "--dir", dest="directory", action='store', help="the directory to start the tool from", metavar="FILE", type=str)
    parser.add_argument("-i", "--mln-filename", dest="mlnarg", action='store', help="input MLN filename", metavar="FILE", type=str)
    parser.add_argument("-t", "--db-filename", dest="dbarg", action='store', help="training database filename", metavar="FILE", type=str)
    parser.add_argument("-o", "--output-file", dest="outputfile", action='store', help="output MLN filename", metavar="FILE", type=str)

    args = parser.parse_args()
    opts_ = vars(args)

    # run learning task/GUI
    root = Tk()
    conf = PRACMLNConfig(DEFAULT_CONFIG)
    app = MLNLearnGUI(root, conf, directory=os.path.abspath(args.directory) if args.directory is not None else None)

    if args.run:
        logger.debug('running mlnlearn without gui')
        app.learn(savegeometry=False, options=opts_)
    else:
        root.mainloop()
Пример #4
0
def main():
    logger.level = logs.DEBUG

    usage = 'PRACMLN Query Tool'

    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument("-i", "--mln", dest="mlnarg", help="the MLN model file to use")
    parser.add_argument("-d", "--dir", dest="directory", action='store', help="the directory to start the tool from", metavar="FILE", type=str)
    parser.add_argument("-x", "--emln", dest="emlnarg", help="the MLN model extension file to use")
    parser.add_argument("-q", "--queries", dest="queryarg", help="queries (comma-separated)")
    parser.add_argument("-e", "--evidence", dest="dbarg", help="the evidence database file")
    parser.add_argument("-r", "--results-file", dest="outputfile", help="the results file to save")
    parser.add_argument("--run", action="store_true", dest="run", default=False, help="run with last settings (without showing GUI)")

    args = parser.parse_args()
    opts_ = vars(args)

    root = Tk()
    conf = PRACMLNConfig(DEFAULT_CONFIG)
    app = MLNQueryGUI(root, conf, directory=os.path.abspath(args.directory) if args.directory else None)

    if args.run:
        logger.debug('running mlnlearn without gui')
        app.infer(savegeometry=False, options=opts_)
    else:
        root.mainloop()
    def activate_model(self,database, mln):
        """
        Returns the learned mln
        --Inputs--
        database and mln objects in MLN format
        """

        DEFAULT_CONFIG = os.path.join(locs.user_data, global_config_filename)
        conf = PRACMLNConfig(DEFAULT_CONFIG)

        config = {}
        config['verbose'] = True
        config['discr_preds'] = 0
        config['db'] = database
        config['mln'] = mln
        config['ignore_zero_weight_formulas'] = 1    #0
        config['ignore_unknown_preds'] = True   #0
        config['incremental'] = 1   #0
        config['grammar'] = 'PRACGrammar' #StandardGrammar
        config['logic'] = 'FirstOrderLogic'
        config['method'] = 'BPLL'    # BPLL (BPLL, 'pseudo-log-likelihood')
        config['optimizer'] = 'bfgs'
        config['multicore'] = False
        config['profile'] = 0
        config['shuffle'] = 0
        config['prior_mean'] = 0
        config['prior_stdev'] = 10   # 5
        config['save'] = True
        config['use_initial_weights'] = 0
        config['use_prior'] = 0


        config['infoInterval'] = 500
        config['resultsInterval'] = 1000
        conf.update(config)

        print('training...')
        learn = MLNLearn(conf, mln=mln, db=database)

        result = learn.run()
        print('finished...')
        return result
Пример #6
0
    def activate_model(self, database, mln):

        DEFAULT_CONFIG = os.path.join(locs.user_data, global_config_filename)
        conf = PRACMLNConfig(DEFAULT_CONFIG)

        config = {}
        config['verbose'] = True
        config['discr_preds'] = 0
        config['db'] = database
        config['mln'] = mln
        config['ignore_zero_weight_formulas'] = 1  # 0
        config['ignore_unknown_preds'] = True  # 0
        config['incremental'] = 1  # 0
        config['grammar'] = 'StandardGrammar'
        config['logic'] = 'FirstOrderLogic'
        config['method'] = 'BPLL'  # BPLL
        config['multicore'] = False
        config['profile'] = 0
        config['shuffle'] = 0
        config['prior_mean'] = 0
        config['prior_stdev'] = 10  # 5
        config['save'] = True
        config['use_initial_weights'] = 0
        config['use_prior'] = 0
        # config['output_filename'] = 'learnt.dbpll_cg.student-new-train-student-new-2.mln'
        # 亲测无效, 此句没法储存.mln 档案
        config['infoInterval'] = 500
        config['resultsInterval'] = 1000
        conf.update(config)

        print('training...')
        learn = MLNLearn(conf, mln=mln, db=database)
        # learn.output_filename(r'C:\Users\anaconda3 4.2.0\test.mln')
        # 亲测无效, 此句没法储存.mln 档案
        result = learn.run()
        print('finished...')
        return result
Пример #7
0
                      "--queries",
                      dest="queryarg",
                      help="queries (comma-separated)")
    parser.add_option("-e",
                      "--evidence",
                      dest="dbarg",
                      help="the evidence database file")
    parser.add_option("-r",
                      "--results-file",
                      dest="outputfile",
                      help="the results file to save")
    parser.add_option("--run",
                      action="store_true",
                      dest="run",
                      default=False,
                      help="run with last settings (without showing GUI)")
    (opts, args) = parser.parse_args()
    options = vars(opts)

    root = Tk()
    conf = PRACMLNConfig(DEFAULT_CONFIG)
    app = MLNQueryGUI(root,
                      conf,
                      directory=os.path.abspath(args[0]) if args else None)

    if opts.run:
        logger.debug('running mlnlearn without gui')
        app.infer(savegeometry=False, options=options)
    else:
        root.mainloop()
Пример #8
0
def main():
    logger.level = logs.DEBUG

    usage = 'PRAC Query Tool'

    parser = argparse.ArgumentParser(description=usage)
    parser.add_argument("instruction", help="The instruction.")
    parser.add_argument(
        "-i",
        "--interactive",
        dest="interactive",
        default=False,
        action='store_true',
        help="Starts PRAC inference with an interactive GUI tool.")
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        default=1,
                        type=int,
                        action="store",
                        help="Set verbosity level {0..3}. Default is 1.")

    args = parser.parse_args()
    opts_ = vars(args)

    sentences = args.instruction
    prac = PRAC()
    prac.verbose = args.verbose

    conf = PRACMLNConfig(DEFAULT_CONFIG)

    if args.interactive:  # use the GUI
        from tkinter import Tk
        root = Tk()
        # in case we have natural-language parameters, parse them
        infer = PRACInference(prac, sentences)
        if len(sentences) > 0:
            # module = prac.module('nl_parsing')
            # prac.run(infer, module)
            n = infer.runstep()

            # print parsing result
            for odb in n.outdbs:
                odb.write()

            # print input sentence
            print(n.nlinstr())

            #Started control structure handling
            '''
            cs_recognition = prac.module('cs_recognition')
            prac.run(inference, cs_recognition)
            
            
            dbs = inference.inference_steps[-1].output_dbs
            dbs_ = []
            
            for db in dbs:
                dbs_.extend(parser.extract_multiple_action_cores(db)) 
            inference.inference_steps[-1].output_dbs = dbs_
            '''
            app = PRACQueryGUI(root,
                               infer.prac,
                               n,
                               conf,
                               directory=args[0] if args else None)
            root.mainloop()
        exit(0)

    # regular PRAC pipeline
    infer = PRACInference(prac, sentences)
    infer.run()

    print(headline('inference results'))
    print('instructions:')
    for i in infer.root:
        print(i)
    frames = []
    for step in infer.steps():
        print(step.frame)
    print(prac_heading('cram plans', color='blue'))
    for step in infer.steps():
        if hasattr(step, 'plan'):
            print(step.plan)


#     infer.write()
    exit(0)