Write and Read Textfiles


Author
Message
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
(1)
My text file contains this: 
/1="4" 
/2="7" 
/3="3“
/4="5"
/5="2"

The above is not something Inquisit can work with. It's not an element / missing the required tags. Also, if you want to output something that you can use as index numbers, you'll have to modify your code to write something out that conforms to the syntax of e.g. a <list> element. Your text file ought to contain something that looks like this:

<list myindex>
/ items = (4,7,3,5,2)
</list>

(2)

<include Attitudes_index>
/ file = "/Users/Julia/Documents/Inquisit/Test/Test.rtf"
</include>

Don't use RTF, use a plain, UTF-8 encoded TXT file.

<include Attitudes_index>
/ file = "/Users/Julia/Documents/Inquisit/Test/Test.txt"
</include>

(3)

<text attitudes>
/ items = attitudes
/fontstyle = ("Arial", 5%, true)
/txcolor = (0, 0, 255)
/vposition = 43
/select = include.attitudes_index.file
</text>

This is wrong. It is not the *file* you ought to reference, but the *element that's in the file* (see #1 above). All <include> does is effectively paste the *contents* of one file (your TXT file) into another (your main script). I.e.

<text attitudes>
/ items = attitudes
/fontstyle = ("Arial", 5%, true)
/txcolor = (0, 0, 255)
/vposition = 43
/select = list.myindex.nextvalue
</text>

july1810
july1810
Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)
Group: Forum Members
Posts: 28, Visits: 213
Dear Dave,
thank you for your answer, the part of how to extract the information from the first part is rather clear now, although I think I rather need the index than the text, as I present several item lists in the second part and so far I used the indices to determine which items belong together. 
Yet, I somehow struggle with the second part, where I want to include the information from the first part.
My text file contains this: 
/1="4" 
/2="7" 
/3="3“
/4="5"
/5="2"

and the code I wrote, which is not working, looks like this:
<include Attitudes_index>
/ file = "/Users/Julia/Documents/Inquisit/Test/Test.rtf"
</include>

<item attitudes>
/1 = "A"
/2 = "B"
/3 = "C"
/4 = "D"
/5 = "E"
/6 = "F"
/7 = "G"
/8 = "H"
</item>

<text attitudes>
/ items = attitudes
/fontstyle = ("Arial", 5%, true)
/txcolor = (0, 0, 255)
/vposition = 43
/select = include.attitudes_index.file
</text>

<trial attitudes>
/stimulustimes = [250 = attitudes]
/timeout = 1000
</trial>

<block AttitudeRelevance>
/trials = [1-6 = noreplacenorepeat (attitudes); 9=end]
</block>

To you it is probably really obvious, but I just cannot see, how to use the file I included properly. Sorry.
I really do appreciate your help!!!
Best
Julia






Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
No, Inquisit cannot write arbitrarily formatted text files. You would have to parse its data file (containing the ratings of interest) using some programming language (e.g. Python) and have that write a properly formatted (i.e. Inquisit syntax-compliant) file cotaining the items of interest. That file can then be used by your 2nd Inquisit script via <include>.

You can offload some of the required formatting to the 1st Inquisit script and write the result to one of the data file's columns. E.g.

<values>
/ rating = 0
/ preformattedstring = ""
/ n = 0
</values>

<block myblock>
/ trials = [1=start; 2-11 = mylikert; 12=end]
</block>

<trial start>
/ ontrialbegin = [values.preformattedstring="<item myratingitems>"; ]
/ trialduration = 0
</trial>

<likert mylikert>
/ ontrialend = [values.rating = likert.mylikert.response]
/ ontrialend = [if (values.rating >= 4) {values.n += 1;
    values.preformattedstring = concat(concat(concat(concat("/", values.n), "=~""), text.mytext.currentitem), "~""); }
    else values.preformattedstring = ""; ]
/ stimulusframes = [1=mytext]
/ numpoints = 7
/ anchorwidth = 2%
</likert>

<trial end>
/ ontrialbegin = [values.preformattedstring="</item>"; ]
/ trialduration = 0
</trial>

<text mytext>
/ items = myitems
/ position = (50%, 40%)
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
/ 5 = "E"
/ 6 = "F"
/ 7 = "G"
/ 8 = "H"
/ 9 = "I"
/ 10 = "J"
</item>

<data>
/ columns = [subject trialnum trialcode stimulusitem response latency values.rating values.preformattedstring]
/ separatefiles = true
</data>

will generate <item>-element-like syntax for any rating >= 4 and write that to the values.preformattedstring column.

Using e.g. Python, R, an Excel macro or the like, you would simply have to take the values.preformattedstring column, throw away the first line / variable header, optionally remove the empty lines and write the rest to a text-file.

Attachments
Edited 9 Years Ago by Dave
july1810
july1810
Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)Distinguished Member (3K reputation)
Group: Forum Members
Posts: 28, Visits: 213
Hello, I would really appreciate your help with the following:
I want to set up and MRI experiment and I want participants to rate approx. 160 text-stimuli before the MRI session. Now, I was wondering, whether, it is possible in Inquisit to write a file, with stimuli-indices that achieved a certain rating after the behavioral pretest and then during MRI read these stimuli-indices in again and use them in a list, where I can randomly draw from to present the text-stimuli with a certain rating during the actual task.
If you could get me started on this, I would be grateful.
Thanks.
Julia

 
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search