owmeta_core.dataobject_property module

class owmeta_core.dataobject_property.ContextMappedPropertyClass(name, typ, dct)[source]

Bases: MappedClass, ContextualizableClass

Meta-class for Property.

A few attributes can be specified in the class body which affect how the created type is set up: these are defined in the “Attributes” section.

One aspect in particular is important: a Property class can represent a single type of property where all instances have the same URI, or a Property can represent an a class of RDF properties where the instances have distinct URIs and correspond to instances of the RDF type. An instance of the latter is demonstrated with ContainerMembershipProperty.

Attributes
rdf_type_classtype

A sub-class of DataObject to use as the type. If set, this will be used instead of what init_rdf_type_object would create.

rdf_typestr or URIRef

The RDF type for the Property. Must be defined for init_rdf_type_object to actually create the rdf type object

rdf_type_object_deferredbool

If True, defer calling init_rdf_type_object until it’s explicitly called rather than during normal class init. Useful for cases where init_rdf_type_object uses types that aren’t defined at the point where the Property is defined.

rdf_objectRDFProperty

An instance of RDFProperty corresponding to this class. If set, this will be used instead of what init_rdf_object would create.

rdf_object_deferredbool

If True, defer calling init_rdf_object until it is explicitly called rather than during normal class init. Useful for cases where init_rdf_object uses types that aren’t defined at the point where the Property is defined.

contextualize_class_augment(context)[source]

For MappedClass, rdf_type and rdf_namespace have special behavior where they can be auto-generated based on the class name and base_namespace. We have to pass through these values to our “proxy” to avoid this behavior

init_rdf_type_object()[source]

Initializes rdf_type_class and thereby initializes the rdf_type_object

Sometimes, we actually use Property sub-classes as rdf:Property classes (e.g., rdfs:ContainerMembershipProperty). The rdf_type attribute has to be defined on this class if we’re going to use it as an rdf:Property class.

class owmeta_core.dataobject_property.ExprResultObj(expr, ident)[source]

Bases: object

Object returned by PropertyExpr.to_objects. Attributes for which PropertyExpr.to_dict has been called can be accessed on the object. For example we can print out the b properties of instances of a class A:

class B(DataObject):
    v = DatatypeProperty()

class A(DataObject):
    b = ObjectProperty(value_type=B)

a = A().a.expr
a.b.v()
for anA in a.to_objects():
    print(anA.identifier, anA.b)

anA is an ExprResultObj in the example. The

property(property_class)[source]

Return the results object for this sub-expression

Parameters
property_classProperty, Property sub-class, URIRef, or str
property rdf_type

Allias to rdf_type_property

class owmeta_core.dataobject_property.Property(*args, **kwargs)[source]

Bases: DataUser, Contextualizable

A property attached to a DataObject.

clear()[source]

Clears values set in all contexts

contextualize_augment(context)[source]

For MappedClass, rdf_type and rdf_namespace have special behavior where they can be auto-generated based on the class name and base_namespace. We have to pass through these values to our “proxy” to avoid this behavior

get_terms()

Get the Node instances matching this property query

has_defined_value()[source]

Returns True if this property has a value in the current context which is either a GraphObject with defined set to True or a literal value

has_value()[source]

Returns True if there is a value set on this property in the currrent context

one()[source]

Query for a single value from this property.

For a multi-valued property, the returned value is chosen arbitrarily. If there’s no value returned from the query, then None is returned.

onedef()[source]

Return a single defined value set on this property in the current context

This does not execute a query, but returns a value which was set on this property.

set(v)[source]

Set the value for or add a value to this property

unset(v)

Remove a from this property

property defined_values

The “defined” values set on this property in the current context

property expr

An query expression from this property

property identifier

Alias to link

lazy = True

If True, then the property is not attached to an instance until the property is set or queried.

multiple = False

If True, then the property will only maintain a single staged value at a time. No effort is made to check how many values are stored in the RDF graph.

property values

Return all values set on this property in the current context

class owmeta_core.dataobject_property.PropertyExpr(props, triples_provider=None, terms_provider=None, origin=None)[source]

Bases: object

A property expression

property(property_class)[source]

Create a sub-expression with the given property.

Allows for creating expressions with properties that are not necessarily declared for the value_type of this expression’s property

to_dict(multiple=False)[source]

Return a dict mapping from identifiers for subjects of this expression’s property to the objects for that property.

Parameters
multiplebool, optional

If False, then only a single object is allowed for each subject in the results. An exception is raised if more than one object is found for a given subject.

to_objects()[source]

Returns a list of ExprResultObj that allow for retrieving results in a convenient attribute traversal

to_terms()[source]

Return a list of rdflib.term.Node terms produced by this expression.

property rdf_type

Short-hand for rdf_type_property