def _optimise(): from caspo import core graph = core.Graph(pkn.nodes(), map(lambda t: (t[0],t[1], 1 if t[2]['link'] == '+' else -1), pkn.edges_iter(pkn.nodes(),True))) # Now, we read the MIDAS from caspo from zope import component reader = component.getUtility(core.ICsvReader) reader.read('../caspo/data/LiverToy/dataset.csv') dataset = core.IDataset(reader) #Register clingo binary from pyzcasp import potassco potassco.configure(clingo="clingo") # Instantiate the learner and learn using clingo at timepoint 10, # tolerance of 10% over fitness, and tolerance of 5 over size from caspo.learn import learner networks = learner(graph, dataset, 10, potassco.IClingo, compress=False).learn(0.1, 5) return networks """
parser = argparse.ArgumentParser() parser.add_argument("--clasp", dest="clasp", default="clasp", help="clasp solver binary (Default to 'clasp')", metavar="C") parser.add_argument("--gringo", dest="gringo", default="gringo", help="gringo grounder binary (Default to 'gringo')", metavar="G") parser.add_argument("--gringo-series", dest="gringo_series", type=int, default=4, choices=[3,4], help="gringo series", metavar="S") args = parser.parse_args() gsm = component.getGlobalSiteManager() if args.gringo_series == 3: potassco.configure(gringo3=args.gringo, clasp3=args.clasp) else: potassco.configure(gringo4=args.gringo, clasp3=args.clasp) gsm.registerUtility(asp.EncodingRegistry(), asp.IEncodingRegistry, 'example') root = __file__.rsplit('/', 1)[0] reg = component.getUtility(asp.IEncodingRegistry, 'example') reg.register('enco-1', root + '/encodings/encoding-1-gringo3.lp', potassco.IGringo3) reg.register('enco-1', root + '/encodings/encoding-1-gringo4.lp', potassco.IGringo4) main(args)
from zope import component from pyzcasp import potassco, asp from pyzcasp.examples.tweety import * if __name__ == '__main__': # first thing you would do is to register clingo utility potassco.configure(clingo="clingo") clingo = component.getUtility(potassco.IClingo) # tweety and sam are birds, sam is a penguin birds = BirdList([Bird('tweety'), Bird('sam', True)]) flying_birds = component.getMultiAdapter((birds, clingo), IFlyingBirds) for bird in flying_birds: print bird.name # prints only tweety print '---' birds[1].penguin = False # fly sam, fly!!! flying_birds = component.getMultiAdapter((birds, clingo), IFlyingBirds) for bird in flying_birds: print bird.name # prints tweety and sam