Written word-by-word presentation with EEG triggers

74 views
Skip to first unread message

Veranika Puhacheuskaya

unread,
Aug 22, 2022, 2:49:07 PM8/22/22
to E-Prime

Hi all,

This is likely a very basic question but I can't for some reason wrap my head around it. I will be running my first EEG experiment soon (E-Prime 3.0 + BioSemi) and need to send codes to the trigger interface when the target word is displayed (always the last word in the sentence). However, I can't figure out how to do a word-by-word presentation in the first place that because all my sentences have a different number of words in them. If I split my sentences into different columns in my source file, the target words would not be in the same column. Is there any way to do it without writing custom code? Has anyone dealt with the same problem? Thanks!

Spape, Michiel

unread,
Aug 22, 2022, 3:59:42 PM8/22/22
to e-p...@googlegroups.com

Hi Veranika,

I have done this every now and then, and as far as I know, there are three ways, and it’s probably best to combine some elements from each:

  1. Have lists load from text files rather than hard-code them;
  2. Use colon syntax to refer to the row, rather than use different columns. I.e. If you have one list ‘CatList’ with the sentence (e.g. a nested list) “The cat is a medium-sized, usually furry mammal” as an attribute (CatSentence), put 1 word per row: Row 1: The, Row 2: cat, etc. In your trial, add another list for just showing all words within the sentence, one at a time. The trick is to use this list and reference the specific row sequentially, which you do by colon syntax. For example: [CatSentence:0] will refer to row 1, The, [CatSentence:1] to row 2, cat. Let me know if you can’t figure it out further – I have a few examples somewhere.
  3. Write the list from scratch using code, read up on the examples provided in the help on the List objects. OK, so it’s not a way to do it without writing code, obviously, but this is usually the simpler way to get it done!

Hope that helps!

Best,

Michiel

 

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/6636c7b6-a4ce-420b-873b-e4f9961be045n%40googlegroups.com.

Veranika Puhacheuskaya

unread,
Aug 22, 2022, 4:27:28 PM8/22/22
to E-Prime
Hi Michiel, thanks a lot for your detailed answer! If you do have some examples somewhere for 2), I would really appreciate it! I am honestly a real noob in E-Prime (having used jsPsych and PsychoPy only my whole life), so the programming language of E-Prime (E-Basic?) is Greek to me. So all my sentences would just form a giant column with one word per row in the first list and then I will have another list which would be something like:
N  Sentence 
1  [CatSentence:0]  [CatSentence:1]  [CatSentence:2]  [CatSentence:3]  [CatSentence:4]  [CatSentence:5]
2  [CatSentence:6]  [CatSentence:7]  [CatSentence:8]
3  [CatSentence:9]  [CatSentence:10]  [CatSentence:11]  [CatSentence:12]  [CatSentence:13]  [CatSentence:14]
4 etc etc etc ?
How would I make it show one word at a time if they are all in one column? Via custom code? Would it then be different from writing custom code so that it takes a sentence and shows it word-by-word using spaces as a separator (this seems like an obvious solution but I just don't know any E-Basic so I wasn't able to figure it out so far..) Sorry if I misunderstood you! And then of course I also have to send triggers from the target word, which makes it all even worse...


Spape, Michiel

unread,
Aug 23, 2022, 7:37:47 AM8/23/22
to e-p...@googlegroups.com

Hi Veranika,

I’ll do my best, but it’s not so easy to explain in a few sentences :) Basically, the idea is that there’s 1 column, CatSentence, (or even 1 list) per sentence, with each word in a different row. Put it as a nested list in the blocklist. Then, the triallist can say where the sentence comes from, say with an attribute called [Sentence], saying Cat in trial 1. In the TrialList, add another list, SubTrialList (let’s say it has 8 words, so 8 rows) to show each word with an attribute Word. In SubTrialList, add a procedure (WordProc) and add a textdisplay TheWord* to say [Word]. Now you could say in SubTrialList, row 1 [CatSentence:0] and row 2 [CatSentence:1], and it will show 1 word at a time. BUT, even cleverer, would be to refer dynamically to the list CatSentence, by referring to the attribute [Sentence] within it: [[Sentence]Sentence:0] for row 1, [[Sentence]Sentence:1] for row 2.

