[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Advice for program to use to write a reading program
From:       Nicola Mingotti <nmingotti () gmail ! com>
Date:       2018-08-21 23:57:08
Message-ID: 66ab0a8e-b33d-467a-6f02-324311a6f9f8 () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Elizabeth,

so, I wrote you a very simple program that goes in the direction
you say. You can see a screenshot here :
http://euriscom.it/data/example-text-highlither.png

The code is at the bottom.

1] I put a lot of comments to simplify your reading

2] There is some stuff in italian, forgive me is 2:00 am, in the next 
days i will
have other stuff to do, so now or never;) Anyhow, GoogleTranslate where 
needed ;)

3] I wrote it fast, about 2 hours, it took me most of the time to find
how to make the graphical interface do what i want to.

4] The graphical interface i like for scripting is Tk, probably the 
simplest.

5] since i wrote it fast, it should be easier to understand than well 
written code.
But, consider this is just a script, not a serius program, it is just to 
get your started.

6] I am really interested in knowing if you can run the program. Please
let me know that. I need to know if a non-programmer can run a Ruby program
with a simple interface, since we discussed about this recently in the list.

7] There are tons of typos, sorry for that.


enough cha cha cha, here is the script

========================
#!/usr/local/bin/ruby
# ; -*- mode: Ruby;-*-

require "irb"
require "irb/completion"

require "tk"
require "tk/font"

root = TkRoot.new { title "Text Hilighter" }

# size and place of the window
root.minsize [500, 100]
root.geometry "+300+300"

# first push button
b1 = TkButton.new root do
   text "Hilight Stuff" ;
   command proc { pushedHilight; }
   pack :side => "top", :fill => "x", :expand => "true"
end

# second push button
b2 = TkButton.new root do
   text "Clean Highligthing" ;
   command proc { pushedCleanHighlighting; }
   pack :side => "top", :fill => "x", :expand => "true"
end

# text widget, where you write stuff
# here it is a global variable because we need to access it from functions
$t1 = TkText.new root do
   pack :side => "top", :fill => "both", :expand => "true"
end

# ---- some commands for Tk Text widget -----
# $t1.insert :end "helo"    # inserisce una parola alla fine
# $t1.delte 1.0, :end       # cacella tutto
# $t1.get 1.0, :end         # ottiene tutto il testo
# $t1.tag_add :xx, 1.0, 1.2      # taggo con :xx i primi due caratteri 
nella prima riga
# $t1.tag_configure :xx, :background, "yellow"     # il tag :xx viene 
impostato a background yellow
# $t1.tag_delete :xx        # elimina i tag dal testo
# $t1.index :end            # ritorna con x.y che e' l'ultimo carattere


def pushedHilight
   # pattern, that says: I want all strings starting with any of the 
letter a,e,i,o,u
   # and followed by any of the letter {b,c,d, ... }
   # the "i" at the ends means we ignore case of letters
   pattern = /[aeiou][bcdfghjklmnpqrstvwyz]/i
   puts "pushed button: Hilight"
   # get all the text from the Tk Text widget
   text = $t1.get 1.0, :end
   # split the text in lines
   lines = text.split /\n/;
   # iterate over each lines looking for the pattern we are interested into
   (0...lines.length).each do |idx|
     # lines in a Tk Text widget are numbered starting from 1 
(unfortunately)
     # but charactes in each line are numbered starting from 0 (we like 
this more)
     tclLineIdx = idx + 1
     # "li" is the line i am currently observing
     li = lines[idx]
     puts "line: #{idx} -- #{li}"
     # "pe" (pattern end) at the beginnig is set to zero, we have not 
found still any
     # pattern.
     pe = 0
     # now we look for all pattern occurring in "li"
     loop do
       pb = li.index(pattern, pe)
       # if no pattern is found "pb" (pattern begin) is "nil", we can 
exit the study
       # of the current line.
       break if pb == nil
       pe  = Regexp.last_match.end(0)
       puts "line #{idx},  pb: #{pb}, pe: #{pe} "
       # this line is the one telling to Tk to mark each patter with the 
tag :xx (just a random name)
       $t1.tag_add :xx, "#{tclLineIdx}.#{pb}", "#{tclLineIdx}.#{pe-1}"
     end
   end
   # here we say that what is tagged as tag ":xx" must be hilighted in 
yellow
   $t1.tag_configure :xx, :background, "yellow"
end

def pushedCleanHighlighting
   puts "pushed button: Clean-Hilight"
   # delete all tags, so remove all hilights
   $t1.tag_delete :xx
end

# this thing is usefull for debugging and learn Ruby
# decomment next line when studying.
# Thread.new {  IRB.start(__FILE__) }

# start the event loop (waits for button pushed and other events)
Tk.mainloop;

========================













