Beispiel #1
0
def _configure_class_restriction(Class, restriction):
  if   isinstance(restriction, AndRestriction):
    for sub_restriction in restriction.Classes:
      _configure_class_restriction(Class, sub_restriction)
      
  elif isinstance(restriction, OneOfRestriction):pass
    
  elif isinstance(restriction, PropertyValueRestriction):
    if   restriction.type == "VALUE":
      introsp.description(Class).def_attr(restriction.Prop.python_name, field.LabelField, priority = _get_priority(restriction.Prop))
      
    elif restriction.type == "ONLY":
      if not restriction.Prop._is_data_property():
        if   isinstance(restriction.Class, ThingClass): ranges = [restriction.Class]
        else:
          if not hasattr(restriction.Class, "Classes"): return
          ranges =  restriction.Class.Classes
        if len(ranges) == 1: one_of = _get_class_one_of(ranges[0])
        else:                one_of = None
        if one_of: RangeInstanceOnly(restriction.Prop, Class, one_of)
        else:      RangeClassOnly   (restriction.Prop, Class, ranges)
        
    elif (restriction.type == "EXACTLY") or (restriction.type == "MAX"):
      # These restrictions can make the Property functional for the given Class
      # => Force the redefinition of the field type by creating an empty range restriction list
      for subprop in restriction.Prop.descendant_subclasses():
        prop_children_group = get_prop_children_group(subprop)
        prop_children_group.range_restrictions[Class] # Create the list if not already existent
        prop_children_group.changed = 1
        
      
  elif isinstance(restriction, NotRestriction):
    if isinstance(restriction.Class, Restriction):
      _configure_class_negative_restriction(Class, restriction.Class)
Beispiel #2
0
def _configure_class_restriction(Class, restriction):
    if isinstance(restriction, And):
        for sub_restriction in restriction.Classes:
            _configure_class_restriction(Class, sub_restriction)

    elif isinstance(restriction, Restriction):
        if restriction.type == "VALUE":
            introsp.description(Class).def_attr(restriction.Prop.python_name,
                                                field.LabelField,
                                                priority=_get_priority(
                                                    restriction.Prop))

        elif restriction.type == "ONLY":
            if isinstance(restriction.Prop, ObjectPropertyClass):
                if isinstance(restriction.Class, ThingClass):
                    ranges = [restriction.Class]
                elif isinstance(restriction.Class, LogicalClassConstruct):
                    ranges = list(_flattened_or(restriction.Class.Classes))
                else:
                    return
                if len(ranges) == 1: one_of = _get_class_one_of(ranges[0])
                else: one_of = None
                if one_of: RangeInstanceOnly(restriction.Prop, Class, one_of)
                else: RangeClassOnly(restriction.Prop, Class, ranges)

        elif (restriction.type == "EXACTLY") or (restriction.type == "MAX"):
            # These restrictions can make the Property functional for the given Class
            # => Force the redefinition of the field type by creating an empty range restriction list
            if restriction.cardinality == 1:
                for subprop in restriction.Prop.descendants(
                        include_self=False):
                    prop_children_group = get_prop_children_group(subprop)
                    prop_children_group.range_restrictions[
                        Class]  # Create the list if not already existent
                    prop_children_group.changed = True

    elif isinstance(restriction, Not):
        for sub_restriction in _flattened_or([restriction.Class]):
            if isinstance(sub_restriction, Restriction):
                if sub_restriction.type == SOME and isinstance(
                        sub_restriction.Prop, ObjectPropertyClass):
                    ranges = list(_flattened_or([sub_restriction.Class]))
                    if len(ranges) == 1: one_of = _get_class_one_of(ranges[0])
                    else: one_of = None
                    if one_of:
                        RangeInstanceExclusion(sub_restriction.Prop, Class,
                                               one_of)
                    else:
                        RangeClassExclusion(sub_restriction.Prop, Class,
                                            ranges)
