Пример #1
0
    def __init__(self,instal_texts,domain_texts,fact_text,options=""):
	#instal_texts is a list of strings
	ipath = []
	for i in instal_texts:
		ipath.append(self.temporary_text_file(i))

        dpath = []
	for d in domain_texts:
		dpath.append(self.temporary_text_file(d))
        fpath = self.temporary_text_file(fact_text)
        opath = mkdtemp()

	#-o needs to be a directory if >1 input file and a .lp file otherwise. This is a hack but it crashes otherwise.
	if len(instal_texts) > 1:
		opath_end = "/"
	else:
		opath_end = "/tmp.lp"

	#Construct argument list using temp files
        argparser = instalargparse.buildargparser()
	topass = ['-o',opath+opath_end,'-f',fpath,options]
	topass += ['-i'] + ipath
	topass += ['-d'] + dpath
        (args,unk) = argparser.parse_known_args(topass)
        # assumes input files are .ial not .lp
        args.ial_files = args.input_files
        args.lp_files = []
        model_files = instal_compile(args)
        initial_state = instal_state_facts(args)
        domain_facts = instal_domain_facts(args)
        self.sensor = Sensor(dummy,initial_state,model_files,domain_facts,args)

	# Clean up files. 
	for i in ipath:
        	os.remove(i)
	for d in dpath:
        	os.remove(d)
        os.remove(fpath)
        shutil.rmtree(opath)
Пример #2
0
def instal_query():
    argparser = buildargparser()
    # additional parameters for instalquery
    argparser.add_argument(
        '-a', '--answer-set', type=int, default=0,
        help='choose an answer set (default all)')
    argparser.add_argument(
        '-l', '--length', type=int, default=1,
        help='length of trace (default 1)')
    argparser.add_argument(
        '-n', '--number', type=int, default=1,
        help='compute at most <n> models (default 1, 0 for all)')
    args,unk = argparser.parse_known_args()
    check_args(args,unk)
    model_files = instal_compile(args)
    initial_state = instal_state_facts(args)
    domain_facts = instal_domain_facts(args)
    oracle = Oracle(initial_state,model_files,domain_facts,args)
    # delete temporary files
    if os.path.dirname(args.output_file)=='/tmp': 
        if os.path.isdir(args.output_file):
            shutil.rmtree(args.output_file)
        else:
            os.remove(args.output_file)
    observed = []
    # enumerate the events in the query file
    for i,e in enumerate(fileinput.input(args.query)):
        observed += [Fun('observed',[parse_term(e).args()[0],i])]
    # note: events is a list of Fun not strings
    oracle.solve_iter(observed)
    # print("occurred = ",oracle.occurred)
    # print("holdsat = ",oracle.holdsat)
    # write LaTeX visualizations
    if args.trace_file:
        instal_trace(args,oracle.answersets)
    if args.gantt_file:
        instal_gantt(args,oracle.answersets)
    if args.text_file:
        instal_text(args,oracle.answersets)