当前位置: 首页>>代码示例>>Python>>正文


Python Sensor.check_facts方法代码示例

本文整理汇总了Python中sensor.Sensor.check_facts方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.check_facts方法的具体用法?Python Sensor.check_facts怎么用?Python Sensor.check_facts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor.Sensor的用法示例。


在下文中一共展示了Sensor.check_facts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InstalTest

# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import check_facts [as 别名]
class InstalTest(object):

    def temporary_text_file(self,text):
        (fd,path) = mkstemp() # returns a handle/path pair
        file = open(path,'w')
        print(text,file=file)
        file.close()
        os.close(fd)
        return path

    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)

    def syntax_check(self,data,terms):
        good = True;
        for d in data:
            t = parse_term(d)
            if not(t.name() in terms):
                print("Warning: unrecognized term",t)
                good = False
        return good;

    def run_test(self,event,initially=[],
                 holds=[],notholds=[],occurs=[],notoccurs=[],name=None):
        if name is None: #Default name to the event if no name set
            name = event
        # check for simple typos in term inputs
        self.syntax_check(initially+holds+notholds+[event]+occurs+notoccurs,
                          ["observed","occurred","holdsat"])
        self.sensor.holdsat += map(parse_term,initially)
        self.sensor.solve(event)
        event_sat = self.sensor.check_events(event,occurs,notoccurs)
        fact_sat = self.sensor.check_facts(event,holds,notholds)
        if (event_sat and fact_sat): # and (present != [] or absent != []):
            print("Satisfied({n}) {name}"
                  .format(name=name,n=self.sensor.cycle))
开发者ID:cblop,项目名称:storybuilder,代码行数:75,代码来源:instaltest.py


注:本文中的sensor.Sensor.check_facts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。