sequence function: smap

    description:
        smap(min_size, max_size, operators) input-seq
        the sequence map operator
        The input sequence is broken into pieces/ngrams of len min_size to max_size
        then the operators defined by 'operators' is then applied to each piece

    examples:
        -- just an abstract test to verify smap() is working as desired:
        smerge-dot (*) #=> smerge[" . "] |_self>
        smerge-under (*) #=> smerge[" _ "] |_self>
        long-display smap(|2>, |4>, |op: smerge-dot> + |op: smerge-under>) ssplit |abcdef>


        -- another test, this time to print out the sequences handed to the specified operator:
        bracket (*) #=> |[> _ smerge[", "] |_self> _ |]>
        print-bracket (*) #=> print bracket |_self>
        smap(|2>, |4>, |op: print-bracket>) ssplit |abcdef>
            []
            [a, b]
            [b, c]
            [c, d]
            [d, e]
            [e, f]
            []
            []
            [a, b, c]
            [b, c, d]
            [c, d, e]
            [d, e, f]
            []
            []
            []
            [a, b, c, d]
            [b, c, d, e]
            [c, d, e, f]        

        -- active reading example:
        -- first define background knowledge, defined through if-then machines
        -- then read a couple of sample sentences
        pattern |node: 1: 1> => |Hello>
        then |node: 1: *> => |greeting: hello>
        
        pattern |node: 2: 1> => |Fred> . |Smith>
        then |node: 2: *> => |person: Fred Smith>
        
        pattern |node: 3: 1> => ssplit[" "] |how are you?>
        then |node: 3: *> => |phrase question: how are you>
                
        pattern |node: 4: 1> => ssplit[" "] |university of Adelaide>
        pattern |node: 4: 2> => ssplit[" "] |University of Adelaide>
        pattern |node: 4: 3> => |Adelaide> . |uni>
        then |node: 4: *> => |university: Adelaide>
        
        pattern |node: 5: 1> => |Adelaide>
        then |node: 5: *> => |Australia: city: Adelaide> + |UK: queen: Adelaide>
        
        pattern |node: 6: 1> => |river> . |Torrens>
        pattern |node: 6: 2> => |the> . |Torrens>
        pattern |node: 6: 3> => |Torrens> . |river>
        then |node: 6: *> => |South Australia: river: Torrens>
        
        pattern |node: 7: 1> => |South> . |Australia>
        pattern |node: 7: 2> => |SA>
        then |node: 7: *> => |Australia: state: South Australia>
        
        pattern |node: 8: 1> => |university>
        pattern |node: 8: 2> => |Univeristy>
        pattern |node: 8: 3> => |uni>
        then |node: 8: *> => |place of study: university>


        -- define our required operators:
        -- depending on what you are doing, you might want to increase drop-below threshold to say 0.97, or lower it.
        -- and you might want to make the max ngrams bigger than 3.        
        sim-pattern (*) #=> then drop-below[0.7] similar-input[pattern] |_self>
        read-sentence |*> #=> smap(|1>, |3>, |op: sim-pattern>) ssplit[" "] |_self>
        
        -- now read simple sentences:
        read-sentence |Hello Fred Smith how are you?>
            |greeting: hello> . |> . |person: Fred Smith> . |> . |> . |phrase question: how are you>

        long-display read-sentence |The university of Adelaide is located next to the beautiful river Torrens in Adelaide South Australia>
            seq |0> => |>
            seq |1> => |place of study: university>
            seq |2> => |>
            seq |3> => |Australia: city: Adelaide> + |UK: queen: Adelaide> + |university: Adelaide>
            seq |4> => |>
            seq |5> => |>
            seq |6> => |>
            seq |7> => |>
            seq |8> => |>
            seq |9> => |>
            seq |10> => |>
            seq |11> => |South Australia: river: Torrens>
            seq |12> => |>
            seq |13> => |Australia: city: Adelaide> + |UK: queen: Adelaide>
            seq |14> => |>
            seq |15> => |Australia: state: South Australia>

        long-display read-sentence |Adelaide uni is next to the Torrens in SA>
            seq |0> => |Australia: city: Adelaide> + |UK: queen: Adelaide>
            seq |1> => |place of study: university> + |university: Adelaide>
            seq |2> => |>
            seq |3> => |>
            seq |4> => |>
            seq |5> => |>
            seq |6> => |South Australia: river: Torrens>
            seq |7> => |>
            seq |8> => |Australia: state: South Australia>


        -- using it for a simple spell-check operator:
        -- first load a dictionary, eg:
        -- web-load http://semantic-db.org/sw-examples/small-english-dictionary.sw
        -- web-load http://semantic-db.org/sw-examples/moby-dictionary.sw

        -- define the required operators:
        seq2sp-op (*) #=> seq2sp |_self>
        spelling-encoder |*> #=> smap(|1>, |3>, |op: seq2sp-op>) ssplit |_self>
        spell-check |*> #=> select[1,10] similar-input[encoded-spelling] spelling-encoder |_self>
        
        -- learn the encoded spelling patterns:
        |null> => map[spelling-encoder, encoded-spelling] rel-kets[spelling] |>
        
        -- now use the spell-check operator:
        bar-chart[10] spell-check |heirarchy>
            ----------
            hierarchy    : ||||||||||
            hierarchical : |||||||
            oligarchy    : ||||||
            heirloom     : |||||
            hesitancy    : |||||
            headache     : |||||
            heirs        : |||||
            research     : |||||
            overarching  : |||||
            oligarch     : |||||
            ----------

        bar-chart[10] spell-check |recieve>
            ----------
            relieve  : ||||||||||
            receive  : |||||||||
            recipe   : ||||||||
            recite   : ||||||||
            recover  : ||||||||
            recital  : |||||||
            recline  : |||||||
            receipt  : |||||||
            reviewer : |||||||
            believe  : |||||||
            ----------

        bar-chart[10] spell-check |elefant>
            ----------
            elegant   : ||||||||||
            elevate   : ||||||||
            element   : ||||||||
            elegance  : ||||||||
            elevator  : |||||||
            elegiac   : ||||||
            eleven    : ||||||
            elephant  : ||||||
            elevation : ||||||
            elemental : ||||||
            ----------
        
        bar-chart[10] spell-check |teh>
            ----------
            tea  : ||||||||||
            ten  : ||||||||||
            the  : ||||||||
            team : |||||||
            tear : |||||||
            teem : |||||||
            teen : |||||||
            tell : |||||||
            tend : |||||||
            tens : |||||||
            ----------

        bar-chart[10] spell-check |shwo>
            ----------
            show  : ||||||||||
            shod  : |||||||||
            shoe  : |||||||||
            shop  : |||||||||
            shot  : |||||||||
            sham  : ||||||||
            shed  : ||||||||
            ship  : ||||||||
            shown : ||||||||
            shows : ||||||||
            ----------

    see also:
        map, ngrams, swrite, sread, long-display, bar-chart
        spell-check-operator.sw
        identify-and-predict-sequence-fragments.swc
        identify-and-predict-integer-sequence-fragments.swc


Home