But what to do if there’s more or fewer words per sentence? (perhaps not a great idea if you do EEG). The simplest way would be to add a codeword: TheEnd at the end of the cat sentence. Then just BEFORE TheWord, put an inline, and after TheWord, put a goto flag, Skipper. The inline can say

 

If c.getattrib (“Word”) = “TheEnd” then goto Skipper

 

Done!

I also attached an experiment that does it slightly less elegantly by code, maybe it helps!

Best,

Michiel

 

*Anyone else read Transmetropolitan?

 

BrainStory1d_tst.es3

Veranika Puhacheuskaya

unread,
Aug 24, 2022, 2:31:07 PM8/24/22
to E-Prime
Hi Michiel, thanks for sending me your experiment! It may be not a great idea to have a varying number of words per sentence when you do EEG, but when you have >200 natural sentences, it's just not physically possible ;) If there wasn't, it wouldn't be a problem in the first place and there is a super elegant way of doing it without any custom coding :) Anyway, having 200 lists sounds like an enormous amount of work to be honest, and I am starting to have a feeling that I will have to use E-Basic to somehow solve the problem and use spaces in between words as a separator to do a word-by-word display. I will thoroughly examine your code to see whether I can use bits and pieces from it somehow to speed up the process. Thanks a lot for your help! 

David McFarlane

unread,
Aug 25, 2022, 4:50:52 PM8/25/22
to e-p...@googlegroups.com
Well doing word-by-word presentation with a variable number of words
between trials really is not very basic at all. Seems to me that I
tackled this issue for a project here some years ago, but I cannot put
my finger on it just now. But here is another idea off the top of my
head ...

You could make one List with one row for each trial. The List would
have enough columns for the longest sentence, with column names like
"Word1", "Word2", etc., plus whatever other columns you need for the
trials. As Michiel suggested, you could use a key string such as "***"
to mark the end of the sentence, or use a column to supply the number of
words in each sentence.

Then you would have to use some InLine code to actually run a loop to
present the words for each trial. You could construct the loop using
good-old GoTo, or use a Do-Loop or For-Next structure.

E.g., using a trial Procedure structured as
- TrialSetupCode
- WordLoopBeginLabel
- WordSetupCode
- WordSlide
- WordLoopCode
- WordLoopExitLabel

TrialSetupCode does

Dim wordCount as Integer
Dim xWord as String

WordSetupCode does

wordCount = wordCount + 1
xWord = c.GetAttrib("Word" + wordCount)
If xWord = "***" Then GoTo WordLoopExitLabel
c.SetAttrib "Word", c.GetAttrib("Word" + wordCount)

WordSlide presents the word using the attribute [Word]. Then
WordLoopCode simply does

GoTo WordLoopBeginLabel

This is just a basic sketch of the idea. You could instead base the
loop on the provided number of words in the sentence, or surround
WordSlide with InLine code that does a Do-Loop or a For-Next, etc. And
I did not address outputting a signal/marker/trigger for the target word
yet.

Of course, splitting up 200 sentences into their component words for
each row still takes a lot of effort. Alternatively, you could use a
single column to hold the entire sentence text string for each trial.
Then you would have to use some extensive InLine code to parse out the
words on the fly and present them. If you want to go that route, look
into string handling functions such as Mid$, Item$, Word$, WordCount,
etc. Browse through the E-Basic Help for more info on these and more.
Good luck!

-- David McFarlane


