# Constraint¶

class jwst.associations.lib.constraint.Constraint(init=None, reduce=None, name=None, reprocess_on_match=False, reprocess_on_fail=False, work_over=1, reprocess_rules=None)[source]

Bases: object

Constraint that is made up of SimpleConstraint

Parameters
• init (object or [object[,..]]) – A single object or list of objects where the objects are as follows. - SimpleConstraint or subclass - Constraint

• reduce (function) – A reduction function with signature x(iterable) where iterable is the components list. Returns boolean indicating state of the components. Default value is Constraint.all

• name (str or None) – Optional name for constraint.

• reprocess_on_match (bool) – Reprocess the item if the constraint is satisfied.

• reprocess_on_fail (bool) – Reprocess the item if the constraint is not satisfied.

• work_over (ProcessList.[BOTH, EXISTING, RULES]) – The condition on which this constraint should operate.

• reprocess_rules ([rule[,.]] or None) – List of rules to be applied to. If None, calling function will determine the ruleset. If empty, [], all rules will be used.

constraints

List of Constraint or SimpleConstaint that make this constraint.

Type

[Constraint[,..]]

matched

Result of the last check_and_set

Type

bool

reduce

A reduction function with signature x(iterable) where iterable is the components list. Returns boolean indicating state of the components. Predefined functions are: - all: True if all components return True - any: True if any component returns True

Type

function

Notes

Named constraints can be accessed directly through indexing:

>>> c = Constraint(SimpleConstraint(name='simple', value='a_value'))
>>> c['simple']
SimpleConstraint({'sources': <function SimpleConstraint.__init__.<locals>.<lambda> at 0x7f8be05f5730>,
'force_unique': True,
'test': <bound method SimpleConstraint.eq of SimpleConstraint({...})>,
'reprocess_on_match': False,
'reprocess_on_fail': False,
'work_over': 1,
'reprocess_rules': None,
'value': 'a_value',
'name': 'simple',
'matched': False})


Methods Summary

 all(item, constraints) Return positive only if all results are positive. any(item, constraints) Return the first successful constraint. append(constraint) Append a new constraint check_and_set(item[, work_over]) Check and set the constraint Copy ourselves notany(item, constraints) True if none of the constraints match

Methods Documentation

static all(item, constraints)[source]

Return positive only if all results are positive.

static any(item, constraints)[source]

Return the first successful constraint.

append(constraint)[source]

Append a new constraint

check_and_set(item, work_over=1)[source]

Check and set the constraint

Returns

success, reprocess

Returns 2-tuple of

• success : True if check is successful.

• List of ProcessList.

Return type

bool, [ProcessList[,..]]

copy()[source]

Copy ourselves

static notany(item, constraints)[source]

True if none of the constraints match
{"ft_lang_label":"__label__en","ft_lang_prob":0.5351857,"math_prob":0.7398425,"size":2552,"snap":"2020-34-2020-40","text_gpt3_token_len":625,"char_repetition_ratio":0.18092622,"word_repetition_ratio":0.11464968,"special_character_ratio":0.23393416,"punctuation_ratio":0.20689656,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95624197,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-13T09:36:07Z\",\"WARC-Record-ID\":\"<urn:uuid:9a8d170f-530c-4388-8789-1177b7b284eb>\",\"Content-Length\":\"35206\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6bdcab90-2f3e-49f6-b3d9-61f5bec8573b>\",\"WARC-Concurrent-To\":\"<urn:uuid:4afe6f06-4274-4058-91d2-ae49e875128a>\",\"WARC-IP-Address\":\"104.17.32.82\",\"WARC-Target-URI\":\"https://jwst-pipeline.readthedocs.io/en/latest/api/jwst.associations.lib.constraint.Constraint.html\",\"WARC-Payload-Digest\":\"sha1:7B2IV5EUSOMK7RZKXITVNERZOAWGWPUI\",\"WARC-Block-Digest\":\"sha1:KQOVYIHNWDS6PZHKDCABUWJCB2TDZ3G4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439738964.20_warc_CC-MAIN-20200813073451-20200813103451-00275.warc.gz\"}"}