Skip to content

Commit

Permalink
Initial delimiter model
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhang03 committed Oct 21, 2024
1 parent 7e7303b commit 66a5ab4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
32 changes: 32 additions & 0 deletions packages/plugin-spr/examples/delimiter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>

<head>
<script src="https://unpkg.com/jspsych"></script>
<!-- The plugin is loaded here -->
<script src="https://unpkg.com/@jspsych/plugin-spr"></script>
<script src="../dist/index.browser.js"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css">
</head>

<body></body>
<script>
const jsPsych = initJsPsych({
on_finish: async function() {
jsPsych.data.displayData();
},
default_iti: 250
});


const trial = {
type: jsPsychSpr,
unstructured_reading_string: "this %is the %reading string and it is %super super long, i wonder %what will be %coming next.",
mode: 1,
delimiting: true,
};

jsPsych.run([trial])
</script>

</html>
21 changes: 18 additions & 3 deletions packages/plugin-spr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const info = <const>{
type: ParameterType.INT,
default: 1,
},
delimiting: {
type: ParameterType.BOOL,
default: false,
},
},
data: {
/* The representation of the structured_reading_string that was used. Combined with the mode this
Expand Down Expand Up @@ -103,7 +107,15 @@ class SprPlugin implements JsPsychPlugin<Info> {
// creates inital reading string -> TODO: should instead use mode to determine
if (trial.structured_reading_string.length > 0)
this.structured_reading_string = trial.structured_reading_string;
else
else if (trial.delimiting) {
this.structured_reading_string = this.createReadingString(
trial.unstructured_reading_string,
trial.chunk_size,
trial.line_size,
"%"
);
console.log("delimiting is true", this.structured_reading_string);
} else
this.structured_reading_string = this.createReadingString(
trial.unstructured_reading_string,
trial.chunk_size,
Expand All @@ -125,9 +137,12 @@ class SprPlugin implements JsPsychPlugin<Info> {
private createReadingString(
unstructured_reading_string: string,
chunk_size: number,
line_size: number
line_size: number,
delimiter?: string
): string[] {
const split_text = unstructured_reading_string.split(" ");
const split_text = delimiter
? unstructured_reading_string.split(delimiter)
: unstructured_reading_string.split(" ");
const res = [];

var current_chunk = [];
Expand Down

0 comments on commit 66a5ab4

Please sign in to comment.