On 2022-08-24 Wed 2:31 PM, Veranika Puhacheuskaya wrote:
> Hi Michiel, thanks for sending me your experiment! It may be not a great
> idea to have a varying number of words per sentence when you do EEG, but
> when you have >200 natural sentences, it's just not physically possible
> ;) If there wasn't, it wouldn't be a problem in the first place and
> there is a super elegant way of doing it without any custom coding :)
> Anyway, having 200 lists sounds like an enormous amount of work to be
> honest, and I am starting to have a feeling that I will have to use
> E-Basic to somehow solve the problem and use spaces in between words as
> a separator to do a word-by-word display. I will thoroughly examine your
> code to see whether I can use bits and pieces from it somehow to speed
> up the process. Thanks a lot for your help!
>
> On Tuesday, August 23, 2022 at 5:37:47 a.m. UTC-6 michie...@helsinki.fi
> wrote:
>
> Hi Veranika,____
>
> I’ll do my best, but it’s not so easy to explain in a few sentences
> :) Basically, the idea is that there’s 1 column, CatSentence, (or
> even 1 list) per sentence, with each word in a different row. Put it
> as a nested list in the blocklist. Then, the triallist can say
> /where/ the sentence comes from, say with an attribute called
> [Sentence], saying Cat in trial 1. In the TrialList, add another
> list, SubTrialList (let’s say it has 8 words, so 8 rows) to show
> each word with an attribute Word. In SubTrialList, add a procedure
> (WordProc) and add a textdisplay TheWord* to say [Word]. Now you
> could say in SubTrialList, row 1 [CatSentence:0] and row 2
> [CatSentence:1], and it will show 1 word at a time. BUT, even
> cleverer, would be to refer dynamically to the list CatSentence, by
> referring to the attribute [Sentence] within it:
> [[Sentence]Sentence:0] for row 1, [[Sentence]Sentence:1] for row 2. ____
>
> But what to do if there’s more or fewer words per sentence? (perhaps
> not a great idea if you do EEG). The simplest way would be to add a
> codeword: TheEnd at the end of the cat sentence. Then just BEFORE
> TheWord, put an inline, and after TheWord, put a goto flag, Skipper.
> The inline can say____
>
> __ __
>
> If c.getattrib (“Word”) = “TheEnd” then goto Skipper____
>
> __ __
>
> Done!____
>
> I also attached an experiment that does it slightly less elegantly
> by code, maybe it helps!____
>
> Best,____
>
> Michiel____
>
> __ __
>
> *Anyone else read Transmetropolitan?____
>
> __ __
>
> *From:*e-p...@googlegroups.com <e-p...@googlegroups.com> *On Behalf
> Of *Veranika Puhacheuskaya
> *Sent:* 22 August 2022 23:27
> *To:* E-Prime <e-p...@googlegroups.com>
> *Subject:* Re: Written word-by-word presentation with EEG triggers____
>
> __ __
>
> Hi Michiel, thanks a lot for your detailed answer! If you do have
> some examples somewhere for 2), I would really appreciate it! I am
> honestly a real noob in E-Prime (having used jsPsych and PsychoPy
> only my whole life), so the programming language of E-Prime
> (E-Basic?) is Greek to me. So all my sentences would just form a
> giant column with one word per row in the first list and then I will
> have another list which would be something like:
> N  Sentence ____
>
> 1  [CatSentence:0]  [CatSentence:1]  [CatSentence:2]
> [CatSentence:3]  [CatSentence:4]  [CatSentence:5]
> 2  [CatSentence:6]  [CatSentence:7]  [CatSentence:8]
> 3  [CatSentence:9]  [CatSentence:10]  [CatSentence:11]
> [CatSentence:12]  [CatSentence:13]  [CatSentence:14]
> 4 etc etc etc ?
> How would I make it show one word at a time if they are all in one
> column? Via custom code? Would it then be different from writing
> custom code so that it takes a sentence and shows it word-by-word
> using spaces as a separator (this seems like an obvious solution but
> I just don't know any E-Basic so I wasn't able to figure it out so
> far..) Sorry if I misunderstood you! And then of course I also have
> to send triggers from the target word, which makes it all even worse...
>
> ____
>
> On Monday, August 22, 2022 at 1:59:42 p.m. UTC-6
> michie...@helsinki.fi wrote:____
>
> Hi Veranika,____
>
> I have done this every now and then, and as far as I know, there
> are three ways, and it’s probably best to combine some elements
> from each:____
>
> 1. Have lists load from text files rather than hard-code them;____
> 2. Use colon syntax to refer to the row, rather than use
> different columns. I.e. If you have one list ‘CatList’ with
> the sentence (e.g. a nested list) “The cat is a
> medium-sized, usually furry mammal” as an attribute
> (CatSentence), put 1 word per row: Row 1: The, Row 2: cat,
> etc. In your trial, add another list for just showing all
> words within the sentence, one at a time. The trick is to
> use this list and reference the specific row sequentially,
> which you do by colon syntax. For example: [CatSentence:0]
> will refer to row 1, The, [CatSentence:1] to row 2, cat. Let
> me know if you can’t figure it out further – I have a few
> examples somewhere. ____
> 3. Write the list from scratch using code, read up on the
> examples provided in the help on the List objects. OK, so
> it’s not a way to do it /without /writing code, obviously,
> but this is usually the simpler way to get it done!____
>
> Hope that helps!____
>
> Best,____
>
> Michiel____
>
> ____
>
> *From:*e-p...@googlegroups.com <e-p...@googlegroups.com> *On
> Behalf Of *Veranika Puhacheuskaya
> *Sent:* 22 August 2022 21:49
> *To:* E-Prime <e-p...@googlegroups.com>
> *Subject:* Written word-by-word presentation with EEG triggers____
>
> ____
>
> Hi all,____
>
> This is likely a very basic question but I can't for some reason
> wrap my head around it. I will be running my first EEG
> experiment soon (E-Prime 3.0 + BioSemi) and need to send codes
> to the trigger interface when the target word is displayed
> (always the last word in the sentence). However, I can't figure
> out how to do a word-by-word presentation in the first place
> that because all my sentences have a different number of words
> in them. If I split my sentences into different columns in my
> source file, the target words would not be in the same column.
> Is there any way to do it without writing custom code? Has
> anyone dealt with the same problem? Thanks!____

