Descriptor Similarity Service¶
Provides a web-accessible API for computing content descriptor vectors for available descriptor generator labels.
Descriptor generators that are available to the service are based on the a configuration file provided to the server.
-
class
smqtk.web.descriptor_service.
DescriptorServiceServer
(json_config)[source]¶ Simple server that takes in a specification of the following form:
/<descriptor_type>/<uri>[?…]
See the docstring for the
DescriptorServiceServer.compute_descriptor()
method for complete rules on how to form a calling URL.Computes the requested descriptor for the given file and returns that via a JSON structure.
Standard return JSON:
{ "success": <bool>, "descriptor": [ <float>, ... ] "message": <string>, "reference_uri": <uri> }
Additional Configuration
Note
We will look for an environment variable DescriptorService_CONFIG for a string file path to an additional JSON configuration file to consider.
-
generate_descriptor
(de, cd_label)[source]¶ Generate a descriptor for the content pointed to by the given URI using the specified descriptor generator.
- Raises
ValueError – Content type mismatch given the descriptor generator
RuntimeError – Descriptor extraction failure.
- Returns
Generated descriptor element instance with vector information.
- Return type
-
generator_label_configs
¶ - Type
dict[str, dict]
-
get_config
()[source]¶ Return a JSON-compliant dictionary that could be passed to this class’s
from_config
method to produce an instance with identical configuration.In the most cases, this involves naming the keys of the dictionary based on the initialization argument names as if it were to be passed to the constructor via dictionary expansion. In some cases, where it doesn’t make sense to store some object constructor parameters are expected to be supplied at as configuration values (i.e. must be supplied at runtime), this method’s returned dictionary may leave those parameters out. In such cases, the object’s
from_config
class-method would also take additional positional arguments to fill in for the parameters that this returned configuration lacks.- Returns
JSON type compliant configuration dictionary.
- Return type
dict
-
classmethod
get_default_config
()[source]¶ Generate and return a default configuration dictionary for this class. This will be primarily used for generating what the configuration dictionary would look like for this class without instantiating it.
- Returns
Default configuration dictionary for the class.
- Return type
dict
-
get_descriptor_inst
(label)[source]¶ Get the cached content descriptor instance for a configuration label :type label: str :rtype: smqtk.algorithms.descriptor_generator.DescriptorGenerator
-
classmethod
is_usable
()[source]¶ Check whether this class is available for use.
Since certain plugin implementations may require additional dependencies that may not yet be available on the system, or other runtime conditions, this method may be overridden to check for those and return a boolean saying if the implementation is available for usable. When this method returns True, the class is declaring that it should be constructable and usable in the current environment.
By default, this method will return True unless a sub-class overrides this class-method with their specific logic.
- NOTES:
This should be a class method
- When an implementation is deemed not usable, this should emit a
(user) warning, or some other kind of logging, detailing why the implementation is not available for use.
- Returns
Boolean determination of whether this implementation is usable in the current environment.
- Return type
bool
-
resolve_data_element
(uri)[source]¶ Given the URI to some data, resolve it down to a DataElement instance.
- Raises
ValueError – Issue with the given URI regarding either URI source resolution or data resolution.
- Parameters
uri (str) – URI to data
- Returns
DataElement instance wrapping given URI to data.
- Return type
-