示例#1
0
 def iter_see_alsos(self):
     """Iter over the resources related to this item"""
     for uri in self.iter_see_also_uris():
         res = universal_factory(uri)
         if res is None:
             raise ValueError("Could not make resource <%s>" % uri)
         yield res
示例#2
0
文件: example1.py 项目: ktbs/ktbs
 def iter_see_alsos(self):
     """Iter over the resources related to this item"""
     for uri in self.iter_see_also_uris():
         res = universal_factory(uri)
         if res is None:
             raise ValueError("Could not make resource <%s>" % uri)
         yield res
示例#3
0
    def iter_builtin_methods(self):
        """
        I list all the builtin methods implemented by this kTBS.

        :rtype: an iterable of `~.builtin_method.MethodBuiltinMixin`:class:
        """
        for obs in self.state.objects(self.uri, KTBS.hasBuiltinMethod):
            yield universal_factory(obs, [KTBS.BuiltinMethod])
示例#4
0
文件: ktbs_root.py 项目: ktbs/ktbs
    def iter_builtin_methods(self):
        """
        I list all the builtin methods implemented by this kTBS.

        :rtype: an iterable of `~.builtin_method.MethodBuiltinMixin`:class:
        """
        for obs in self.state.objects(self.uri, KTBS.hasBuiltinMethod):
            yield universal_factory(obs, [KTBS.BuiltinMethod])
示例#5
0
    def get_model(self):
        """
        I return the trace model of this trace.

        :rtype: `~.trace_model.TraceModelMixin`:class:
        """
        tmodel_uri = self.state.value(self.uri, KTBS.hasModel)
        return universal_factory(tmodel_uri, [KTBS.TraceModel])
示例#6
0
文件: method.py 项目: ktbs/ktbs
 def get_parent(self):
     """
     I return the inherited method.
     """
     method_uri = self.state.value(self.uri, KTBS.hasParentMethod)
     if method_uri is None:
         return None
     else:
         return universal_factory(method_uri, [KTBS.Method])
示例#7
0
 def get_parent(self):
     """
     I return the inherited method.
     """
     method_uri = self.state.value(self.uri, KTBS.hasParentMethod)
     if method_uri is None:
         return None
     else:
         return universal_factory(method_uri, [KTBS.Method])
示例#8
0
    def iter_obsel_types(self):
        """
        I iter over the obsel types containing this attribute.

        :rtype: iterable of `ObselTypeMixin`:class:
        """
        for uri in self.state.objects(self.uri, _HAS_ATT_OBSELTYPE):
            ret = universal_factory(uri, [KTBS.ObselType])
            assert isinstance(ret, ObselTypeMixin)
            yield ret
示例#9
0
文件: trace_model.py 项目: ktbs/ktbs
    def iter_destinations(self):
        """
        I iter over the destination obsel types of this relation.

        :rtype: iterable of `ObselTypeMixin`:class:
        """
        for uri in self.state.objects(self.uri, _HAS_REL_DESTINATION):
            ret = universal_factory(uri, [KTBS.ObselType])
            assert isinstance(ret, ObselTypeMixin), ret
            yield ret
示例#10
0
文件: trace_model.py 项目: ktbs/ktbs
    def iter_obsel_types(self):
        """
        I iter over the obsel types containing this attribute.

        :rtype: iterable of `ObselTypeMixin`:class:
        """
        for uri in self.state.objects(self.uri, _HAS_ATT_OBSELTYPE):
            ret = universal_factory(uri, [KTBS.ObselType])
            assert isinstance(ret, ObselTypeMixin)
            yield ret
示例#11
0
    def iter_destinations(self):
        """
        I iter over the destination obsel types of this relation.

        :rtype: iterable of `ObselTypeMixin`:class:
        """
        for uri in self.state.objects(self.uri, _HAS_REL_DESTINATION):
            ret = universal_factory(uri, [KTBS.ObselType])
            assert isinstance(ret, ObselTypeMixin), ret
            yield ret
示例#12
0
文件: ktbs_root.py 项目: ktbs/ktbs
    def get_builtin_method(self, uri):
        """I return the built-in method identified by `uri` if supported.

        :rtype: `~.builtin_method.MethodBuiltinMixin`:class:
        """
        uri = coerce_to_uri(uri)
        if (self.uri, KTBS.hasBuiltinMethod, uri) in self.state:
            return universal_factory(uri, [KTBS.BuiltinMethod])
        else:
            return None
示例#13
0
    def get_builtin_method(self, uri):
        """I return the built-in method identified by `uri` if supported.

        :rtype: `~.builtin_method.MethodBuiltinMixin`:class:
        """
        uri = coerce_to_uri(uri)
        if (self.uri, KTBS.hasBuiltinMethod, uri) in self.state:
            return universal_factory(uri, [KTBS.BuiltinMethod])
        else:
            return None
