Please use our GitHub Issues page for all new support inquiries. If you need to contact us directly, please e-mail [email protected]

Hi there. I'm working on a script with Ruby for an OpenShapa document and could use some help. Basically, what I'm asking the script to do is to grab three variables (A, B, and C), look at an argument from variable A and if the condition being specified is fulfilled, to generate me new cells in column C while also giving me the onset times from column B. The issue I'm having is that the output of this code is the generation of 36 cells rather than the 6 I'm looking for. The output times are correct, but each one appears 6 times rather than just once. The code is included below:

begin

id = getVariable("ID")
control = getVariable("CONTROL")
leaneasy = getVariable("LEANEASY")

for idcell in id.cells
for controlcell in control.cells
if idcell.sitstage == "2"
for controlcell in control.cells
lecell = leaneasy.make_new_cell()
lecell.change_arg("onset", controlcell.onset)
end
end
end
end

setVariable("LEANEASY", leaneasy)

end

Thank you for all the help!

asked 06 Jun '13, 12:42

bchin's gravatar image

bchin
1111
accept rate: 0%


There was one small part of the FOR loop part of the syntax that needed to be added. Ruby doesn't know that ID and CONTROL are nested or related to each other in time, so you need to tell it to bind those cells that match or are contained within the other in time. That's why it was giving 36 cells instead of 6: each ID cell was being matched with each CONTROL cell.

Here is an amended script with annotations:

begin

id = getVariable("ID")
control = getVariable("CONTROL")
leaneasy = getVariable("LEANEASY")

# Loop through all ID cells
for idcell in id.cells
  # Select only ID cells with sitstage of 2
  if idcell.sitstage == "2"
    # Now loop through all CONTROL cells
    for controlcell in control.cells
      #Bind CONTROL cells to ID cells based on onsets and offsets
      if controlcell.onset >= idcell.onset and controlcell.offset <= idcell.offset
        lecell = leaneasy.make_new_cell()
        lecell.change_arg("onset", controlcell.onset)
      end
    end
  end
end

setVariable("LEANEASY", leaneasy)

end
permanent link

answered 06 Jun '13, 16:41

KCSoska's gravatar image

KCSoska ♦
2363
accept rate: 17%

edited 06 Jun '13, 16:43

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×47
×2

question asked: 06 Jun '13, 12:42

question was seen: 3,837 times

last updated: 06 Jun '13, 16:43

powered by OSQA