On 08/21/18 21:07, Elizabeth Amisano wrote:
> Hello,
>  I am looking for a system to create a program that will help my 
> daughter learn to read. It will be a program that follows certain 
> rules she is learning with her tutor.
>
> Two examples of a command I would ask the program to do would be to:
>
> -highlight all vowels in the text that are backed up by a consonant 
> yellow....
>
> -3 letters that are between highlight to red
>
>
> I am brand new to coding but am determined to make a program that 
> allows me to input the text she will be reading and then based on the 
> rule that is learned in tutoring, apply them one at a time, then layer.
>
> If there are any suggestions folks have for a system to use I would 
> greatly appreciate it.
> Thank you
> Elizabeth Amisano
>
>
>
> On Wed, Aug 1, 2018 at 1:00 AM Leam Hall <leamhall@gmail.com 
> <mailto:leamhall@gmail.com>> wrote:
>
>     Funny note: I had set POODR down for a week or two (or three).
>     Picked it
>     up last night before bed and read a section on hook methods which may
>     exactly solve this issue. Code when I have it.
>
>     Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
>     <mailto:ruby-talk-request@ruby-lang.org>?subject=unsubscribe>
>     <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

-- 
--------------------------
Dr. Nicola Mingotti
R&D - Borghi Srl
CTO - BondInsider
--------------------------


