KTBS API

I provide an implementation of the Abstract KTBS API.

This implementation is defined as a set of mix-in classes that rely on the uniform interface of rdfrest.cores.ICore. This allows to use those classes in different ways:

  • as local instances (for a standalone kTBS embeded in one’s application),
  • as an HTTP client to a remote kTBS,
  • or even as a client through any protocol implemented on top of rdfrest.

Extensions to the abstract API

I implement the following extensions to the default Abstract KTBS API.

Extensions suggested by the abstract API

  • read-only or read-write properties corresponding to get/set methods
  • read-only properties corresponding to list methods
  • iter methods corresponding to list methods

Note also that those adaptations are automatically generated by the extend_api() class decorator.

Specific extensions for function parameters

  • Anytime a kTBS element is expected, passing a URI should also work (including a URI relative to the target object). For example, the ‘model’ argument of create_stored_trace() can be a URI (as a unicode or an URIRef) rather than an instance of TraceModel.
  • Datetimes can be used instead of integers for representing timecodes in traces when the trace model and origin allow the conversion.

Specific extensions for creation methods

  • The id parameter is specified in the Abstract KTBS API in all creation methods: it is often optional but can be used to set the URI of the resource to create (else, the KTBS will generate a URI). If provided, it must of course be an acceptable URI (not already in use, and subordinated to the parent’s URI). As specified by the Abstract KTBS API, id can be provided as character string, representing a URI either absolute or relative to the parent’s URI. The Python implementation also accepts a rdflib.URIRef or any object with a uri attribute returning a URIRef.
  • Creation methods also accept an additional parameter graph where the user can specify arbitrary properties for the resource to create. This assumes that the resource can be identified in the graph, which is trivial is id is provided. However, if the user wants to provide a graph but also wants to let the KTBS mint a URI for the created resource, they can use a blank node) to represent the resource in graph, and pass it to id.

Resource API

Inheritance diagram of ktbs.api.resource

I provide the pythonic interface common to all kTBS resources.

class ktbs.api.resource.KtbsResourceMixin[source]

I provide the pythonic interface common to all kTBS resources.

get_id()[source]

Return the identifier of this resource.

get_uri()[source]

Return the URI of this resource.

get_label()[source]

Return a user-friendly label for this resource.

If no label has been set, a default label is generated from this resource’s URI.

set_label(value)[source]

Set a user-friendly label for this resource.

reset_label()[source]

Reset the user-friendly label to its default value.

remove()[source]

Remove this resource from the kTBS.

get_readonly()[source]

I return True if this resource can not be modified

get_sync_status()[source]

I return True if this resource is up to date

This is meaningful only if the resource is a “view” on a remote resource. If the resource is self-contained, it is always up to date.

state

I store and return the result of get_state.

This property makes it more concise and hopefully slightly more efficient than to call rdfrest.cores.ICore.get_state() each time we need this resource’s graph.

Note that this graph must not be edited. We must use rdfrest.cores.ICore.get_state() instead.

id

Return the identifier of this resource.

label

Return a user-friendly label for this resource.

If no label has been set, a default label is generated from this resource’s URI.

readonly

I return True if this resource can not be modified

sync_status

I return True if this resource is up to date

This is meaningful only if the resource is a “view” on a remote resource. If the resource is self-contained, it is always up to date.

KtbsRoot API

Inheritance diagram of ktbs.api.ktbs_root

I provide the pythonic interface of ktbs:KtbsRoot .

class ktbs.api.ktbs_root.KtbsRootMixin[source]

I provide the pythonic interface common to ktbs root.

iter_builtin_methods()[source]

I list all the builtin methods implemented by this kTBS.

Return type:an iterable of MethodBuiltinMixin
iter_bases()[source]

I iter over all elements owned by this base.

Return type:an iterable of BaseMixin
get_builtin_method(uri)[source]

I return the built-in method identified by uri if supported.