Beispiel #3
0
 def values_have_children(self):
   for range_restriction in self.range_restrictions:
     if isinstance(range_restriction, RangeClassOnly):
       for range in range_restriction.ranges:
         for subrange in range.descendant_subclasses():
           #if introsp.description(subrange).children_getters: return 1
           for attribute in introsp.description(subrange).attributes.values():
             #if _is_field_subclass(attribute.field_class, FieldInHierarchyPane): return 1
             #if is_displayed_in_hierarchy_pane(self.Prop, ): return 1
             try:    return issubclass(attribute.field_class, FieldInHierarchyPane)
             except: return False # attribute.field_class if a func and not a class
Beispiel #4
0
 def values_have_children(self):
     for range_restriction in self.range_restrictions:
         if isinstance(range_restriction, RangeClassOnly):
             for range in range_restriction.ranges:
                 for subrange in range.descendants():
                     for attribute in introsp.description(
                             subrange).attributes.values():
                         try:
                             return issubclass(attribute.field_class,
                                               FieldInHierarchyPane)
                         except:
                             return False  # attribute.field_class if a func and not a class
Beispiel #5
0
def _configure_class_restriction(Class, restriction):
    if isinstance(restriction, AndRestriction):
        for sub_restriction in restriction.Classes:
            _configure_class_restriction(Class, sub_restriction)

    elif isinstance(restriction, OneOfRestriction):
        pass

    elif isinstance(restriction, PropertyValueRestriction):
        if restriction.type == "VALUE":
            introsp.description(Class).def_attr(restriction.Prop.python_name,
                                                field.LabelField,
                                                priority=_get_priority(
                                                    restriction.Prop))

        elif restriction.type == "ONLY":
            if not restriction.Prop._is_data_property():
                if isinstance(restriction.Class, ThingClass):
                    ranges = [restriction.Class]
                else:
                    if not hasattr(restriction.Class, "Classes"): return
                    ranges = restriction.Class.Classes
                if len(ranges) == 1: one_of = _get_class_one_of(ranges[0])
                else: one_of = None
                if one_of: RangeInstanceOnly(restriction.Prop, Class, one_of)
                else: RangeClassOnly(restriction.Prop, Class, ranges)

        elif (restriction.type == "EXACTLY") or (restriction.type == "MAX"):
            # These restrictions can make the Property functional for the given Class
            # => Force the redefinition of the field type by creating an empty range restriction list
            for subprop in restriction.Prop.descendant_subclasses():
                prop_children_group = get_prop_children_group(subprop)
                prop_children_group.range_restrictions[
                    Class]  # Create the list if not already existent
                prop_children_group.changed = 1

    elif isinstance(restriction, NotRestriction):
        if isinstance(restriction.Class, Restriction):
            _configure_class_negative_restriction(Class, restriction.Class)
Beispiel #6
0
 def values_have_children(self):
     for range_restriction in self.range_restrictions:
         if isinstance(range_restriction, RangeClassOnly):
             for range in range_restriction.ranges:
                 for subrange in range.descendant_subclasses():
                     #if introsp.description(subrange).children_getters: return 1
                     for attribute in introsp.description(
                             subrange).attributes.values():
                         #if _is_field_subclass(attribute.field_class, FieldInHierarchyPane): return 1
                         #if is_displayed_in_hierarchy_pane(self.Prop, ): return 1
                         try:
                             return issubclass(attribute.field_class,
                                               FieldInHierarchyPane)
                         except:
                             return False  # attribute.field_class if a func and not a class
Beispiel #7
0
    def define_children_groups(self):
        self.changed = 0

        priority = _get_priority(self.Prop)

        for domain in set(self.range_restrictions):
            descr = introsp.description(domain)
            functional = self.Prop.is_functional_for(domain)
            range_restrictions = set()
            for superclass in domain.mro():
                s = self.range_restrictions.get(superclass)
                if s: range_restrictions.update(s)

            range_instance_onlys = {
                range_restriction
                for range_restriction in range_restrictions
                if isinstance(range_restriction, RangeInstanceOnly)
            }
            if range_instance_onlys:
                instances = None
                for range_restriction in range_instance_onlys:
                    if instances is None:
                        instances = set(range_restriction.ranges)
                    else:
                        instances.intersection_update(
                            set(range_restriction.ranges))

                d = {instance.name: instance for instance in instances}
                if functional:
                    d["None"] = None
                    descr.def_attr(self.Prop.python_name,
                                   field.EnumField(d),
                                   priority=priority)
                else:
                    descr.def_attr(self.Prop.python_name,
                                   field.EnumListField(d),
                                   priority=priority)

            else:
                datatype = None
                for range_restriction in range_restrictions:
                    if isinstance(range_restriction, RangeClassOnly):
                        for range in range_restriction.ranges:
                            if range in _PYTHON_2_DATATYPES:
                                datatype = range
                                break

                if datatype:
                    if datatype == int:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.IntField,
                                           priority=priority)
                        else:
                            descr.def_attr(self.Prop.python_name,
                                           field.IntListField,
                                           priority=priority)
                    elif datatype == float:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.FloatField,
                                           priority=priority)
                        else:
                            descr.def_attr(self.Prop.python_name,
                                           field.FloatListField,
                                           priority=priority)
                    elif datatype == normstr:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.StringField,
                                           priority=priority)
                        else:
                            descr.def_attr(self.Prop.python_name,
                                           field.StringListField,
                                           priority=priority)
                    elif datatype == str:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.TextField,
                                           priority=priority)
                        else:
                            descr.def_attr(self.Prop.python_name,
                                           field.StringListField,
                                           priority=priority)
                    elif datatype == bool:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.BoolField,
                                           priority=priority)
                    else:
                        if functional:
                            descr.def_attr(self.Prop.python_name,
                                           field.EntryField,
                                           priority=priority)
                        else:
                            descr.def_attr(self.Prop.python_name,
                                           field.EntryListField,
                                           priority=priority)

                else:
                    values_lister = ValuesLister(self.Prop, domain,
                                                 range_restrictions)
                    if _prop_use_children_group(
                            self.Prop,
                            domain) or values_lister.values_have_children():
                        if self.Prop.inverse_property:
                            inverse_attr = self.Prop.inverse_property.python_name
                        else:
                            inverse_attr = ""
                        if functional:
                            field_class = field.HierarchyOrObjectSelectorField
                        else:
                            field_class = field.HierarchyOrObjectListField
                        descr.def_attr(
                            self.Prop.python_name,
                            field_class,
                            addable_values=values_lister.available_values,
                            inverse_attr=inverse_attr,
                            priority=priority)
                    else:
                        descr.def_attr(
                            self.Prop.python_name,
                            field.ObjectSelectorField,
                            addable_values=values_lister.available_values,
                            priority=priority)
Beispiel #8
0
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict

import editobj3, editobj3.introsp as introsp, editobj3.field as field, editobj3.editor as editor

import owlready
from owlready import *
from owlready import _PYTHON_2_DATATYPES

IGNORE_DOMAINLESS_PROPERTY = False

introsp.def_attr("topObjectProperty", field.HiddenField)

descr = introsp.description(Ontology)
descr.def_attr("loaded", field.HiddenField)
descr.def_attr("name", field.HiddenField)
descr.def_attr("base_iri", field.StringField)
descr.def_attr("python_module", field.StringField)
descr.def_attr("classes", add_method="add", label="class")
descr.def_attr("imported_ontologies",
               add_method="add",
               label="imported_ontology")
descr.def_attr("properties", add_method="add", label="property")
descr.def_attr("instances", add_method="add")
descr.def_attr("all_disjoints", add_method="add")
descr.set_icon_filename(
    os.path.join(os.path.dirname(__file__), "icons", "owl_instance.svg"))

Beispiel #9
0
  def __str__(self): return self.name
  
  def details(self): return "%s (%s)" % (self.name, len(self.instances))
  
  def class_and_descendant_classes(self):
    return list(set(self.Class.descendant_subclasses()))
  
  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))]
  
descr = introsp.description(EditedInstances)
descr.set_details(EditedInstances.details)
descr.def_attr("instances", label = "", reorder_method = None, addable_values = "addable_values")
descr.def_attr("ontology" , field.HiddenField)
descr.def_attr("Class"    , field.HiddenField)
descr.def_attr("name"     , field.HiddenField)

class TabPaneRepartitor(editor.PaneRepartitor):
  def __init__(self, instance_editor, tab_edited_class):
    self.instance_editor  = instance_editor
    self.tab_edited_class = tab_edited_class
    self._cache           = {}
    
  def is_displayed_in_other_tab(self, attribute, o_Class):
    Prop = PROPS.get(attribute.name)
    if Prop: 
    def __str__(self):
        return self.name

    def details(self):
        return "%s (%s)" % (self.name, len(self.instances))

    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))
        ]


descr = introsp.description(EditedInstances)
descr.set_details(EditedInstances.details)
descr.def_attr("instances",
               label="",
               reorder_method=None,
               addable_values="addable_values")
descr.def_attr("ontology", field.HiddenField)
descr.def_attr("namespace", field.HiddenField)
descr.def_attr("Class", field.HiddenField)
descr.def_attr("name", field.HiddenField)


class TabPaneRepartitor(editor.PaneRepartitor):
    def __init__(self, instance_editor, tab_edited_class):
        self.instance_editor = instance_editor
        self.tab_edited_class = tab_edited_class
Beispiel #11
0
#descr.set_icon_filename(os.path.join(os.path.dirname(__file__), "icons", "owl_class.svg"))

#descr = introsp.description_for_type(Property)
##descr.def_attr("ontology"        , field.ObjectSelectorField, addable_values = _available_ontologies)
#descr.def_attr("namespace"    , field.HiddenField)
#descr.def_attr("name"            , field.StringField)
#descr.def_attr("python_name"     , field.StringField)
#descr.def_attr("is_a"            , field.HierarchyAndObjectListField, addable_values = _available_properties_and_types)
#descr.def_attr("domain"          , field.HierarchyAndObjectListField, addable_values = _available_classes              , reorder_method = None)
#descr.def_attr("range"           , field.HierarchyAndObjectListField, addable_values = _available_classes_and_datatypes, reorder_method = None)
#descr.def_attr("inverse_property", field.ObjectSelectorField        , addable_values = lambda o: [None] + _available_properties(o))
#descr.def_attr("equivalent_to"   , field.HierarchyAndObjectListField, addable_values = _available_properties_and_types)
#descr.set_label(_get_label)
#descr.set_icon_filename(os.path.join(os.path.dirname(__file__), "icons", "owl_property.svg"))

descr = introsp.description(Thing)
descr.def_attr("iri", field.StringField)
descr.def_attr("namespace", field.HiddenField)
descr.def_attr("is_a", field.HiddenField)
descr.def_attr("is_instance_of", field.HiddenField)
descr.def_attr("name", field.HiddenField)
descr.def_attr("storid", field.HiddenField)
descr.def_attr("equivalent_to", field.HiddenField)
descr.def_attr("properties", field.HiddenField)
descr.def_attr("inverse_properties", field.HiddenField)
descr.set_label(_get_label)
descr.set_icon_filename(
    os.path.join(os.path.dirname(__file__), "icons", "owl_instance.svg"))
descr.set_constructor(
    introsp.Constructor(
        lambda Class, parent: Class(namespace=parent.namespace)))
Beispiel #12
0
 def define_children_groups(self):
   self.changed = 0
   
   priority = _get_priority(self.Prop)
   
   for domain in set(self.range_restrictions):
     descr      = introsp.description(domain)
     functional = self.Prop.is_functional_for(domain)
     range_restrictions = set()
     for superclass in domain.mro():
       s = self.range_restrictions.get(superclass)
       if s: range_restrictions.update(s)
       
     range_instance_onlys = { range_restriction for range_restriction in range_restrictions if isinstance(range_restriction, RangeInstanceOnly) }
     if range_instance_onlys:
       instances = None
       for range_restriction in range_instance_onlys:
         if instances is None: instances = set(range_restriction.ranges)
         else:                 instances.intersection_update(set(range_restriction.ranges))
         
       d = { instance.name : instance for instance in instances }
       if functional:
         d["None"] = None
         descr.def_attr(self.Prop.python_name, field.EnumField(d), priority = priority)
       else:
         descr.def_attr(self.Prop.python_name, field.EnumListField(d), priority = priority)
         
     else:
       datatype = None
       for range_restriction in range_restrictions:
         if isinstance(range_restriction, RangeClassOnly):
           for range in range_restriction.ranges:
             if range in _PYTHON_2_DATATYPES:
               datatype = range
               break
               
       if datatype:
         if   datatype == int:
           if functional: descr.def_attr(self.Prop.python_name, field.IntField       , priority = priority)
           else:          descr.def_attr(self.Prop.python_name, field.IntListField   , priority = priority)
         elif datatype == float:
           if functional: descr.def_attr(self.Prop.python_name, field.FloatField     , priority = priority)
           else:          descr.def_attr(self.Prop.python_name, field.FloatListField , priority = priority)
         elif datatype == normstr:
           if functional: descr.def_attr(self.Prop.python_name, field.StringField    , priority = priority)
           else:          descr.def_attr(self.Prop.python_name, field.StringListField, priority = priority)
         elif datatype == str:
           if functional: descr.def_attr(self.Prop.python_name, field.TextField      , priority = priority)
           else:          descr.def_attr(self.Prop.python_name, field.StringListField, priority = priority)
         elif datatype == bool:
           if functional: descr.def_attr(self.Prop.python_name, field.BoolField      , priority = priority)
         else:
           if functional: descr.def_attr(self.Prop.python_name, field.EntryField     , priority = priority)
           else:          descr.def_attr(self.Prop.python_name, field.EntryListField , priority = priority)
           
       else:
         values_lister = ValuesLister(self.Prop, domain, range_restrictions)
         if _prop_use_children_group(self.Prop, domain) or values_lister.values_have_children():
           if self.Prop.inverse_property: inverse_attr = self.Prop.inverse_property.python_name
           else:                          inverse_attr = ""
           if functional: field_class = field.HierarchyOrObjectSelectorField
           else:          field_class = field.HierarchyOrObjectListField
           descr.def_attr(self.Prop.python_name,
                          field_class,
                          addable_values = values_lister.available_values,
                          inverse_attr = inverse_attr,
                          priority = priority)
         else:
           descr.def_attr(self.Prop.python_name,
                          field.ObjectSelectorField, addable_values = values_lister.available_values,
                          priority = priority)
Beispiel #13
0
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict

import editobj3, editobj3.introsp as introsp, editobj3.field as field, editobj3.editor as editor

import owlready
from owlready import *
from owlready import _PYTHON_2_DATATYPES

IGNORE_DOMAINLESS_PROPERTY = False

introsp.def_attr("topObjectProperty"  , field.HiddenField)

descr = introsp.description(Ontology)
descr.def_attr("loaded"             , field.HiddenField)
descr.def_attr("name"               , field.HiddenField)
descr.def_attr("base_iri"           , field.StringField)
descr.def_attr("python_module"      , field.StringField)
descr.def_attr("classes"            , add_method = "add", label = "class")
descr.def_attr("imported_ontologies", add_method = "add", label = "imported_ontology")
descr.def_attr("properties"         , add_method = "add", label = "property")
descr.def_attr("instances"          , add_method = "add")
descr.def_attr("all_disjoints"      , add_method = "add")
descr.set_icon_filename(os.path.join(os.path.dirname(__file__), "icons", "owl_instance.svg"))

def _keep_most_generic(s):
  r = set()
  for i in s:
    for parent in i.is_a: