The Nitty Gritty

 It's time to get down to the "nitty gritties."

The grandiose planning and scheming for the Xpander project [here] is done for now. So next I've got to break down the code into smaller pieces and figure out how to do the logic properly.

First up is the analyzer for the input text. I've got to consider edge cases as well as the assumed general case.

[Note to myself: Use r"/'''"  strings in the dictionaries! QABg ::: python r strings ] [G4G re r strings here] [OTHER prefixed strings here !!]

[Music for reading below boring stuff with is here]

Some of the possible permutations for the input text variable include:
(0) An empty text string;
(1) Only 1 character
        (1a) A received lone char is a P3 or a P4 (no pre-fixed char)
                --what to do?
(2) Only 2 characters:
        (2a) Second one is a P3 or a P4 while first is not = a valid Abv
        (2b) First one is a P3 or a P4 while second is not --see (1a)
        (2c) Both are an exclusive one of P3 or a P4 --see (1a)
        (2d) A mixed pair of either P3 P4  or P4 P3    --execute a script
        (2e) Neither  is a P3 or a P4 = pass it thru the pipe as Out= Out + In

Initial draft: Not very Pythonic -- There must be a better way
SPOILER ALERT ::: I'm going to trash the below thought experiment. It was helpful for understanding the issues but it's a wrong way to approach the problem. Only by going through details did I see what the better way should be. Let's just say I took the wrong road when I got to the fork. Now I have to double back and find an alternate path. Shouldn't punish myself for trying and not immediately finding a solution. (Neuroscience lesson: Don't punish yourself for trying and failing )


def analize_input (self, in_txt):
l = len(in_txt)
if l== 0:
print(f'an empty input string was provided')
analysis = 'null'

elif l== 1:
print(f'a single char input string was provided')
if in_txt == P3:
print(f'a lone P3 was provided')
analysis = 'default P3 trigger'
if in_txt == P4:
print(f'a lone P was provided')
analysis = 'default P4 trigger'

elif l == 2:
print(f'a two char input string was provided')
if in_txt[1] == P3 and (in_txt[0] != P3 and in_txt[0] != P4):
print(f'a valid Abv was provided')
analysis = 'valid lone P3 Abv'
if in_txt[1] == P4 and (in_txt[0] != P3 and in_txt[0] != P4):
print(f'a valid Abv was provided')
analysis = 'valid lone P4 Abv'
if in_txt[0] == P4 and in_txt[1] == P3:
print(f'default P4P3 trigger was provided')
analysis = 'default P4P3 trigger'
if in_txt[0] == P3 and in_txt[1] == P4:
print(f'default P3P4 trigger was provided')
analysis = 'default P3P4 trigger'
if in_txt[0] == P3 and in_txt[1] == P3:
print(f'default P3P3 trigger was provided')
analysis = 'default P3P3 trigger'
if in_txt[0] == P4 and in_txt[1] == P4:
print(f'default P4P4 trigger was provided')
analysis = 'default P4P4 trigger'
return analysis

Let's Make a Truth Table of sorts as shown below:


There are five (5) major permutations:

        (a) Case number 00 = No P3 or P4 has been found in the input text string
              OR the input string is empty.

        (b) Case number 01 = A continuous sequence has been found in the input text
              string that is pure [P3]'s  = one or more, possibly up to 4-12 of them,
              and not preceded or followed by another trigger char (namely [P4])
        (c) Case number 02 = A continuous sequence has been found in the input text
              string that is pure [P4]'s  = one or more, possibly up to 4-12 of them,
              not preceded or followed by another trigger char (namely [P3])
        (d) Case number 11 = A continuous sequence of mixed 
[P3][P4]has been found
                in the input text string that is started by a [P3]
        (e) Case number 12 = A continuous sequence of mixed [P3][P4]has been found
                in the input text string that is started by a [P4]

Sub-cases for 11-12:

        (11a) The mix is preceded by one or more non-trigger chars (ones that are
                    NOT 
[P3] or [P4]) including being preceded by just a white space
        (11b) The mix is NOT preceded by one or more non-trigger chars,
                   it is located at the leading edge of the input string
                    (Possible solution = pretend it was preceded by a space)
        (11c)  
The mix is preceded by one or more non-trigger chars AND
                  additionally it is followed 
by one or more non-trigger chars
        (11d)  The mix is 
NOT additionally followed by one or more non-trigger chars


        (12a)- (12d) = same as (11a)-(11d) except that [P4] is the starter


    TO BE CONTINUED

    MORE TO EXPLORE

QABg ::: Neuroscience lesson: Don't punish yourself for trying and failing
    ^^^-- Reddit take on above is here
QABy ::: Neuroscience lesson: Don't punish yourself for trying and failing
            ^^^-- TED: 
How to overcome your mistakes




xxxx

Comments

Popular posts from this blog

Links for Python Noobs

The Learn HOW to Learn Page

Advanced Python Links Accumulation Page