Return type:MethodBuiltinMixin
get_base(id)[source]

I return the base corresponding to the given URI.

Return type:BaseMixin
create_base(id=None, label=None, graph=None)[source]

Create a new base in this kTBS.

Parameters:
Return type:

BaseMixin

bases

Make a list from iter_bases

builtin_methods

Make a list from iter_builtin_methods

list_bases(*args, **kw)

Make a list from iter_bases

list_builtin_methods(*args, **kw)

Make a list from iter_builtin_methods

Base API

Inheritance diagram of ktbs.api.base

I provide the pythonic interface of ktbs:Base .

class ktbs.api.base.BaseMixin[source]

I provide the pythonic interface common to bases.

iter_bases()[source]

Iter over all the sub-bases of this base.

Return type:an iterable of BaseMixin
iter_traces()[source]

Iter over all the traces (stored or computed) of this base.

Return type:an iterable of AbstractTraceMixin
iter_models()[source]

Iter over all the trace models of this base.

Return type:an iterable of TraceModelMixin
iter_methods()[source]

Iter over all the methods of this base.

Return type:an iterable of MethodMixin
iter_data_graphs()[source]

Iter over all the methods of this base.

Return type:an iterable of MethodMixin
get(id)[source]

Return one of the element contained in the base.

Parameters:id (str) – the URI of the element; can be relative to the URI of the base
Return type:BaseMixin, TraceModelMixin, Method or AbstractTraceMixin
get_parent()[source]

Return the root of the KTBS containing this base.

Return type:KtbsRootMixin
get_depth()[source]

Return the distance of this base to the kTBS root.

create_base(id=None, label=None, graph=None)[source]

Create a new base in this kTBS.

Parameters:
Return type:

BaseMixin

create_model(id=None, parents=None, label=None, graph=None)[source]

Create a new model in this trace base.

Parameters:
Return type:

TraceModelMixin

create_method(id=None, parent=None, parameters=None, label=None, graph=None)[source]

Create a new computed trace in this trace base.

Parameters:
Return type:

MethodMixin

create_stored_trace(id=None, model=None, origin=None, default_subject=None, label=None, graph=None)[source]

Create a new store trace in this trace base.

Parameters:
  • id – see Specific extensions for creation methods
  • model – mode of the trace to create (required)
  • origin – Typically a timestamp. It can be an opaque string, meaning that the precise time when the trace was collected is not known
  • default_subject – The subject to set to new obsels when they do not specifify a subject
  • label – explain.
  • graph – see Specific extensions for creation methods
Return type:

StoredTraceMixin

create_computed_trace(id=None, method=None, parameters=None, sources=None, label=None, graph=None)[source]

Create a new computed trace in this trace base.

Parameters:
Return type:

ComputedTraceMixin

create_data_graph(id=None, label=None, graph=None)[source]

Create a new base in this kTBS.

Parameters:
Return type:

InBaseMixin

remove()[source]

Delete this base from the kTBS.

bases

Make a list from iter_bases

data_graphs

Make a list from iter_data_graphs

depth

Return the distance of this base to the kTBS root.

list_bases(*args, **kw)

Make a list from iter_bases

list_data_graphs(*args, **kw)

Make a list from iter_data_graphs

list_methods(*args, **kw)

Make a list from iter_methods

list_models(*args, **kw)

Make a list from iter_models

list_traces(*args, **kw)

Make a list from iter_traces

methods

Make a list from iter_methods

models

Make a list from iter_models

parent

Return the root of the KTBS containing this base.

Return type:KtbsRootMixin
traces

Make a list from iter_traces

class ktbs.api.base.InBaseMixin[source]

Common mixin for all elements of a trace base.

get_base()[source]

Return the trace base this element belongs to.

Return type:BaseMixin
remove()[source]

Delete this element from its base.

base

Return the trace base this element belongs to.

Return type:BaseMixin

TraceModel API

Inheritance diagram of ktbs.api.trace_model

