Utility Methods#
A collection of convenient helper-functions.
-
class
rethon.util.
RethonJSONEncoder
(serialize_implementation=False, **kwargs)# Methods
default
(o)An implemention of
JSONEncoder.default()
.encode
(o)Return a JSON string representation of a Python data structure.
iterencode
(o[, _one_shot])Encode the given object and yield each string representation as available.
-
default
(o)# An implemention of
JSONEncoder.default()
.This implementation handles the serialization of
Position
-,DialecticalStructure
-,REState
- andReflectiveEquilibrium
instances.
-
-
rethon.util.
local_re_model_params_varied_alphas
(alpha_resolution, with_extremes=False)# Model parameters for Local RE with varied alphas.
Convenience method that uses
varied_alphas()
to generate a list of model parameters for the locally searching standard model (seeLocalReflectiveEquilibrium
) as dict. Alphas are varied; all other parameters a set to default (seebasics.ReflectiveEquilibrium
for details about model parameters).- Return type
Iterator
[Dict
]
-
rethon.util.
re_from_text_file
(dir, file_name, re_implementations=[('rethon', 'BitarrayReflectiveEquilibrium')], ds_module_name='tau', ds_class_name='BitarrayDialecticalStructure', position_module_name='tau', position_class_name='BitarrayPosition')# Creates a list of RE classes from a text-file.
The text file consists of a list (i.e. […]) of dictionaries (i.e. {…}) and commented lines used for the description of the example (starting with #). The dictionaries have to contain comma separated entries for the number of unnegated sentences (key: ‘n’, e.g. ‘n’:7) and the arguments (key: ‘arguments’) as a list of lists of numbers (e.g.’arguments’:[[1,-3], [2,3,5]]).
Optionally, the dictionary may contain entries ‘account_penalties’, ‘faithfulness_penalties’ and ‘weights’ if non-standard values should be considered. Finally, an entry of ‘initial_commitments’ may be provided, which is returned as a list of positions in the desired implementation.
A simple schematic example is:
[ # the standard examples (cases A,B,C and D) contain only arguments with one premise. { 'n': 7, 'arguments': [ [1,3], [1,4], [1,5], [1,-6], [2,-4], [2,5], [2,6], [2,7] ], 'initial_commitments': [{3,4,5}, {2,3,4,5}, {3,4,5,6,7}, {3,4,5,-6,7}], 'weights' : {'account': 0.35, 'systematicity': 0.55, 'faithfulness': 0.1}, 'account_penalties' : [0, 0.3, 1, 1], 'faithfulness_penalties' : [0, 0, 1, 1] }, { # some other dialectical structure ... } ]
- Parameters
dir (
str
) – Directory of the text-file.file_name (
str
) – Name of the text-file to be used.re_implementations (
List
[Tuple
[str
,str
]]) – String-representation of the implementation to be used (defined by module- and class name).ds_module_name (
str
) – Modulename of the implementation ofDialecticalStructure
to be used.ds_class_name (
str
) – Classname of the implementation ofDialecticalStructure
to be used.position_module_name (
str
) – Module name of the implementation ofPosition
to be used.position_class_name (
str
) – Class name of the implementation ofPosition
to be used.
- Return type
List
[Tuple
[ReflectiveEquilibrium
,List
[Position
]]]- Returns
List of the form
[(ReflectiveEquilibrium,[Position,Position,...]),(ReflectiveEquilibrium,[Position,Position,...]),...]
with the inner lists ofPosition
possibly beingNone
.
-
rethon.util.
re_weight_variations
(re, initial_commitments, DIR, fileName, resolution=20)# Simulate RE processes with todo
-
rethon.util.
rethon_decoder
(json_obj, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure', reflective_equilibrium_module='rethon', reflective_equilibrium_class='BitarrayReflectiveEquilibrium')# Object hook for
json.loads()
andjson.load()
.- Parameters
use_json_specified_type – If
True
the methods used the implementation details (module name and class name) that are specified in the json string, if there are any. Otherwise, the methode uses implementation details as given by the other parameters.
-
rethon.util.
rethon_dump
(re_object, fp, cls=<class 'rethon.util.RethonJSONEncoder'>, serialize_implementation=False, **kwargs)# Saving an object as JSON-String in a file.
This is a convenient method that calls
json.dump()
withRethonJSONEncoder
as its default encoder, which will handle the JSON serialization ofPosition
-,DialecticalStructure
-,REState
- andReflectiveEquilibrium
instances.**kwargs will be given to
json.dumps()
- Parameters
serialize_implementation – If
True
implementation details (module name and class name) will be serialized.- Returns
The object as a JSON string.
-
rethon.util.
rethon_dumps
(re_object, cls=<class 'rethon.util.RethonJSONEncoder'>, serialize_implementation=False, **kwargs)# Getting an object as JSON-String.
This is a convenient method that calls
json.dumps()
withRethonJSONEncoder
as its default encoder, which will handle the JSON serialization ofPosition
-,DialecticalStructure
-,REState
- andReflectiveEquilibrium
instances.**kwargs will be given to
json.dumps()
- Parameters
serialize_implementation – If
True
implementation details (module name and class name) will be serialized.- Returns
The object as a JSON string.
-
rethon.util.
rethon_load
(fp, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure', reflective_equilibrium_module='rethon', reflective_equilibrium_class='BitarrayReflectiveEquilibrium')# Loading an object from a JSON file.
This is a convenient method that calls
json.load()
and usesrethon_decoder()
as object hook to handle the instantiation ofPosition
-,DialecticalStructure
-,REState
- andReflectiveEquilibrium
objects. Desired implementation details can be given by parameter values (seerethon_decoder()
).
-
rethon.util.
rethon_loads
(json_obj, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure', reflective_equilibrium_module='rethon', reflective_equilibrium_class='BitarrayReflectiveEquilibrium')# Loading an object from a JSON string.
This is a convenient method that calls
json.loads()
and usesrethon_decoder()
as object hook to handle the instantiation ofPosition
-,DialecticalStructure
-,REState
- andReflectiveEquilibrium
objects. Desired implementation details can be given by parameter values (seerethon_decoder()
).
-
rethon.util.
standard_model_params_varied_alphas
(alpha_resolution, with_extremes=False)# Standard model parameters with varied alphas.
Convenience method that uses
varied_alphas()
to generate a list of model parameters for the standard model (seeStandardReflectiveEquilibrium
) as dict. Alphas are varied; all other parameters a set to default (seebasics.ReflectiveEquilibrium
for details about model parameters).- Return type
Iterator
[Dict
]
-
rethon.util.
varied_alphas
(alpha_resolution, with_extremes=False)# A list of alpha values that can be used as model parameters.
- Return type
Iterator
[List
[float
]]