[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    Hi Elizabeth,<br>
    <br>
    so, I wrote you a very simple program that goes in the direction<br>
    you say. You can see a screenshot here : <br>
    <a class="moz-txt-link-freetext" \
href="http://euriscom.it/data/example-text-highlither.png">http://euriscom.it/data/example-text-highlither.png</a><br>
  <br>
    The code is at the bottom.<br>
    <br>
    1] I put a lot of comments to simplify your reading<br>
    <br>
    2] There is some stuff in italian, forgive me is 2:00 am, in the
    next days i will<br>
    have other stuff to do, so now or never;) Anyhow, GoogleTranslate
    where needed ;)<br>
    <br>
    3] I wrote it fast, about 2 hours, it took me most of the time to
    find <br>
    how to make the graphical interface do what i want to. <br>
    <br>
    4] The graphical interface i like for scripting is Tk, probably the
    simplest. <br>
    <br>
    5] since i wrote it fast, it should be easier to understand than
    well written code.<br>
    But, consider this is just a script, not a serius program, it is
    just to get your started.<br>
    <br>
    6] I am really interested in knowing if you can run the program.
    Please<br>
    let me know that. I need to know if a non-programmer can run a Ruby
    program<br>
    with a simple interface, since we discussed about this recently in
    the list.<br>
    <br>
    7] There are tons of typos, sorry for that.<br>
    <br>
    <br>
    enough cha cha cha, here is the script <br>
    <br>
    ========================<br>
    #!/usr/local/bin/ruby <br>
    # ; -*- mode: Ruby;-*-<br>
    <br>
    require "irb"<br>
    require "irb/completion"<br>
    <br>
    require "tk"<br>
    require "tk/font"<br>
    <br>
    root = TkRoot.new { title "Text Hilighter" }<br>
    <br>
    # size and place of the window <br>
    root.minsize [500, 100]<br>
    root.geometry "+300+300"<br>
    <br>
    # first push button <br>
    b1 = TkButton.new root do <br>
      text "Hilight Stuff" ; <br>
      command proc { pushedHilight; }<br>
      pack :side =&gt; "top", :fill =&gt; "x", :expand =&gt; "true"<br>
    end <br>
    <br>
    # second push button <br>
    b2 = TkButton.new root do <br>
      text "Clean Highligthing" ; <br>
      command proc { pushedCleanHighlighting; }<br>
      pack :side =&gt; "top", :fill =&gt; "x", :expand =&gt; "true"<br>
    end <br>
    <br>
    # text widget, where you write stuff<br>
    # here it is a global variable because we need to access it from
    functions<br>
    $t1 = TkText.new root do <br>
      pack :side =&gt; "top", :fill =&gt; "both", :expand =&gt; "true"<br>
    end <br>
    <br>
    # ---- some commands for Tk Text widget -----<br>
    # $t1.insert :end "helo"    # inserisce una parola alla fine <br>
    # $t1.delte 1.0, :end       # cacella tutto <br>
    # $t1.get 1.0, :end         # ottiene tutto il testo <br>
    # $t1.tag_add :xx, 1.0, 1.2      # taggo con :xx i primi due
    caratteri nella prima riga<br>
    # $t1.tag_configure :xx, :background, "yellow"     # il tag :xx
    viene impostato a background yellow<br>
    # $t1.tag_delete :xx        # elimina i tag dal testo<br>
    # $t1.index :end            # ritorna con x.y che e' l'ultimo
    carattere <br>
    <br>
    <br>
    def pushedHilight<br>
      # pattern, that says: I want all strings starting with any of the
    letter a,e,i,o,u <br>
      # and followed by any of the letter {b,c,d, ... } <br>
      # the "i" at the ends means we ignore case of letters  <br>
      pattern = /[aeiou][bcdfghjklmnpqrstvwyz]/i<br>
      puts "pushed button: Hilight"<br>
      # get all the text from the Tk Text widget <br>
      text = $t1.get 1.0, :end <br>
      # split the text in lines <br>
      lines = text.split /\n/;<br>
      # iterate over each lines looking for the pattern we are
    interested into <br>
      (0...lines.length).each do |idx| <br>
        # lines in a Tk Text widget are numbered starting from 1
    (unfortunately)<br>
        # but charactes in each line are numbered starting from 0 (we
    like this more)<br>
        tclLineIdx = idx + 1<br>
        # "li" is the line i am currently observing <br>
        li = lines[idx]<br>
        puts "line: #{idx} -- #{li}"<br>
        # "pe" (pattern end) at the beginnig is set to zero, we have not
    found still any <br>
        # pattern.<br>
        pe = 0<br>
        # now we look for all pattern occurring in "li"<br>
        loop do <br>
          pb = li.index(pattern, pe)<br>
          # if no pattern is found "pb" (pattern begin) is "nil", we can
    exit the study<br>
          # of the current line.<br>
          break if pb == nil      <br>
          pe  = Regexp.last_match.end(0)<br>
          puts "line #{idx},  pb: #{pb}, pe: #{pe} "<br>
          # this line is the one telling to Tk to mark each patter with
    the tag :xx (just a random name)<br>
          $t1.tag_add :xx, "#{tclLineIdx}.#{pb}",
    "#{tclLineIdx}.#{pe-1}"<br>
        end    <br>
      end<br>
      # here we say that what is tagged as tag ":xx" must be hilighted
    in yellow<br>
      $t1.tag_configure :xx, :background, "yellow"<br>
    end<br>
    <br>
    def pushedCleanHighlighting <br>
      puts "pushed button: Clean-Hilight"<br>
      # delete all tags, so remove all hilights<br>
      $t1.tag_delete :xx<br>
    end <br>
    <br>
    # this thing is usefull for debugging and learn Ruby <br>
    # decomment next line when studying.<br>
    # Thread.new {  IRB.start(__FILE__) }<br>
    <br>
    # start the event loop (waits for button pushed and other events)  <br>
    Tk.mainloop;<br>
    <br>
    ======================== <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 08/21/18 21:07, Elizabeth Amisano
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CA+TyhaOt_VMQ2oCFuX6n4j84c-kufMCbKM55SY+Twe7kpCtJNQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <div>
        <div dir="auto">Hello,</div>
        <div dir="auto"> I am looking for a system to create a program
          that will help my daughter learn to read. It will be a program
          that follows certain rules she is learning with her tutor. </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Two examples of a command I would ask the
          program to do would be to:</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">-highlight all vowels in the text that are
          backed up by a consonant yellow.... </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">-3 letters that are between highlight to red</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">I am brand new to coding but am determined to
          make a program that allows me to input the text she will be
          reading and then based on the rule that is learned in
          tutoring, apply them one at a time, then layer. </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">If there are any suggestions folks have for a
          system to use I would greatly appreciate it.</div>
        <div dir="auto">Thank you </div>
        <div dir="auto">Elizabeth Amisano </div>
        <div class="gmail_quote">
          <div dir="auto"><br>
          </div>
          <div dir="auto"><br>
          </div>
          <div dir="auto"><br>
          </div>
          <div>On Wed, Aug 1, 2018 at 1:00 AM Leam Hall &lt;<a
              href="mailto:leamhall@gmail.com" \
moz-do-not-send="true">leamhall@gmail.com</a>&gt;  wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Funny
            note: I had set POODR down for a week or two (or three).
            Picked it <br>
            up last night before bed and read a section on hook methods
            which may <br>
            exactly solve this issue. Code when I have it.<br>
            <br>
            Unsubscribe: &lt;mailto:<a
              href="mailto:ruby-talk-request@ruby-lang.org"
              target="_blank" \
moz-do-not-send="true">ruby-talk-request@ruby-lang.org</a>?subject=unsubscribe&gt;<br>
  &lt;<a
              href="http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk"
              rel="noreferrer" target="_blank" \
moz-do-not-send="true">http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk</a>&gt;<br>
  </blockquote>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">
Unsubscribe: <a class="moz-txt-link-rfc2396E" \
href="mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe">&lt;mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe&gt;</a>
 <a class="moz-txt-link-rfc2396E" \
href="http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk">&lt;http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;</a>
 </pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
--------------------------
Dr. Nicola Mingotti
R&amp;D - Borghi Srl
CTO - BondInsider
--------------------------</pre>
  </body>
</html>



Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic