feat: parse out explanation text (#358)

This commit is contained in:
Raymond Zhou
2023-06-28 14:05:31 -04:00
committed by GitHub
parent 86b67022ba
commit 436fdfc470
4 changed files with 34 additions and 17 deletions

View File

@@ -529,13 +529,15 @@ export class OLXParser {
const solutionArray = [];
if (divBody && divBody.div) {
divBody.div.forEach(tag => {
if (_.get(Object.values(tag)[0][0], '#text', null) !== 'Explanation') {
const tagText = _.get(Object.values(tag)[0][0], '#text', '');
if (tagText.toString().trim() !== 'Explanation') {
solutionArray.push(tag);
}
});
} else {
solutionBody.solution.forEach(tag => {
if (_.get(Object.values(tag)[0][0], '#text', null) !== 'Explanation') {
const tagText = _.get(Object.values(tag)[0][0], '#text', '');
if (tagText.toString().trim() !== 'Explanation') {
solutionArray.push(tag);
}
});

View File

@@ -23,6 +23,7 @@ import {
solutionExplanationTest,
solutionExplanationWithoutDivTest,
tablesInRichTextTest,
parseOutExplanationTests,
} from './mockData/olxTestData';
import { ProblemTypeKeys } from '../../../data/constants/problem';
@@ -327,5 +328,11 @@ describe('OLXParser', () => {
const explanation = olxparser.getSolutionExplanation(problemType);
expect(explanation).toBe(solutionExplanationWithoutDivTest.solutionExplanation);
});
it('should parse out <p>Explanation</p>', () => {
const olxparser = new OLXParser(parseOutExplanationTests.rawOLX);
const problemType = olxparser.getProblemType();
const explanation = olxparser.getSolutionExplanation(problemType);
expect(explanation).toBe(parseOutExplanationTests.solutionExplanation);
});
});
});

View File

@@ -1090,3 +1090,25 @@ export const tablesInRichTextTest = {
In which of the following observations does the C-value paradox apply? Select all that apply.
</p>`,
};
export const parseOutExplanationTests = {
rawOLX: `<problem>
<multiplechoiceresponse>
<choicegroup>
</choicegroup>
<solution>
<p>Explanation</p>
<p>
Explanation
</p>
<p>solution meat</p>
</solution>
</multiplechoiceresponse>
<demandhint></demandhint>
</problem>`,
solutionExplanation: `
<p>solution meat</p>
`
};

View File

@@ -36,21 +36,7 @@ export const fetchBlockById = ({ blockId, studioEndpointUrl }) => {
} else if (blockId === 'problem-block-id') {
data = {
data: `<problem>
<multiplechoiceresponse>
<p>What is the content of the register x2 after executing the following three lines of instructions?</p>
<p><span style="font-family: 'courier new', courier;"><strong>Address&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;assembly instructions <br />0x0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;addi x1, x0, 1<br />0x4&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;slli x2, x1, 4<br />0x8&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;sub x1, x2, x1</strong></span></p>
<choicegroup type="MultipleChoice">
<choice correct="false">answerA</choice>
<choice correct="true">answerB</choice>
</choicegroup>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p><span style="font-family: 'courier new', courier;"><strong>Address&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;assembly instructions&#160;&#160;&#160;&#160;comment<br />0x0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;addi x1, x0, 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x1 = 0x1<br />0x4&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;slli x2, x1, 4&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x2 = x1 &lt;&lt; 4 = 0x10<br />0x8&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;sub x1, x2, x1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x1 = x2 - x1 = 0x10 - 0x01 = 0xf</strong></span></p>
</div>
</solution>
</multiplechoiceresponse>
</problem>`,
</problem>`,
display_name: 'Dropdown',
metadata: {
markdown: `You can use this template as a guide to the simple editor markdown and OLX markup to use for dropdown problems. Edit this component to replace this template with your own assessment.