Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.9K Views
|
13 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Can I use the Wolfram Language to generate Vector images of text?

I am designing a psycholinguistics experiment in which I will be presenting a large number of sentences in a self-paced reading task.

For instance I would need the following images if I were to use this particular sentence:

--- -------- - ----- ---- --- --------- ------ -- - ---- -- --- ---- ---------- --------.

For instance - ----- ---- --- --------- ------ -- - ---- -- --- ---- ---------- --------.

--- -------- I would ---- --- --------- ------ -- - ---- -- --- ---- ---------- --------.

--- -------- - ----- need the --------- ------ -- - ---- -- --- ---- ---------- --------.

--- -------- - ----- ---- --- following images -- - ---- -- --- ---- ---------- --------.

--- -------- - ----- ---- --- --------- ------ if I ---- -- --- ---- ---------- --------.

--- -------- - ----- ---- --- --------- ------ -- - were to --- ---- ---------- --------.

--- -------- - ----- ---- --- --------- ------ -- - ---- -- use this ---------- --------.

--- -------- - ----- ---- --- --------- ------ -- - ---- -- --- ---- particular sentence.

In an evenly spaced font of course, but you get the idea. Also, the experiment involves four factorial conditions, in which both either, or neither of the words in view are presented in a less legible color. I designed the original stimulus using a web-based html to image converter and did every image excrutiatingly by hand. That is not plausible for the full experiment. It seems to me that this task should be fairly straightforward and well within the power of the Wolfram Language.

POSTED BY: Kyle Zimmer
13 Replies

Bill, yes, that's a wonderful example.

Kyle, send me an email at the address in my Wolfram Community profile (click on my name) and we can finish up via email.

Best, David

POSTED BY: David Reiss
Posted 12 years ago

It is not the kind of presentation you were asking for, but if you want another impressive example of what a few dozen lines of Mathemaica can do for presenting carefully positioned and formatted and highlighted text to a viewer then you might search the forum for the word spritz

POSTED BY: Bill Simpson

...Blushes...

Actually, it's the Wolfram Language that's amazing.

Spread the word!

POSTED BY: David Reiss

You are amazing David.

POSTED BY: Kyle Zimmer

Kyle, see the attached updated notebook which now has an additional function, PsychoSentenceSVG, that takes a directory path as an additional argument and which exports each individual line to its own svg file. --David

Attachments:
POSTED BY: David Reiss
POSTED BY: David Reiss

Longer answer: see the attached notebook that implements something along the lines of what I think you are wanting. Of course this is just a quick sketch (20 minutes development time) but it could be expanded in a variety of ways....

--David

Attachments:
POSTED BY: David Reiss

Just for people's reference, attached is the updated notebook.

And here is the associated function:

ClearAll[PsychoSentenceSVG, modifyWords];

modifyWords[{word1_String, word2_String}, {style1_, style2_}] :=

  Switch[{style1, style2},

   {None, None},
   {word1, word2},

   {None, _},
   {word1, Style[word2, style2]},

   {_, None},
   {Style[word1, style1], word2},

   {_, _},
   {Style[word1, style1], Style[word2, style2]}
   ];


Options[PsychoSentenceSVG] = {ReplacementCharacter -> "-", 
   FontFamily -> "Courier", FontSize -> 12};

PsychoSentenceSVG[sentence_String, path_String, 
   fileName_String, {style1_, style2_}, OptionsPattern[]] :=

  Module[{splitSentence, dashedTemplate, stringTable, 
    processedSentences, replacementCharacter, fontFamily, fontSize},

   replacementCharacter = OptionValue[ReplacementCharacter];
   fontFamily = OptionValue[FontFamily];
   fontSize = OptionValue[FontSize];

   splitSentence = Partition[StringSplit[sentence], 2, 2, 1, ""];

   dashedTemplate = 
    Map[StringReplace[#, _ -> replacementCharacter] &, 
     splitSentence, {2}];

   splitSentence = modifyWords[#, {style1, style2}] & /@ splitSentence;

   stringTable = Table[
     Riffle[Flatten[
       ReplacePart[dashedTemplate, i -> splitSentence[[i]]]], 
      " "], {i, Length[splitSentence]}];

   processedSentences = Row /@ stringTable;
   processedSentences = 
    TextCell[#, "Text", FontFamily -> fontFamily, 
       FontSize -> fontSize, ShowStringCharacters -> False] & /@ 
     processedSentences;

   MapIndexed[
    Export[FileNameJoin[{path, 
        "s" <> fileName <> "w" <> ToString[#2[[1]]] <> ".svg"}], #1, 
      "SVG"] &, processedSentences]

   ];
Attachments:
POSTED BY: David Reiss

Thanks Bill.

POSTED BY: Kyle Zimmer
POSTED BY: Kyle Zimmer
POSTED BY: Kyle Zimmer
Posted 12 years ago
POSTED BY: Fuping Tan

Short answer: yes.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard