sanskrit_data.schema.common¶
A module containing some data container base classes.
-
class
sanskrit_data.schema.common.
DataSource
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
is_id_impersonated_by_non_admin
(db_interface=None, user=None)[source]¶ A None user is assumed to be a valid authorized backend script.
-
schema
= {'description': 'Source of the json-data which contains this node. Eg. Uploader details in case of books, annotator in case of annotations. Consider naming the field that contains this object `source` to make querying uniform.', 'jsonClass': {'enum': ['DataSource']}, 'properties': {'source_type': {'default': 'system_inferred', 'enum': ['system_inferred', 'user_supplied'], 'type': 'string', 'description': 'Does this data come from a machine, or a human? source_ prefix avoids keyword conflicts in some languages.'}, 'jsonClass': {'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}, 'id': {'type': 'string', 'description': 'Something to identify the particular data source.'}, 'by_admin': {'type': 'boolean', 'description': 'Was the creator of this data an admin at the time it was created or updated?'}}, 'required': ['source_type', 'jsonClass'], 'type': 'object'}¶
-
validate
(db_interface=None, user=None)[source]¶ Validate the JSON serialization of this object using the schema member. Called before database writes.
Parameters: - user –
- db_interface – Potentially useful in subclasses to perform validations (eg. is the target_id valid). This value may not be available: for example when called from the from_details methods.
Returns: a boolean.
-
-
class
sanskrit_data.schema.common.
JsonObject
[source]¶ Bases:
object
The base class of all Json-serializable data container classes, with many utility methods.
-
delete_in_collection
(db_interface, user=None)[source]¶ To delete referrent items also, use appropriate method in JsonObjectNode. :param db_interface: :param user: :return:
-
get_external_storage_path
(db_interface)[source]¶ Get the directory path where files associated with this object are to be stored.
-
classmethod
make_from_dict
(input_dict)[source]¶ Defines our canonical way of constructing a JSON object from a dict.
All other deserialization methods should use this.
Note that this assumes that json_class_index is populated properly!
from sanskrit_data.schema import *
before using this should take care of it.
Parameters: input_dict – Returns: A subclass of JsonObject
-
schema
= {'properties': {'jsonClass': {'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['jsonClass'], 'type': 'object'}¶
-
to_json_map
()[source]¶ One convenient way of ‘serializing’ the object.
So, the type must be properly set. Many functions accept such json maps, just as they accept strings.
-
validate
(db_interface=None, user=None)[source]¶ Validate the JSON serialization of this object using the schema member. Called before database writes.
Parameters: - user –
- db_interface – Potentially useful in subclasses to perform validations (eg. is the target_id valid). This value may not be available: for example when called from the from_details methods.
Returns: a boolean.
-
-
class
sanskrit_data.schema.common.
JsonObjectNode
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
Represents a tree (not a general Directed Acyclic Graph) of UllekhanamJsonObject.
-
delete_in_collection
(db_interface, user=None)[source]¶ To delete referrent items also, use appropriate method in JsonObjectNode. :param db_interface: :param user: :return:
-
recursively_delete_attr
(field_name)[source]¶ Rarely useful method: example when the schema of a Class changes to omit a field.
Limitation: Only useful with direct members.
-
schema
= {'id': 'JsonObjectNode', 'properties': {'content': {'required': ['jsonClass'], 'type': 'object', 'properties': {'jsonClass': {'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}}, 'children': {'items': {'type': 'object', '$ref': 'JsonObjectNode'}, 'type': 'array'}, 'jsonClass': {'enum': ['JsonObjectNode'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['jsonClass'], 'type': 'object'}¶
-
validate
(db_interface=None, user=None)[source]¶ Validate the JSON serialization of this object using the schema member. Called before database writes.
Parameters: - user –
- db_interface – Potentially useful in subclasses to perform validations (eg. is the target_id valid). This value may not be available: for example when called from the from_details methods.
Returns: a boolean.
-
-
class
sanskrit_data.schema.common.
NamedEntity
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
The same name written in different languages have different spellings - oft due to differing case endings and conventions: kAlidAsaH vs Kalidasa. Hence this container.
-
schema
= {'properties': {'names': {'minItems': 1, 'items': {'required': ['jsonClass'], 'type': 'object', 'properties': {'search_strings': {'items': {'type': 'string'}, 'type': 'array', 'description': 'Search strings which should match this text. It could be derived from script_renderings - by a simple copy (intended for use with a text index) or some intelligent tokenization thereof.'}, 'language_code': {'type': 'string'}, 'script_renderings': {'minItems': 1, 'items': {'required': ['text', 'jsonClass'], 'type': 'object', 'properties': {'encoding_scheme': {'type': 'string'}, 'text': {'type': 'string'}, 'jsonClass': {'enum': ['ScriptRendering'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}}, 'type': 'array'}, 'jsonClass': {'enum': ['Text'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}}, 'type': 'array'}, 'jsonClass': {'enum': ['NamedEntity'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['jsonClass'], 'type': 'object'}¶
-
-
class
sanskrit_data.schema.common.
ScriptRendering
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
schema
= {'properties': {'encoding_scheme': {'type': 'string'}, 'text': {'type': 'string'}, 'jsonClass': {'enum': ['ScriptRendering'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['text', 'jsonClass'], 'type': 'object'}¶
-
-
class
sanskrit_data.schema.common.
Target
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
classmethod
check_target_classes
(targets_to_check, db_interface, allowed_types, targeting_obj)[source]¶
-
schema
= {'properties': {'container_id': {'type': 'string'}, 'jsonClass': {'enum': ['Target'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['container_id', 'jsonClass'], 'type': 'object'}¶
-
classmethod
-
exception
sanskrit_data.schema.common.
TargetValidationError
(allowed_types, target_obj, targeting_obj)[source]¶ Bases:
exceptions.Exception
-
class
sanskrit_data.schema.common.
Text
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
schema
= {'properties': {'search_strings': {'items': {'type': 'string'}, 'type': 'array', 'description': 'Search strings which should match this text. It could be derived from script_renderings - by a simple copy (intended for use with a text index) or some intelligent tokenization thereof.'}, 'jsonClass': {'enum': ['Text'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}, 'script_renderings': {'minItems': 1, 'items': {'required': ['text', 'jsonClass'], 'type': 'object', 'properties': {'encoding_scheme': {'type': 'string'}, 'text': {'type': 'string'}, 'jsonClass': {'enum': ['ScriptRendering'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}}, 'type': 'array'}, 'language_code': {'type': 'string'}}, 'required': ['jsonClass'], 'type': 'object'}¶
-
-
class
sanskrit_data.schema.common.
UllekhanamJsonObject
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
The archetype JsonObject for use with the Ullekhanam project. See description.schema field
-
schema
= {'description': 'Some JsonObject which can be saved as a document in the ullekhanam database.', 'properties': {'source': {'properties': {'source_type': {'default': 'system_inferred', 'enum': ['system_inferred', 'user_supplied'], 'type': 'string', 'description': 'Does this data come from a machine, or a human? source_ prefix avoids keyword conflicts in some languages.'}, 'by_admin': {'type': 'boolean', 'description': 'Was the creator of this data an admin at the time it was created or updated?'}, 'id': {'type': 'string', 'description': 'Something to identify the particular data source.'}, 'jsonClass': {'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['source_type', 'jsonClass'], 'type': 'object', 'description': 'Source of the json-data which contains this node. Eg. Uploader details in case of books, annotator in case of annotations. Consider naming the field that contains this object `source` to make querying uniform.', 'jsonClass': {'enum': ['DataSource']}}, 'editable_by_others': {'default': True, 'type': 'boolean', 'description': 'Can this annotation be taken over by others for wiki-style editing or deleting?'}, 'targets': {'items': {'required': ['container_id', 'jsonClass'], 'type': 'object', 'properties': {'container_id': {'type': 'string'}, 'jsonClass': {'enum': ['Target'], 'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}}, 'type': 'array', 'description': 'This field lets us define a directed graph involving JsonObjects stored in a database.'}, 'jsonClass': {'type': 'string', 'description': 'A hint used by json libraries to deserialize json data to an object of the appropriate type. This is necessary for sub-objects to have as well (to ensure that the deserialization functions as expected).'}}, 'required': ['jsonClass'], 'type': 'object'}¶
-
validate
(db_interface=None, user=None)[source]¶ Validate the JSON serialization of this object using the schema member. Called before database writes.
Parameters: - user –
- db_interface – Potentially useful in subclasses to perform validations (eg. is the target_id valid). This value may not be available: for example when called from the from_details methods.
Returns: a boolean.
-
-
sanskrit_data.schema.common.
json_class_index
= {'BookPortion': <class 'sanskrit_data.schema.books.BookPortion'>, 'BookPositionTarget': <class 'sanskrit_data.schema.books.BookPositionTarget'>, 'CreationDetails': <class 'sanskrit_data.schema.books.CreationDetails'>, 'DataSource': <class 'sanskrit_data.schema.common.DataSource'>, 'JsonObject': <class 'sanskrit_data.schema.common.JsonObject'>, 'JsonObjectNode': <class 'sanskrit_data.schema.common.JsonObjectNode'>, 'NamedEntity': <class 'sanskrit_data.schema.common.NamedEntity'>, 'PublicationDetails': <class 'sanskrit_data.schema.books.PublicationDetails'>, 'SchemaError': <class 'jsonschema.exceptions.SchemaError'>, 'ScriptRendering': <class 'sanskrit_data.schema.common.ScriptRendering'>, 'Target': <class 'sanskrit_data.schema.common.Target'>, 'TargetValidationError': <class 'sanskrit_data.schema.common.TargetValidationError'>, 'Text': <class 'sanskrit_data.schema.common.Text'>, 'UllekhanamJsonObject': <class 'sanskrit_data.schema.common.UllekhanamJsonObject'>, 'ValidationError': <class 'jsonschema.exceptions.ValidationError'>}¶ Maps jsonClass values to the containing Python module object. Useful for (de)serialization. Updated using
update_json_class_index()
calls at the end of each module file (such as this one) whose classes may be serialized.