Utility Methods#
A collection of convenient helper-functions.
-
class
tau.util.
TauJSONEncoder
(serialize_implementation=False, **kwargs)# Methods
default
(o)An implementation 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 implementation of
JSONEncoder.default()
.This implementation handles the serialization of
Position
andDialecticalStructure
instances.
-
-
tau.util.
arg_to_cnf
(arg)# Converts list representation of an argument to a cnf-position-like list of negated premises + non-negated conclusion
- Parameters
arg (List[int]) –
-
tau.util.
args2cnf
(arguments, n_sentence_pool)# Converting argument list to
pysat.formula.CNF
This method converts a list of arguments into a conjunctive normal form. Sentences \(p\) that are not used in arguments will be added in a tautological manner (i.e., \(p\vee\neg p\)) to the CNF formula.
- Return type
CNF
- Parameters
arguments (List[List[int]]) –
n_sentence_pool (int) –
-
tau.util.
create_random_argument_list
(n_arguments_min, n_arguments_max, n_sentences, n_premises_max)# A random list of arguments.
A convenience function that uses
create_random_arguments2()
to create a random list of arguments. Instead of specifying a fixed number of desired arguments the number of arguments will be a random number between n_arguments_min and ` n_arguments_max`.- Return type
List
[List
[int
]]- Parameters
n_arguments_min (int) –
n_arguments_max (int) –
n_sentences (int) –
n_premises_max (int) –
-
tau.util.
create_random_arguments
(n_sentences, n_arguments, n_max_premises, n_principles=0, variation=True, connected=True, use_all_sentences=False, max_loops=1000)# Returns a list of arguments represented as integer lists.
The dialectical structure given by the returned arguments is satisfiable (i.e. there is at least one complete and dialectically consistent position). Furthermore, the arguments avoid begging the question, repeating premises, flat contradictions among premises and with the conclusion, and using the same premises for different conclusions.
- Parameters
n_sentences (int) – Number of non-negated sentences of the sentence pool. Every sentence (or its negation) occurs at least once in an argument.
n_arguments (int) – Number of generated arguments.
n_max_premises (int) – Maximal number of premises per argument.
n_principles (int) – The number of principles, i.e. sentences that may occur in arguments as premises only.
variation (bool) – If true (default), the number of premises per argument is chosen randomly. Otherwise it is constantly n_max_premises.
connected (bool) – If true (default), the arguments are related (either by attack or support) to at least one other argument in the structure.
use_all_sentences (bool) – If true, the algorithm returns only dialectical structures that include each sentence ,or its negation respectively, in the arguments. If the algorithm is not able to generate such a structure in the limits given by
max_loops
, a RuntimeWarning is thrown.max_loops (int) – Breaks possibly endless loops. Number of arguments that tested whether they fit into the dialectical structure. If the algorithm takes longer a RuntimeWarning is thrown.
- Returns
A list of argument as integer lists.
- Return type
List[List[int]]
- Return type
List
[List
[int
]]
-
tau.util.
get_principles
(arguments)# ” Returns a list of tuples of the form
(principle, multiplicity)
withmultiplicity
indicating the multiplicity of the principle. A sentence counts as a principle iff it occurs in at least one argument as premise and it or its negation does not occur as a conclusion in an argument. The multiplicity counts in how many argument the sentence occurs as premise.
-
tau.util.
inferential_density
(dialectical_structure)# Inferential density of a dialectical structure.
As defined by Betz (2013), p. 44: todo
-
tau.util.
is_satisfiable
(args, principles=None)# Fast method of checking for satisfiability (using xxx).
- Parameters
args (List[List[int]]) –
principles (Optional[List[int]]) –
-
tau.util.
load_dialectical_structure
(DIR, fileName)# ToDo: doc
-
tau.util.
number_of_complete_consistent_positions
(args, n_unnegated_sentence_pool)# Fast method to calculate the number of complete consistent positions.
- Return type
int
- Parameters
args (List[List[int]]) –
n_unnegated_sentence_pool (int) –
-
tau.util.
random_dialectical_structures
(n_dialectical_structure, n_arguments_min, n_arguments_max, n_sentences, n_premises_max, module_name='rethon.model', class_name='DAGDialecticalStructure')# A random list of dialectical structures.
A convenience function that uses
create_random_argument_list()
to create an instance ofbasics.DialecticalStructure
.- Returns
A random dialectical structure. The implementing class can be specified via the method’s arguments.
- Return type
Iterator[tau.base.DialecticalStructure]
- Return type
Iterator
[DialecticalStructure
]
-
tau.util.
random_position_as_set
(n_sentences, allow_empty_position=False)# Generates a random minimally consistent position in its set-representation.
- Parameters
n_sentences (int) – Size of the sentence-pool (without negations).
allow_empty_position (bool) – Iff
True
an empty position might be returned.
- Returns
A set of integer representing the position.
-
tau.util.
random_positions
(n_positions, n_sentences, position_module_name='rethon.model', position_class_name='StandardPosition')# List of random positions.
Convenience method that uses
random_position_as_set()
to generate a list of positions. The implementing class can be specified via arguments.- Return type
Iterator
[Position
]
-
tau.util.
save_dialectical_structure
(DIR, fileName, dialectical_structure)# ToDo: doc
-
tau.util.
tau_decoder
(json_obj, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure')# Object hook for
json.loads()
andjson.load()
.- Parameters
use_json_specified_type – If
True
the method uses the implementation details (modulename and classname) that are specified in the json string, if there are any. Otherwise, the method uses implementation details as specified the other given parameters.
-
tau.util.
tau_dump
(re_object, fp, cls=<class 'tau.util.TauJSONEncoder'>, serialize_implementation=False, **kwargs)# Saving an object as JSON-String in a file.
This is a convenient method that calls
json.dump()
withTauJSONEncoder
as its default encoder, which will handle the JSON serialization ofPosition
andDialecticalStructure
instances.**kwargs will be given to
json.dumps()
- Parameters
serialize_implementation – If
True
implementation details (modulename and classname) will be serialized.- Returns
The object as a JSON string.
-
tau.util.
tau_dumps
(re_object, cls=<class 'tau.util.TauJSONEncoder'>, serialize_implementation=False, **kwargs)# Getting an object as JSON-String.
This is a convenient method that calls
json.dumps()
withTauJSONEncoder
as its default encoder, which will handle the JSON serialization ofPosition
andDialecticalStructure
.**kwargs will be given to
json.dumps()
- Parameters
serialize_implementation – If
True
implementation details (modulename and classname) will be serialized.- Returns
The object as a JSON string.
-
tau.util.
tau_load
(fp, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure')# Loading an object from a JSON file.
This is a convenient method that calls
json.load()
and usestau_decoder()
as object hook to handle the instantiation ofPosition
andDialecticalStructure
objects. Desired implementation details can be given by parameter values (seetau_decoder()
).
-
tau.util.
tau_loads
(json_obj, use_json_specified_type=False, position_module='tau', position_class='BitarrayPosition', dialectical_structure_module='tau', dialectical_structure_class='BitarrayDialecticalStructure')# Loading an object from a JSON string.
This is a convenient method that calls
json.loads()
and usestau_decoder()
as object hook to handle the instantiation ofPosition
andDialecticalStructure
objects. Desired implementation details can be given by parameter values (seetau_decoder()
).
-
tau.util.
write_as_dot
(directory, fileName, arg_list, equal_rank_for_principles=False)# ToDo: doc
-
tau.util.
write_as_tex
(directory, fileName, arg_list)# ToDo: doca