示例#14
0
文件: trace_model.py 项目: ktbs/ktbs
 def iter_inverse_relation_types(self, include_inherited=True):
     """
     I iter over the relation types having this obsel type as destination.
     """
     if include_inherited:
         for supertype in self.iter_supertypes(True):
             for rtype in supertype.iter_inverse_relation_types(False):
                 yield rtype
     else:
         for uri in self.state.subjects(_HAS_REL_DESTINATION, self.uri):
             yield universal_factory(uri, [KTBS.RelationType])
示例#15
0
文件: trace_model.py 项目: ktbs/ktbs
 def iter_attribute_types(self, include_inherited=True):
     """
     I iter over the attribute types allowed for this type.
     """
     if include_inherited:
         for supertype in self.iter_supertypes(True):
             for atype in supertype.iter_attribute_types(False):
                 yield atype
     else:
         for uri in self.state.subjects(_HAS_ATT_OBSELTYPE, self.uri):
             yield universal_factory(uri, [KTBS.AttributeType])
示例#16
0
 def iter_attribute_types(self, include_inherited=True):
     """
     I iter over the attribute types allowed for this type.
     """
     if include_inherited:
         for supertype in self.iter_supertypes(True):
             for atype in supertype.iter_attribute_types(False):
                 yield atype
     else:
         for uri in self.state.subjects(_HAS_ATT_OBSELTYPE, self.uri):
             yield universal_factory(uri, [KTBS.AttributeType])
示例#17
0
 def iter_inverse_relation_types(self, include_inherited=True):
     """
     I iter over the relation types having this obsel type as destination.
     """
     if include_inherited:
         for supertype in self.iter_supertypes(True):
             for rtype in supertype.iter_inverse_relation_types(False):
                 yield rtype
     else:
         for uri in self.state.subjects(_HAS_REL_DESTINATION, self.uri):
             yield universal_factory(uri, [KTBS.RelationType])
示例#18
0
 def iter_supertypes(self, include_indirect=False):
     """
     I list the supertypes of this type.
     If include_indirect is True, all supertypes are listed,
     including indirect supertypes and this type itself
     """
     if include_indirect:
         return _closure(self, "supertypes")
     else:
         return (universal_factory(uri, [
             self._RDF_TYPE
         ]) for uri in self.state.objects(self.uri, self._SUPER_TYPE_PROP))
示例#19
0
文件: trace_model.py 项目: ktbs/ktbs
 def iter_supertypes(self, include_indirect=False):
     """
     I list the supertypes of this type.
     If include_indirect is True, all supertypes are listed,
     including indirect supertypes and this type itself
     """
     if include_indirect:
         return _closure(self, "supertypes")
     else:
         return ( universal_factory(uri, [self._RDF_TYPE])
                  for uri in self.state.objects(self.uri, 
                                                 self._SUPER_TYPE_PROP) )
示例#20
0
 def iter_parents(self, include_indirect=False):
     """
     I iter over all the parent models of this model.
     """
     cache = set()
     for uri in self.state.objects(self.uri, KTBS.hasParentModel):
         model = universal_factory(uri, [KTBS.TraceModel]) or uri
         if include_indirect:
             cache.add(model)
         yield model
     if include_indirect:
         for model in list(cache):
             for i in model.iter_parents(include_indirect=True):
                 if i not in cache:
                     cache.add(i)
                     yield i
示例#21
0
文件: trace_model.py 项目: ktbs/ktbs
 def iter_parents(self, include_indirect=False):
     """
     I iter over all the parent models of this model.
     """
     cache = set()
     for uri in self.state.objects(self.uri, KTBS.hasParentModel):
         model = universal_factory(uri, [KTBS.TraceModel]) or uri
         if include_indirect:
             cache.add(model)
         yield model
     if include_indirect:
         for model in list(cache):
             for i in model.iter_parents(include_indirect=True):
                 if i not in cache:
                     cache.add(i)
                     yield i
