MCPcopy Index your code
hub / github.com/NousResearch/Open-Reasoning-Tasks / parseTaskToJSON

Function parseTaskToJSON

parser.js:1–59  ·  view source on GitHub ↗
(taskString)

Source from the content-addressed store, hash-verified

1function parseTaskToJSON(taskString) {
2 const taskObject = {
3 name: '',
4 description: '',
5 modality: '',
6 diagram: null,
7 citations: null,
8 examples: [],
9 tags: []
10 };
11
12 // Helper function to extract content between two patterns
13 function extractBetween(text, startPattern, endPattern) {
14 const startIndex = text.indexOf(startPattern);
15 if (startIndex === -1) return '';
16 const endIndex = endPattern ? text.indexOf(endPattern, startIndex + startPattern.length) : text.length;
17 return text.slice(startIndex + startPattern.length, endIndex !== -1 ? endIndex : undefined).trim();
18 }
19
20 // Extract name
21 taskObject.name = extractBetween(taskString, '# ', '\n').trim();
22
23 // Extract description
24 taskObject.description = extractBetween(taskString, '## Description:', '##').trim();
25
26 // Extract modality
27 taskObject.modality = extractBetween(taskString, '## Modality:', '##').trim();
28
29 // Extract diagram
30 const diagramContent = extractBetween(taskString, '## Diagram (Optional):', '##').trim();
31 taskObject.diagram = diagramContent || null;
32
33 // Extract citations
34 const citationsContent = extractBetween(taskString, '## Citations (Optional):', '##');
35 if (citationsContent) {
36 taskObject.citations = citationsContent.split('\n')
37 .filter(line => line.trim().startsWith('-'))
38 .map(line => line.trim().slice(1).trim());
39 }
40
41 // Extract examples
42 const examplesContent = extractBetween(taskString, '## Examples:', '## Tags:');
43 const exampleMatches = examplesContent.match(/### Example \d+:([\s\S]*?)(?=### Example \d+:|$)/g);
44 if (exampleMatches) {
45 taskObject.examples = exampleMatches.map(example => {
46 const input = extractBetween(example, 'Input:', 'Output:').replace(/```/g, '').replace(/---/g, '').trim();
47 const output = extractBetween(example, 'Output:', '').replace(/```/g, '').replace(/---/g, '').trim();
48 return [{ input, output }];
49 });
50 }
51
52 // Extract tags
53 const tagsContent = extractBetween(taskString, '## Tags:', '');
54 taskObject.tags = tagsContent.split('\n')
55 .filter(line => line.trim().startsWith('-'))
56 .map(line => line.trim().slice(1).trim());
57
58 return taskObject;
59}
60

Callers 1

generate-json.jsFile · 0.90

Calls 1

extractBetweenFunction · 0.85

Tested by

no test coverage detected