I provide the pythonic interface of ktbs:TraceModel .

class ktbs.api.trace_model.TraceModelMixin[source]

I provide the pythonic interface to a trace model.

get_unit()[source]

Return the temporal unit used by this model.

set_unit(unit)[source]

Return the temporal unit used by this model.

get(id)[source]

Return the pythonic instance corresponding to the given id, or None.

Parameters:id (str) – a URI; can be relative to this Model’s URI
Return type:AttributeTypeMixin:class, ObselTypeMixin or RelationTypeMixin

NB: None if the id is not found but also if it does not identify a Model element (ObselType, AttributeType or RelationType).

iter_parents(include_indirect=False)[source]

I iter over all the parent models of this model.

iter_attribute_types(include_inherited=True)[source]

I iter over the attribute types used in this trace model.

iter_obsel_types(include_inherited=True)[source]

I iter over the obsel types used in this trace model.

iter_relation_types(include_inherited=True)[source]

I iter over the relation types used in this trace model.

add_parent(model)[source]

I add model as a parent model to this model.

remove_parent(model)[source]

I remove model as a parent model to this model.

create_obsel_type(id=None, supertypes=(), label=None)[source]

I create a new obsel type in this model.

Parameters:
Return type:

ObselTypeMixin

create_relation_type(id=None, origins=None, destinations=None, supertypes=(), label=None)[source]

I create a new relation type in this model.

Parameters:
Return type:

RelationTypeMixin

create_attribute_type(id=None, obsel_types=None, data_types=None, value_is_list=False, label=None)[source]

I create a new obsel type in this model.

Parameters:
Return type:

AttributeTypeMixin

add_supertype(element=None, element_type=None, super_type=None)[source]

I add a super type to the element (obsel or relation) type in this model.

Parameters:
  • element – ObselType or RelationType or their URI.
  • element_type – Type of the concerned element.
  • super_type – SuperObselType or SuperRelationType.
remove_supertype(element=None, element_type=None, super_type=None)[source]

I remove a super type from the element (obsel or relation) type in this model.

Parameters:
  • element – ObselType or RelationType or their URI.
  • element_type – Type of the concerned element.
  • super_type – SuperObselType or SuperRelationType.
attribute_types

Make a list from iter_attribute_types

list_attribute_types(*args, **kw)

Make a list from iter_attribute_types

list_obsel_types(*args, **kw)

Make a list from iter_obsel_types

list_parents(*args, **kw)

Make a list from iter_parents

list_relation_types(*args, **kw)

Make a list from iter_relation_types

obsel_types

Make a list from iter_obsel_types

parents

Make a list from iter_parents

relation_types

Make a list from iter_relation_types

unit

Return the temporal unit used by this model.

class ktbs.api.trace_model.AttributeTypeMixin[source]

I provide the pythonic interface to an attribute type.

iter_obsel_types()[source]

I iter over the obsel types containing this attribute.

Return type:iterable of ObselTypeMixin
add_obsel_type(obsel_type)[source]

I add an obsel type to this attribute.

remove_obsel_type(obsel_type)[source]

I remove an obsel type from this attribute.

iter_data_types()[source]

I iter over the data types allowed for this attribute.

Returns the types as URIRefs

add_data_type(data_type)[source]

I add the data type to this attribute.

remove_data_type(data_type)[source]

I remove the data type from this attribute.

data_types

Make a list from iter_data_types

list_data_types(*args, **kw)

Make a list from iter_data_types

list_obsel_types(*args, **kw)

Make a list from iter_obsel_types

obsel_types

Make a list from iter_obsel_types

class ktbs.api.trace_model.ObselTypeMixin[source]

I provide the pythonic interface to an obsel type.

iter_attribute_types(include_inherited=True)[source]

I iter over the attribute types allowed for this type.

iter_relation_types(include_inherited=True)[source]

I iter over the relation types having this obsel type as origin.

iter_inverse_relation_types(include_inherited=True)[source]

I iter over the relation types having this obsel type as destination.

create_attribute_type(id=None, data_types=None, value_is_list=False, label=None)[source]

Call the associated Model method.

create_relation_type(id=None, destinations=None, supertypes=(), label=None)[source]

Call the associated Model method.

attribute_types

Make a list from iter_attribute_types

inverse_relation_types

Make a list from iter_inverse_relation_types

list_attribute_types(*args, **kw)

Make a list from iter_attribute_types

list_inverse_relation_types(*args, **kw)

Make a list from iter_inverse_relation_types

list_relation_types(*args, **kw)

Make a list from iter_relation_types

relation_types

Make a list from iter_relation_types

class ktbs.api.trace_model.RelationTypeMixin[source]

I provide the pythonic interface to a relation type.

iter_origins()[source]

I iter over the origin obsel types of this relation.

Return type:iterable of ObselTypeMixin
iter_destinations()[source]

I iter over the destination obsel types of this relation.

Return type:iterable of ObselTypeMixin
iter_all_origins()[source]

I iter over all the origins (direct or inherited) of this relation.

Return type:iterator of ObselTypeMixin
iter_all_destinations()[source]

I iter over all the destinations (direct or inherited) of this relation.

Return type:iterator of ObselTypeMixin
add_origin(origin)[source]

I add an obsel type to this attribute.

remove_origin(origin)[source]

I remove an obsel type from this attribute.

add_destination(destination)[source]

I add an obsel type to this attribute.

remove_destination(destination)[source]

I remove an obsel type from this attribute.

all_destinations

Make a list from iter_all_destinations

all_origins

Make a list from iter_all_origins

destinations

Make a list from iter_destinations

list_all_destinations(*args, **kw)

Make a list from iter_all_destinations

list_all_origins(*args, **kw)

Make a list from iter_all_origins

list_destinations(*args, **kw)

Make a list from iter_destinations

list_origins(*args, **kw)

Make a list from iter_origins

origins

Make a list from iter_origins

Trace API

Inheritance diagram of ktbs.api.trace

I provide the pythonic interface of ktbs:StoredTrace and ktbs:ComputedTrace.

class ktbs.api.trace.AbstractTraceMixin[source]

I provide the pythonic interface common to all kTBS traces.

get_obsel(id)[source]

Return the obsel with the given uri.

Parameters:id (str) – the URI of the obsel; may be relative to the URI of the trace
Return type:ObselMixin
get_model()[source]

I return the trace model of this trace.

Return type:TraceModelMixin
get_origin(as_datetime=False)[source]

I return the origin of this trace.

If as_datetime is true, get_origin will try to convert the return value to datetime, or return it unchanged if that fails.

iter_obsels(begin=None, end=None, after=None, before=None, reverse=False, bgp=None, limit=None, offset=None, refresh=None)[source]

Iter over the obsels of this trace.

Return type:an iterable of ObselMixin

The obsels are sorted by their end timestamp, then their begin timestamp, then their identifier. If reverse is true, the order is inversed.

If given, begin and/or end are interpreted as the (included) boundaries of an interval; only obsels entirely contained in this interval will be yielded.

  • begin: an int, datetime
  • end: an int, datetime
  • after: an obsel, URIRef
  • before: an obsel, URIRef
  • reverse: an object with a truth value
  • bgp: an additional SPARQL Basic Graph Pattern to filter obsels
  • limit: an int
  • offset: an int
  • refresh:
    • if “no”, prevent force_state_refresh to be called
    • if None or “default”, force_state_refresh will be called
    • if “yes” or “force”, will force recomputation of a ComputedTrace even if the sources have not change
    • if “recursive”, will recursively force recomputatioon as above

In the bgp parameter, notice that:

  • the variable ?obs is bound each obsel
  • the m: prefix is bound to the trace model

NB: the order of “recent” obsels may vary even if the trace is not amended, since collectors are not bound to respect the order in begin timestamps and identifiers.

iter_source_traces()[source]

I iter over the sources of this computed trace.

iter_transformed_traces()[source]

Iter over the traces having this trace as a source.

iter_contexts()[source]

I iter over the contexts of this computed trace.

add_source_trace(val)[source]

I add a source trace to this trace

del_source_trace(val)[source]

I break the link between this trace and one of its source traces

get_model_uri()[source]

I return the URI of the trace model of this trace.

get_model_prefix(_NICE_SUFFIX=set(['#', '/']))[source]

I return a prefix-friendly version of the model URI for this trace.

obsel_collection

This trace’s obsel collection as a raw resource.

Return type:trace_obsels.AbstractTraceObselsMixin
trace_statistics

This trace’s statistics.

Return type:trace_stats.TraceStatistics
get_pseudomon_range()[source]

Return the pseudo-monotonicity range of this trace.

If the pseudo-monotonicity range is X, all changes applied less than X time-units before the last obsel will be considered pseudo-monotonic.

TODO DOC reference to a detailed explaination about monotonicity.

set_pseudomon_range(val)[source]

Return the pseudo-monotonicity range of this trace.

See-also:get_pseudomon_range()

TODO DOC reference to a detailed explaination about monotonicity.

get_trace_begin()[source]

I return the begin timestamp of the obsel.

get_trace_begin_dt()[source]

I return the begin dateteime of the obsel.

get_trace_end()[source]

I return the end timestamp of the obsel.

get_trace_end_dt()[source]

I return the end timestamp of the obsel.

iter_context_uris()[source]

I iter over the context URIs of this computed trace.

context_uris

Make a list from iter_context_uris

contexts

Make a list from iter_contexts

list_context_uris(*args, **kw)

Make a list from iter_context_uris

list_contexts(*args, **kw)

Make a list from iter_contexts

list_obsels(*args, **kw)

Make a list from iter_obsels

list_source_traces(*args, **kw)

Make a list from iter_source_traces

list_transformed_traces(*args, **kw)

Make a list from iter_transformed_traces

model

I return the trace model of this trace.

Return type:TraceModelMixin
model_prefix

I return a prefix-friendly version of the model URI for this trace.

model_uri

I return the URI of the trace model of this trace.

obsels

Make a list from iter_obsels

origin

I return the origin of this trace.

If as_datetime is true, get_origin will try to convert the return value to datetime, or return it unchanged if that fails.

pseudomon_range

Return the pseudo-monotonicity range of this trace.

If the pseudo-monotonicity range is X, all changes applied less than X time-units before the last obsel will be considered pseudo-monotonic.

TODO DOC reference to a detailed explaination about monotonicity.

source_traces

Make a list from iter_source_traces

trace_begin

I return the begin timestamp of the obsel.

trace_begin_dt

I return the begin dateteime of the obsel.

trace_end

I return the end timestamp of the obsel.

trace_end_dt

I return the end timestamp of the obsel.

transformed_traces

Make a list from iter_transformed_traces

class ktbs.api.trace.StoredTraceMixin[source]

I provide the pythonic interface common to kTBS stored traces.

set_model(model)[source]

I set the model of this trace. model can be a Model or a URI; relative URIs are resolved against this trace’s URI.

set_origin(origin)[source]

I set the origin of this trace. origin can be a string or a datetime.

get_default_subject()[source]

I return the default subject of this trace.

set_default_subject(subject)[source]

I set the default subject of this trace.

set_trace_begin(val)[source]

I set the begin timestamp of the obsel.

This will automatically unset the trace_begin_dt property.

set_trace_begin_dt(val)[source]

I return the begin datetime of the obsel.

This will automatically update the trace_begin property.

set_trace_end(val)[source]

I set the end timestamp of the obsel.

This will automatically unset the trace_end_dt property.

set_trace_end_dt(val)[source]