Spape, Michiel

unread,
Aug 25, 2022, 6:20:29 PM8/25/22
to e-p...@googlegroups.com
Hi,
Sorry, I'm in a bit of a travel situation at the moment (what you might call a holiday) but I wanted to point out:
* It's certainly not physically impossible, though I do agree it is linguistically very difficult :) And, likely, you'll end up with sentences that won't sound great.
* Anyway, the example uses a single list with all sentences (each in a row) and provides the ebasic to hack these sentences and show them one word at the time.

Let me know if you get it to work to begin with, and I'll be happy to explain in more detail what it does! In this experiment, there were stories (each 100 words), based on a bunch of emotional words. Words are shown 1 by 1, and of course, as you mention it's not hard as long as there are always the same number of words. But David provides below some pointers on how to get out of that, and in a much less elegant sort of way (but time-accuracy, experimentally wise it works fine), my single line of code should fix it right up.
Cheers from sunny (to put it mildly) Portugal,
Michiel

(PS David, like you, I had some sort of experiment a long time ago where I did something just like this, but found it too hard to dig up the original - and getting it to work with different devices, EP1, removing all the idiosyncratic fluff, etc. ! And, I was actually much more pleased with this ad-hoc sentence-chopping solution attached in my previous email)

> -----Original Message-----
> From: e-p...@googlegroups.com <e-p...@googlegroups.com> On
> --
> You received this message because you are subscribed to the Google Groups
> "E-Prime" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to e-prime+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/e-prime/aa9ce351-cc3a-2d81-9170-
> 70c207bb491d%40msu.edu.

Veranika Puhacheuskaya

unread,
Aug 27, 2022, 12:26:04 PM8/27/22
to E-Prime
Hi Michiel and David, thank you so much for all your precious help! Truth be told, I got too tired and frustrated of dealing with this pretty archaic piece of software and programmed everything using Python and PsychoPy. I will definitely keep all your solutions in the lab in case we face the same issues and have to stick with E-Prime. Wish you two all the best! 
Veranika
Reply all
Reply to author
Forward
0 new messages