owmeta_core.dataobject module

exception owmeta_core.dataobject.ClassResolutionFailed[source]

Bases: Exception

Thrown when a PythonClassDescription can’t resolve its class

exception owmeta_core.dataobject.ModuleResolutionFailed[source]

Bases: Exception

Thrown when a PythonModule can’t resolve its module

class owmeta_core.dataobject.Alias(target)[source]

Bases: object

Used to declare that a descriptor is an alias to some other Property

Example usage:

class Person(DataObject):
    child = DatatypeProperty()
    offspring = Alias(child)
Parameters
targetdataobject_property.Property

The property to alias

class owmeta_core.dataobject.BaseDataObject(*args, no_type_decl=False, **kwargs)[source]

Bases: IdMixin, GraphObject, ContextualizableDataUserMixin

An object which can be mapped to an RDF graph

Attributes
rdf_typerdflib.term.URIRef

The RDF type URI for objects of this type

rdf_namespacerdflib.namespace.Namespace

The rdflib namespace (prefix for URIs) for instances of this class

schema_namespacerdflib.namespace.Namespace

The rdflib namespace (prefix for URIs) for types that are part of this class’ schema

propertieslist of owmeta_core.dataobject_property.Property or owmeta_core.custom_dataobject_property.CustomProperty

Properties belonging to this object

owner_propertieslist of owmeta_core.dataobject_property.Property or owmeta_core.custom_dataobject_property.CustomProperty

Properties belonging to parents of this object

properties_are_init_argsbool

If true, then properties defined in the class body can be passed as keyword arguments to __init__. For example:

>>> class A(DataObject):
...     p = DatatypeProperty()

>>> A(p=5)

If the arguments are written explicitly into the __init__ method definition, then no special processing is done.

classmethod DatatypeProperty(*args, **kwargs)[source]

Attach a, possibly new, property to this class that has a simple type (string, number, etc) for its values

Parameters
linkNamestr

The name of this property.

ownerowmeta_core.dataobject.BaseDataObject

The owner of this property.

classmethod ObjectProperty(*args, **kwargs)[source]

Attach a, possibly new, property to this class that has a BaseDataObject for its values

Parameters
linkNamestr

The name of this property.

ownerowmeta_core.dataobject.BaseDataObject

The owner of this property.

value_typetype

The type of BaseDataObject for values of this property

classmethod UnionProperty(*args, **kwargs)[source]

Attach a, possibly new, property to this class that has a simple type (string,number,etc) or BaseDataObject for its values

Parameters
linkNamestr

The name of this property.

ownerowmeta_core.dataobject.BaseDataObject

The owner of this property.

attach_property(prop_cls, name=None, ephemeral=False, **kwargs)[source]
Parameters
prop_clstype

The property class to attach to this dataobject

namestr, optional

The name to use for attaching to this dataobject

ephemeralbool, optional

If True, the property will not be set as an attribute on the object

**kwargs

Arguments to pass to the initializer of the property class

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_owners(property_class_name)[source]

Return a generator of owners along a property pointing to this object

graph_pattern(shorten=False, show_namespaces=True, **kwargs)[source]

Get the graph pattern for this object.

It should be as simple as converting the result of triples() into a BGP

Parameters
shortenbool

Indicates whether to shorten the URLs with the namespace manager attached to the self

hashfun()

Returns a md5 hash object; optionally initialized with a string

id_is_variable()[source]

Is the identifier a variable?

load(graph=None)[source]

Loads DataObjects by matching between the object graph and the RDF graph

Parameters
graphrdflib.graph.ConjunctiveGraph

the RDF graph to load from

load_one(graph=None)[source]

Load a single DataObject

load_terms(graph=None)[source]

Loads URIs by matching between the object graph and the RDF graph

Parameters
graphrdflib.graph.ConjunctiveGraph

the RDF graph to load from

make_key_from_properties(names)[source]

Creates key from properties

retract()[source]

Remove this object from the data store.

save()[source]

Write in-memory data to the database. Derived classes should call this to update the store.

property expr