I return the end datetime of the obsel.

This will automatically update the trace_end property.

create_obsel(id=None, type=None, begin=None, end=None, subject=None, attributes=None, relations=None, inverse_relations=None, source_obsels=None, label=None, no_return=False)[source]

Creates a new obsel for the stored trace.

Parameters:
  • id – see Specific extensions for creation methods.
  • type – Obsel type, defined by the Trace model.
  • begin – Begin timestamp of the obsel, can be an int.
  • end – End timestamp of the obsel, can be an int.
  • subject – Subject of the obsel.
  • attributes – explain.
  • relations – explain.
  • inverse_relations – explain.
  • source_obsels – explain.
  • label – explain.
  • no_return – if True, None will be returned instead of the created obsek; this saves time and (in the case of a remote kTBS) network traffic
Return type:

ktbs.client.obsel.Obsel

default_subject

I return the default subject of this trace.

model

I return the trace model of this trace.

Return type:TraceModelMixin
origin

I return the origin of this trace.

If as_datetime is true, get_origin will try to convert the return value to datetime, or return it unchanged if that fails.

trace_begin

I return the begin timestamp of the obsel.

trace_begin_dt

I return the begin dateteime of the obsel.

trace_end

I return the end timestamp of the obsel.

trace_end_dt

I return the end timestamp of the obsel.

class ktbs.api.trace.ComputedTraceMixin[source]

I provide the pythonic interface common to kTBS computed traces.

get_method()[source]

I return the method used by this computed trace

set_method(val)[source]

I set the method that this computed trace will use

add_source_trace(val)[source]

I override AbstractTraceMixin.add_source_trace()

I force the refresh of this trace after the change, as it may have changed computed properties.

del_source_trace(val)[source]

I override AbstractTraceMixin.del_source_trace()

I force the refresh of this trace after the change, as it may have changed computed properties.

set_parameter(key, value)[source]

I override method.WithParametersMixin.set_parameter()

I force the refresh of this trace after the change, as it may have changed computed properties.

del_parameter(key)[source]

I override method.WithParametersMixin.del_parameter()

I force the refresh of this trace after the change, as it may have changed computed properties.

get_diagnosis(force_refresh=False)[source]

I return the diagnosis of the last execution of this computed trace.

Note that the diagnosis is None iff the execution succeeded.

get_method_uri()[source]

I return the URI of the method used by this computed trace

diagnosis

I return the diagnosis of the last execution of this computed trace.

Note that the diagnosis is None iff the execution succeeded.

method

I return the method used by this computed trace

method_uri

I return the URI of the method used by this computed trace

class ktbs.api.trace.OpportunisticObselCollection(trace)[source]

I implement rdfrest.cores.ICore for obsel collections.

Obsel collections in kTBS can become very big, possibly to the point where a server will refuse to serve the full graph at once. Fortunately, they accept a number of query-string parameters to request only “slices” of the collection.

This implementation retrieves slices of the obsel collection in an opportunistic way (i.e. finding a trade-off between how much the kTBS is willing to provide at a time and what is actually requested by the code using it).

The graph returned by get_state() will always contain all the obsels specified by the parameters passed to it, but possibly more.

factory(uri, rdf_types=None, _no_spawn=False)[source]

I implement cores.ICore.factory().

I simply rely on the factory of my trace.

get_state(parameters=None)[source]

I implement cores.ICore.get_state().

force_state_refresh(parameters=None)[source]

I implement interface.ICore.force_state_refresh.

I simply force a state refresh on my trace.

edit(parameters=None, clear=False, _trust=False)[source]

I implement cores.ICore.edit().

I try to edit the whole graph.

post_graph(graph, parameters=None, _trust=False, _created=None, _rdf_type=None)[source]

I implement cores.ICore.post_graph().

Obsel collection do not support post_graph.

delete(parameters=None, _trust=False)[source]

I implement cores.ICore.delete().

Delegate to proper obsel resource.

state

I implement cores.ICore.get_state().

Obsel API

Inheritance diagram of ktbs.api.obsel

I provide the pythonic interface ktbs:Obsel .

class ktbs.api.obsel.ObselMixin[source]

I provide the pythonic interface of ktbs:Obsel .

get_trace()[source]

I return the trace containing this obsel.

get_obsel_type()[source]

I return the obsel type of this obsel.

get_begin()[source]

I return the begin timestamp of the obsel.

get_begin_dt()[source]

I return the begin timestamp of the obsel.

We use a better implementation than the standard one.

get_end()[source]

I return the end timestamp of the obsel.

get_end_dt()[source]

I return the end timestamp of the obsel.

get_subject()[source]

I return the subject of the obsel.

iter_source_obsels()[source]

I iter over the source obsels of the obsel.

iter_attribute_types()[source]

I iter over all attribute types set for this obsel.

iter_relation_types()[source]

I iter over all outgoing relation types for this obsel.

I iter over all obsels pointed by an outgoing relation.

iter_inverse_relation_types()[source]

I iter over all incoming relation types for this obsel.

iter_relating_obsels(rtype)[source]

I iter over all incoming relation types for this obsel.

get_attribute_value(atype)[source]

I return the value of the given attribut type for this obsel, or None.

attribute_types

Make a list from iter_attribute_types

begin

I return the begin timestamp of the obsel.

begin_dt

I return the begin timestamp of the obsel.

We use a better implementation than the standard one.

end

I return the end timestamp of the obsel.

end_dt

I return the end timestamp of the obsel.

inverse_relation_types

Make a list from iter_inverse_relation_types

list_attribute_types(*args, **kw)

Make a list from iter_attribute_types

list_inverse_relation_types(*args, **kw)

Make a list from iter_inverse_relation_types

Make a list from iter_related_obsels

list_relating_obsels(*args, **kw)

Make a list from iter_relating_obsels

list_relation_types(*args, **kw)

Make a list from iter_relation_types

list_source_obsels(*args, **kw)

Make a list from iter_source_obsels

obsel_type

I return the obsel type of this obsel.

relation_types

Make a list from iter_relation_types

source_obsels

Make a list from iter_source_obsels

subject

I return the subject of the obsel.

trace

I return the trace containing this obsel.

class ktbs.api.obsel.ObselProxy(uri, collection, host_graph, host_parameters)[source]

I provide a lightweight implementation of ktbs:Obsel.

As obsel descriptions can be found in obsel collections, this class provides the Obsel API atop an obsel collection; t

factory(uri, rdf_types=None, _no_spawn=False)[source]

I implement cores.ICore.factory().

I simply rely on the factory of my obsel collection.

get_state(parameters=None)[source]

I implement cores.ICore.get_state().

I simply return

force_state_refresh(parameters=None)[source]

I implement interface.ICore.force_state_refresh.

I simply force a state refresh on my host.

edit(parameters=None, clear=False, _trust=False)[source]

I implement cores.ICore.edit().

If self.host_graph is the complete obsel collection (host_parameters is None), edit it directly; else, try to get “proper” obsel resource and edit it.

Note that the clear argument is not supported in all situations (as host graph may be bigger than the obsel’s state); if you need a clear edit context, you should use a “proper” obsel:

obs = obs.factory(obs.uri)
graph = obs.get_state()

and then ensure that you fill the edit context with what you got from the proper obsel’s state.

post_graph(graph, parameters=None, _trust=False, _created=None, _rdf_type=None)[source]

I implement cores.ICore.post_graph().

Obsels do not support post_graph.

delete(parameters=None, _trust=False)[source]

I implement cores.ICore.delete().

Delegate to proper obsel resource.

Method API

Inheritance diagram of ktbs.api.method

I provide the pythonic interface of ktbs:Method.

class ktbs.api.method.WithParametersMixin[source]

I provide property parameters for both Method and ComputedTrace.

I rely on method _get_inherited_parameters, which must return a (possibly empty) fresh dict.

iter_parameters(include_inherited=True)[source]

I iter over the parameter of this resource.

get_parameter(key)[source]

I return a parameter value.

set_parameter(key, value)[source]

I set a parameter value.

del_parameter(key)[source]

I delete a parameter value.

parameters_as_dict

I return a fresh dict of the parameters of this computed trace.

NB: the keys and values of the dict are unicode. Values are not converted to the datatype expected by the method.

NB: it is assumed that the RDF data is valid, especially that keys are not duplicated.

iter_parameters_with_values(include_inherited=True)[source]

I iter over the parameter of this resource.

list_parameters(*args, **kw)

Make a list from iter_parameters

list_parameters_with_values(*args, **kw)

Make a list from iter_parameters_with_values

parameters

Make a list from iter_parameters

parameters_with_values

Make a list from iter_parameters_with_values

class ktbs.api.method.MethodMixin[source]

I provide the pythonic interface of ktbs:Method.

get_parent()[source]

I return the inherited method.

set_parent(method)[source]

I set the parent method.

get_parent_uri()[source]

I return the URI of the inherited method, if any.

iter_used_by()[source]

I iter over all computed traces using this method

iter_children()[source]

I iter over all children method of this method

children

Make a list from iter_children

list_children(*args, **kw)

Make a list from iter_children

list_used_by(*args, **kw)

Make a list from iter_used_by

parent

I return the inherited method.

parent_uri

I return the URI of the inherited method, if any.

used_by

Make a list from iter_used_by

BuiltinMethod API

Inheritance diagram of ktbs.api.builtin_method

I provide the pythonic interface to kTBS built-in methods.

class ktbs.api.builtin_method.MethodBuiltinMixin[source]

I provide the pythonic interface common to kTBS methods.

get_base()[source]

A built-in method has no base.

get_parent()[source]

A built-in method has no parent.

set_parent(parent)[source]

A built-in method can have no parent.

list_parameters(include_inherited)[source]

A built-in method has no parameter.

get_parameter(key)[source]

A built-in method has no parameters.

set_paremeter(key, value)[source]

A built-in method can have no parameter.

del_parameter(key)[source]

A built-in method has no parameters.

base

A built-in method has no base.

parent

A built-in method has no parent.

TraceObsels API

Inheritance diagram of ktbs.api.trace_obsels

I provide the pythonic interface to kTBS obsel collections.

class ktbs.api.trace_obsels.AbstractTraceObselsMixin[source]

I provide the pythonic interface common to all kTBS obsel collections.

trace

I return the trace owning this obsel collection.

trace_uri

I return the trace owning this obsel collection.

build_select(begin=None, end=None, after=None, before=None, reverse=False, bgp=None, limit=None, offset=None, selected='?obs')[source]

Build a SPARQL query listing the obsels of this trace.

Return type:rdflib.query.Result

NB: the SPARQL query includes no PREFIX definition, in order to be embedable as a subquery, but it requires the prefix ktbs to be declared (bound to the kTBS namespace, of course).

The obsels are sorted by their end timestamp, then their begin timestamp, then their identifier. If reverse is true, the order is inversed.

If given, begin and/or end are interpreted as the (included) boundaries of an interval; only obsels entirely contained in this interval will be yielded.

  • begin: an int, datetime
  • end: an int, datetime
  • after: an obsel, URIRef
  • before: an obsel, URIRef
  • reverse: an object with a truth value
  • bgp: an additional SPARQL Basic Graph Pattern to filter obsels
  • limit: an int
  • selected: the selected variables

In the bgp parameter, notice that:

  • the variable ?obs is bound each obsel
  • the m: prefix is bound to the trace model

NB: the order of “recent” obsels may vary even if the trace is not amended, since collectors are not bound to respect the order in begin timestamps and identifiers.