def addable_values(self): # return [introsp.Constructor(Class, lambda subject, Class = Class: Class(ontology = subject.ontology)) # for Class in self.class_and_descendant_classes() # if (not _get_class_one_of(Class)) and (not _is_abstract_class(Class))] return [ introsp.NewInstanceOf(Class) for Class in self.class_and_descendant_classes() if (not _get_class_one_of(Class)) and ( not _is_abstract_class(Class)) ]
def available_values(self, subject): available_classes = None excluded_classes = set() for range_restriction in self.range_restrictions: if isinstance(range_restriction, RangeClassOnly): range_restriction_available_classes = range_restriction.get_classes( ) if available_classes is None: available_classes = range_restriction_available_classes else: available_classes &= range_restriction_available_classes elif isinstance(range_restriction, RangeClassExclusion): excluded_classes.update(range_restriction.get_classes()) if not available_classes: available_classes = set() available_classes.difference_update(excluded_classes) available_classes = sorted(available_classes, key=lambda Class: Class.name) new_instances_of = [ introsp.NewInstanceOf(Class) for Class in available_classes if (not _get_class_one_of(Class)) and ( not _is_abstract_class(Class)) ] #new_instances_of = [introsp.NewInstanceOf(Class, lambda subject, Class = Class: Class(ontology = subject.ontology)) for Class in available_classes if (not _get_class_one_of(Class)) and (not _is_abstract_class(Class))] existent_values = set() for Class in available_classes: existent_values.update(Class._direct_instances) if excluded_classes: excluded_classes = tuple(excluded_classes) existent_values = [ o for o in existent_values if not isinstance(o, excluded_classes) ] # For InverseFounctional props, remove values already used. if issubclass( self.Prop, InverseFunctionalProperty) and self.Prop.inverse_property: existent_values = { value for value in existent_values if not getattr(value, self.Prop.inverse_property.python_name) } existent_values = sorted(existent_values, key=lambda obj: obj.name) return new_instances_of + existent_values
def available_values(self, subject): available_classes = [] excluded_classes = set() for range_restriction in self.range_restrictions: if isinstance(range_restriction, RangeClassOnly): available_classes.append(range_restriction.get_classes()) elif isinstance(range_restriction, RangeClassExclusion): excluded_classes.update(range_restriction.get_classes()) available_classes = _intersect_reduce(available_classes) available_classes.difference_update(excluded_classes) available_classes = sorted(available_classes, key=lambda Class: Class.name) new_instances_of = [ introsp.NewInstanceOf(Class) for Class in available_classes if (not _get_class_one_of(Class)) and ( not _is_abstract_class(Class)) ] existent_values = set() for Class in available_classes: existent_values.update(default_world.search(type=Class)) if excluded_classes: excluded_classes = tuple(excluded_classes) existent_values = [ o for o in existent_values if not isinstance(o, excluded_classes) ] # For InverseFunctional props, remove values already used. if issubclass( self.Prop, InverseFunctionalProperty) and self.Prop.inverse_property: existent_values = { value for value in existent_values if not getattr(value, self.Prop.inverse_property.python_name) } existent_values = sorted(existent_values, key=lambda obj: obj.name) return new_instances_of + existent_values
def addable_values(self): return [ introsp.NewInstanceOf(Class) for Class in self.Class.descendants() if (not _get_class_one_of(Class)) and ( not _is_abstract_class(Class)) ]