Create a query expression rooted at this object

property rdf

Returns either the configured RDF graph or the Context.rdf_graph of its context

property rdfs_comment

Corresponds to the rdfs:comment predicate

property rdfs_label

Corresponds to the rdfs:label predicate

property rdfs_member

Corresponds to the rdfs:member predicate

class owmeta_core.dataobject.ClassDescription(*args, no_type_decl=False, **kwargs)[source]

Bases: DataObject

Describes a class in the programming language.

Note that, in other languages, there may not actually be classes per se. In such cases, the ClassDescription may instead indicate a function. The conventions for how that function accepts a URI for the sake of creating an “instance” of is up to the associated software module.

property module

The module the class belongs to

class owmeta_core.dataobject.ContextMappedClass(name, typ, dct)[source]

Bases: MappedClass, ContextualizableClass

The metaclass for a BaseDataObject.

augment_rdf_type_object(rdf_type_object)[source]

Runs after initialization of the rdf_type_object

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

property definition_context

Unlike self.context, definition_context isn’t meant to be overriden

property query

Creates a proxy that changes how some things behave for purposes of querying

class owmeta_core.dataobject.ContextualizableList(*args, **kwargs)[source]

Bases: Contextualizable, list

A Contextualizable list

class owmeta_core.dataobject.DataObject(*args, no_type_decl=False, **kwargs)[source]

Bases: BaseDataObject

An object that can be mapped to an RDF graph

class owmeta_core.dataobject.Module(*args, no_type_decl=False, **kwargs)[source]

Bases: DataObject

Represents a module of code

Most modern programming languages organize code into importable modules of one kind or another. This is basically the nearest level above a class in the language.

Modules are accessible by one or more ModuleAccessor

property accessor

Describes a way to get the module

property package

Package that provides the module

class owmeta_core.dataobject.ModuleAccessor(*args, no_type_decl=False, **kwargs)[source]

Bases: DataObject

Describes how to access a module.

Module access is how a person or automated system brings the module to where it can be imported/included, possibly in a subsequent

help_str()[source]

Format a string to show how to access the module by installing it or requiring it or whatever.

Default implementation just returns an empty string

class owmeta_core.dataobject.OptionalKeyValue(prop)[source]

Bases: object

An optional key value to use in key_properties

class owmeta_core.dataobject.PIPInstall(*args, no_type_decl=False, **kwargs)[source]

Bases: ModuleAccessor

Describes a pip install command line

property index_url

URL of the index from which the package should be retrieved

class owmeta_core.dataobject.Package(*args, no_type_decl=False, **kwargs)[source]

Bases: DataObject

Describes an idealized software package identifiable by a name and version number

property name

The standard name of the package

property version

The version of the package

class owmeta_core.dataobject.PythonClassDescription(*args, no_type_decl=False, **kwargs)[source]

Bases: ClassDescription

Description for a Python class

resolve_class()[source]

Load the class described by this object

Returns
type

The class described by this object

Raises
ClassResolutionFailed

Raised if the class can’t be resolved for whatever reason

property module

The module the class belongs to

property name

Local name of the class (i.e., relative to the module name)

class owmeta_core.dataobject.PythonModule(*args, no_type_decl=False, **kwargs)[source]

Bases: Module

A Python module

resolve_module()[source]

Load the module referenced by this object

Returns
types.ModuleType

The module referenced by this object

Raises
ModuleResolutionFailed

Raised if the class can’t be resolved for whatever reason

property name

The full name of the module

class owmeta_core.dataobject.PythonPackage(*args, no_type_decl=False, **kwargs)[source]

Bases: Package

A Python package

class owmeta_core.dataobject.RDFProperty(*args, no_type_decl=False, **kwargs)[source]

Bases: BaseDataObject

The DataObject corresponding to rdf:Property

property rdfs_subpropertyof

Corresponds to the rdfs:subPropertyOf predidcate

class owmeta_core.dataobject.RDFSClass(*args, no_type_decl=False, **kwargs)[source]

Bases: BaseDataObject

