genericize chain remover to use it for bridge and addressed chains

This commit is contained in:
Brian S. Stephan 2023-02-19 13:08:26 -06:00
parent 19cd23879f
commit 76a052e091
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
1 changed files with 52 additions and 44 deletions

View File

@ -15,8 +15,16 @@ class Command(BaseCommand):
for context in markov_contexts:
self.stdout.write(self.style.NOTICE(f"scanning context {context}..."))
# get starting states that look like they came over the bridge
start_states = context.states.filter(k1=MarkovState._start1, k2=MarkovState._start2,
bridge_states = context.states.filter(k1=MarkovState._start1, k2=MarkovState._start2,
v__regex=r'<.*>')
self._chain_remover(context, bridge_states)
def _chain_remover(self, context, start_states):
"""Remove a given k from markov states, deleting the found states after rebuilding subsequent states.
As in, if trying to remove A,B -> X, then B,X -> C and X,C -> D must be rebuilt (A,B -> C / B,C -> D)
then the three states with X deleted.
"""
for start_state in start_states:
self.stdout.write(self.style.NOTICE(f" diving into {start_state}..."))
# find the states that build off of the start