def __init__(cls, classname, bases, newdict): if classname == 'Exists': # due to the ordering of things in clps.py utils.register(classname, cls) return slots = ['(slot %s (type %s) (visibility public) (pattern-match reactive))' % (mod, issubclass(utils.get_class(modclass), Number) and \ 'NUMBER' or 'INSTANCE') for mod,modclass in cls.mods.items()] slots = ' '.join(slots) parents = ' '.join([base.__name__ for base in bases]) clp = '(defclass %s (is-a %s) %s)' % (classname, parents, slots) for mod,modclass in cls.mods.items(): if isinstance(modclass, type): cls.mods[mod] = modclass.__name__ modification = ['%s a %s' % (mod, modclass.lower()) for mod, modclass in cls.mods.items()] verb_def = '%s is %s withsubject %s' % (classname.lower(), parents.lower().replace(' ', ', '), cls.subject.__name__.lower()) if modification: verb_def += ' andcanbe ' + ', '.join(modification) verb_def += '.' utils.to_history(verb_def) for kls in bases: if getattr(kls, 'mods', False): cls.mods.update(kls.mods) super(Verb, cls).__init__(classname, bases, newdict, clp=clp)
def __init__(cls, classname, bases, newdict): if classname == 'Exists': # due to the ordering of things in clps.py utils.register(classname, cls) return slots = ['(slot %s (type %s) (visibility public) (pattern-match reactive))' % (mod, issubclass(utils.get_class(modclass), Number) and \ '?VARIABLE' or 'INSTANCE') for mod,modclass in cls.mods.items()] slots = ' '.join(slots) clp = '(defclass %s (is-a %s) %s)' % (classname, bases[0].__name__, slots) for mod,modclass in cls.mods.items(): if isinstance(modclass, type): cls.mods[mod] = modclass.__name__ for kls in bases: if getattr(kls, 'mods', _m): cls.mods.update(kls.mods) super(Verb, cls).__init__(classname, bases, newdict, clp=clp)
def __init__(cls, classname, bases, newdict, clp=''): super(Word, cls).__init__(classname, bases, newdict) if clp: logger.info(clp) clips.Build(clp) utils.register(classname, cls)
""" q = self.get_query_cls(vrs, ancestor, mod_path) queries += q @classmethod def from_clips(cls, instance): ''' build nl instance starting from a clips instance or instance name ''' if not isinstance(instance, clips._clips_wrap.Class): instance = clips.FindClass(instance) clsname = str(instance.Name) return utils.get_class(clsname) utils.register('Word', Word) class ClassVar(object): ''' Used in rules, in the head or tail, as subject or mod in a predicate, when Word is called with a string that matches varpat. Intances can be called, and give back an instance of ClassVarVar, that can handle clips for the case in which we have both the class and the name or mods as variables. This is not to be part of the public api