The GraphObject corresponding to rdfs:Class

property rdfs_subclassof_property

Corresponds to the rdfs:subClassOf predidcate

class owmeta_core.dataobject.RDFSCommentProperty(*args, **kwargs)[source]

Bases: DatatypeProperty

Corresponds to the rdfs:comment predicate

Parameters
resolverRDFTypeResolver

Resolves RDF identifiers returned from get() into objects

owner_type

alias of BaseDataObject

class owmeta_core.dataobject.RDFSLabelProperty(*args, **kwargs)[source]

Bases: DatatypeProperty

Corresponds to the rdfs:label predicate

Parameters
resolverRDFTypeResolver

Resolves RDF identifiers returned from get() into objects

owner_type

alias of BaseDataObject

class owmeta_core.dataobject.RDFSMemberProperty(*args, **kwargs)[source]

Bases: UnionProperty

Corresponds to the rdfs:member predicate

Parameters
resolverRDFTypeResolver

Resolves RDF identifiers into objects returned from get()

owner_type

alias of BaseDataObject

class owmeta_core.dataobject.RDFSSubClassOfProperty(*args, **kwargs)[source]

Bases: ObjectProperty

Corresponds to the rdfs:subClassOf predidcate

owner_type

alias of RDFSClass

value_type

alias of RDFSClass

class owmeta_core.dataobject.RDFSSubPropertyOfProperty(*args, **kwargs)[source]

Bases: ObjectProperty

Corresponds to the rdfs:subPropertyOf predidcate

owner_type

alias of RDFProperty

value_type

alias of RDFProperty

class owmeta_core.dataobject.RDFTypeProperty(*args, **kwargs)[source]

Bases: ObjectProperty

Corresponds to the rdf:type predidcate

owner_type

alias of BaseDataObject

class owmeta_core.dataobject.RegistryEntry(*args, no_type_decl=False, **kwargs)[source]

Bases: DataObject

A mapping from a class in the programming language to an RDF class.

Objects of this type are utilized in the resolution of classes from the RDF graph

property class_description

The description of the class

property rdf_class

The RDF type for the class

We use rdf_type for the type of a DataObject (RegistryEntry.rdf_type in this case), so we call this rdf_class to avoid the conflict

owmeta_core.dataobject.DatatypeProperty(*args, **kwargs)[source]

Used in a DataObject implementation to designate a property whose values are not DataObjects.

An example DatatypeProperty use:

class Person(DataObject):
    name = DatatypeProperty()
    age = DatatypeProperty()

Person(name='Abioye', age=34)
owmeta_core.dataobject.ObjectProperty(*args, **kwargs)[source]

Used in a DataObject implementation to designate a property whose values are other DataObjects.

An example ObjectProperty use:

class Person(DataObject):
    name = DatatypeProperty()
    friend = ObjectProperty()

Person(name='Abioye', friend=Person(name='Baako'))
owmeta_core.dataobject.UnionProperty(*args, **kwargs)[source]

Used in a DataObject implementation to designate a property whose values are either other DataObjects or literals (e.g., str, int).

An example UnionProperty use:

class Address(DataObject):
    street = DatatypeProperty()
    number = DatatypeProperty()
    city = DatatypeProperty()
    state = DatatypeProperty()
    zip = DatatypeProperty()

class Person(DataObject):
    name = DatatypeProperty()
    address = UnionProperty()

Person(name='Umoja', address='38 West 88th Street, Manhattan NY 10024 , New York, USA')
Person(name='Umoja', address=Address(number=38,
                                     street='West 88th Street',
                                     city='New York',
                                     state='NY',
                                     zip=10024))
owmeta_core.dataobject.DATAOBJECT_PROPERTY_NAME_PREFIX = '_owm_'

Prefix for property attribute names

owmeta_core.dataobject.This = <object object>

A reference to be used in class-level property declarations to denote the class currently being defined. For example:

>>> class Person(DataObject):
...     parent = ObjectProperty(value_type=This,
...                             inverse_of=(This, 'child'))
...     child = ObjectProperty(value_type=This)