Help

Re: Extracting specific text from a field

654 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Jamie_Rood
6 - Interface Innovator
6 - Interface Innovator

Hi all,

I have created a table that houses outputs from ChatGPT; namely creating assessments. 

I am currently prompting the output to create an assessment section by section. Each section contains a number of questions, which as per the prompt, are referred to as 'Question 1', 'Question 2', 'Question 3'. 

I want to extract each question and populate them as new records so that I can create marking guides and model answers for them. 

What would be the formula I could use or script I could run to extract each question from the string? 

See an example of a generated section below:

-----------------------------------------------------------------------------------------------------------------------------------------

Total Marks: 15

Instructions: Please read each question and select the best possible answer from the options provided.

Question 1 (3 marks): Which of the following laws in South Africa is the highest law?

A. Labour Law

B. Traffic Law

C. Medical Law

D. Constitution

 

Question 2 (2 marks): Which of these three branches of government in South Africa has the power to oversee the others?

A. Executive

B. Legislative

C. Judicial

 

Question 3 (3 marks): What is the role of the Constitutional Court in South Africa?

A. To enforce the Constitution

B. To create laws

C. To provide protection for criminal offenders

D. To oversee elections

 

Question 4 (3 marks): What is the maximum number of years a person can serve as a president of South Africa?

A. 2 years

B. 7 years

C. 10 years

D. 15 years

 

Question 5 (4 marks): Which eight individual human rights are guaranteed by the South African Constitution?

A. Freedom of Religion, Culture, Belief

B. Right to Property, Education, Healthcare

C. Right to Life, Human Dignity, Equality

D. Freedom of Fear, Speech, Assembly

 

Distribution of Blooms Taxonomy:

Low Order Thinking: 1.5 marks (10%)

Middle Order Thinking: 4.5 marks (30%)

Higher Order Thinking: 9 marks (60%)

 

Thanks in advance!

2 Replies 2

I don’t believe that formulas would work well. Formulas cannot split text into an array, and formulas do not work well when you have a varying number of items in the text. 

It looks like a script could parse out the questions and answers. However, it would likely be a custom script. I doubt you will find a ready-made script for this particular use case.

Hi, 

Thanks for your input. I have tried running the following script but keep getting the following error:

'

TypeError: Cannot read properties of undefined (reading 'fields') at main on line 9

Here is the actual script:

// Declare the table names and replace with the appropriate names in your base
let TallyMasterTable = 'Tally master';
let QuestionsJamieTestTable = 'questionsTbl';

// Get the record from the trigger
const inputRecord = input.config().record;

// Get the text from the input record
const TallyMasterTable_S1ResponseField = inputRecord.fields['S1: Response'];

// Define the regex pattern to extract questions
const pattern = /Question \d+: [^?]+\?/g;

// Find all questions using the regex pattern
const questions = text.match(pattern) || [];

// Get a reference to the Questions table
const questionsTbl = base.getTable(questionsTable);

// Iterate through the extracted questions
for (const question of questions) {
  // Create a new record in the Questions table
  await questionsTable.createRecordAsync({
    'Question': question
  });
}

I can't seem to identify the error. Thanks