示例#22
0
    def complete_new_graph(cls,
                           service,
                           uri,
                           parameters,
                           new_graph,
                           resource=None):
        """I implement :meth:`ILocalCore.complete_new_graph`.

        At create time, I add default values for missing information about the
        trace.
        """
        super(StoredTrace, cls).complete_new_graph(service, uri, parameters,
                                                   new_graph, resource)
        if resource is None:
            origin = new_graph.value(uri, KTBS.hasOrigin)
            if origin is None:
                origin = Literal("o" + random_token(32))
                # start origin with a letter because if it starts with 4 digits,
                # it will be misinterpreted for a year
                new_graph.add((uri, KTBS.hasOrigin, origin))
            elif unicode(origin) == "now":
                origin = Literal("%sZ" % datetime.utcnow().isoformat())
                new_graph.set((uri, KTBS.hasOrigin, origin))

        # compute begin and/or end if beginDT and/or endDT are provided
        begin_dt = lit2datetime(new_graph.value(uri, KTBS.hasTraceBeginDT))
        end_dt = lit2datetime(new_graph.value(uri, KTBS.hasTraceEndDT))
        if begin_dt or end_dt:
            model = universal_factory(new_graph.value(uri, KTBS.hasModel),
                                      [KTBS.TraceModel])
            delta2unit = get_converter_to_unit(model.unit)
            origin = lit2datetime(new_graph.value(uri, KTBS.hasOrigin))
            if origin is not None:
                if delta2unit is not None:
                    if begin_dt is not None:
                        begin = delta2unit(begin_dt - origin)
                        new_graph.add(
                            (uri, KTBS.hasTraceBegin, Literal(begin)))
                    if end_dt is not None:
                        end = delta2unit(end_dt - origin)
                        new_graph.add((uri, KTBS.hasTraceEnd, Literal(end)))
示例#23
0
文件: trace.py 项目: ktbs/ktbs
    def complete_new_graph(cls, service, uri, parameters, new_graph,
                           resource=None):
        """I implement :meth:`ILocalCore.complete_new_graph`.

        At create time, I add default values for missing information about the
        trace.
        """
        super(StoredTrace, cls).complete_new_graph(service, uri, parameters,
                                                   new_graph, resource)
        if resource is None:
            origin = new_graph.value(uri, KTBS.hasOrigin)
            if origin is None:
                origin = Literal("o"+random_token(32))
                # start origin with a letter because if it starts with 4 digits,
                # it will be misinterpreted for a year
                new_graph.add((uri, KTBS.hasOrigin, origin))
            elif unicode(origin) == "now":
                origin = Literal("%sZ" % datetime.utcnow().isoformat())
                new_graph.set((uri, KTBS.hasOrigin, origin))


        # compute begin and/or end if beginDT and/or endDT are provided
        begin_dt = lit2datetime(new_graph.value(uri, KTBS.hasTraceBeginDT))
        end_dt = lit2datetime(new_graph.value(uri, KTBS.hasTraceEndDT))
        if begin_dt or end_dt:
            model = universal_factory(new_graph.value(uri, KTBS.hasModel),
                                      [KTBS.TraceModel])
            delta2unit = get_converter_to_unit(model.unit)
            origin = lit2datetime(new_graph.value(uri, KTBS.hasOrigin))
            if origin is not None:
                if delta2unit is not None:
                    if begin_dt is not None:
                        begin = delta2unit(begin_dt - origin)
                        new_graph.add((uri, KTBS.hasTraceBegin, Literal(begin)))
                    if end_dt is not None:
                        end = delta2unit(end_dt - origin)
                        new_graph.add((uri, KTBS.hasTraceEnd, Literal(end)))
示例#24
0
    def _method_impl(self):
        """I hold the python object implementing my method.
        """
        if self.__method_impl is None:
            uri = self.get_method_uri()
            ret = get_builtin_method_impl(uri)

            while ret is None:
                met = universal_factory(uri, [KTBS.Method])
                try:
                    parent_uri = getattr(met, "parent_uri", None)
                except:
                    parent_uri = None
                if parent_uri:
                    uri = parent_uri
                    ret = get_builtin_method_impl(uri)
                else:
                    ret = get_builtin_method_impl(uri, True)
                    # the above will always return a method (possibly fake)
                    # so we will exit the loop
            self.__method_impl = ret
        else:
            ret = self.__method_impl
        return ret
示例#25
0
文件: trace.py 项目: ktbs/ktbs
    def _method_impl(self):
        """I hold the python object implementing my method.
        """
        if self.__method_impl is None:
            uri = self.get_method_uri()
            ret = get_builtin_method_impl(uri)

            while ret is None:
                met = universal_factory(uri, [KTBS.Method])
                try:
                    parent_uri = getattr(met, "parent_uri", None)
                except:
                    parent_uri = None
                if parent_uri:
                    uri = parent_uri
                    ret = get_builtin_method_impl(uri)
                else:
                    ret = get_builtin_method_impl(uri, True)
                    # the above will always return a method (possibly fake)
                    # so we will exit the loop
            self.__method_impl = ret
        else:
            ret = self.__method_impl
        return ret
示例#26
0
 def get_method(self):
     """I return the method used by this computed trace
     """
     return universal_factory(self.state.value(self.uri, KTBS.hasMethod),
                              [KTBS.Method])