Skip to content

Commit

Permalink
support urls to exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwen101 committed Oct 1, 2023
1 parent 7910e23 commit e88898c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
17 changes: 11 additions & 6 deletions javascript/parseXmlJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
recursivelyProcessTextSnippetJson
} from "./processingFunctions";

import {getIdForExerciseJson} from "./processingFunctions/processExerciseJson";

import {
generateSearchData
} from "./generateSearchData";
Expand Down Expand Up @@ -122,18 +124,19 @@ const processLatex = (node, obj, inline) => {
obj["body"] = math;
obj["tag"] = "LATEX";
};

let latest_exercise_json_id = undefined;
const tagsWithIds = {
TITLE: () => subsubsection_count>0? `#sec${chapterIndex}.${subsubsection_count}` :"",
"#document": () => "",
SUBSUBSECTION: () => subsubsection_count>0? `#sec${chapterIndex}.${subsubsection_count}` :"",
TEXT:() => "#p" + paragraph_count,
SUBHEADING: () => `#h${heading_count}`,
SUBSUBHEADING: () => `#h${heading_count}`,
SECTION: () => `#h${heading_count}`,
FOOTNOTE: () => `#footnote-link-${footnote_count}`,
DISPLAYFOOTNOTE: () => `#footnote-${display_footnote_count}`,
SNIPPET: () => `${snippet_count}`,
//todo, fix this
EXERCISE: () => `#ex-1.${exercise_count}`,
//SNIPPET: () => `${snippet_count}`,

EXERCISE: () => latest_exercise_json_id,
DISPLAYFOOTNOTE: () => `#footnote-${display_footnote_count}`,
};
const findParentID = (node) => {
Expand Down Expand Up @@ -211,6 +214,7 @@ const processTextFunctions = {
},

EXERCISE: (node, obj) => {
latest_exercise_json_id = getIdForExerciseJson(node);
exercise_count += 1;
processExerciseJson(node, obj, chapArrIndex, exercise_count);
},
Expand Down Expand Up @@ -559,7 +563,8 @@ export const parseXmlJson = (doc, arr, filename) => {
} else {
displayTitle = chapterIndex + "\u00A0\u00A0" + chapterTitle;
}


latest_exercise_json_id = undefined;
paragraph_count = 0;
footnote_count = 0;
display_footnote_count = 0;
Expand Down
19 changes: 19 additions & 0 deletions javascript/processingFunctions/processExerciseJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ const processExerciseJson = (node, obj) => {
}
};

export const getIdForExerciseJson = (node) => {
const label = node.getElementsByTagName("LABEL")[0];
let labelName = "";

if (!label) {
labelName = "ex:unlabeled" + unlabeledEx;
} else {
labelName = label.getAttribute("NAME");
}

if (!referenceStore[labelName]) {
missingExerciseWarning(labelName);
return undefined;
}

const displayName = referenceStore[labelName].displayName;
return `#ex-${displayName}`;
}

export default processExerciseJson;
2 changes: 1 addition & 1 deletion javascript/searchRewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const parseAndInsertToIdToContentMap = (json,chapterIndex, idStack = [])
return;
}

if(json.id) {
if(json.id && json.tag !== "SNIPPET") {
const id = chapterIndex + json.id;
idStack.push(id);
idToContentMap[id] = "";
Expand Down
10 changes: 7 additions & 3 deletions javascript/searchRewriteTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// this file is meant to be temporary


/* known issues:
/* todos and issues:
have not test urls, and urls for exercise can be impoved, currently point to the closest paragraph
what is the mechanism for link to snippet and latex? propably need to modify the frontend
works fine for things like <= (numeric comparison operator), but not for || (logical disjunction); could not test for " (double quote)
did not process the "seexml" file, so no see also in index
did not process the latex, roman, italic, etc.
*/
Expand Down Expand Up @@ -224,7 +226,6 @@ const writeFailureMessage = (key, searchResult) => {
failedTests.push(`${key}: result is ${searchResult}, expected occuer number is: ${indexSearchTestCase[key]}`);
}


export function testIndexSearch() {
for (const [key, value] of Object.entries(indexSearchTestCase)) {
const result = search(key, indexTrie);
Expand All @@ -239,8 +240,11 @@ export function testIndexSearch() {
if (result.length < value) {
writeFailureMessage(key, result.length);
continue;
}
}
}

console.log(autoComplete("||", indexTrie));
console.log(search("|| (logical disjunction)", indexTrie));

fs.writeFileSync("failedTests.txt", failedTests.join("\n"));
fs.writeFileSync("urls.txt", JSON.stringify(urls));
Expand Down
2 changes: 1 addition & 1 deletion urls.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"abs":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.61","https://sourceacademy.nus.edu.sg/sicpjs/1.1.62"],"absolute value":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.6#p1"],"abstract data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1#p2"],"abstraction":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.8#p3","https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#p3","https://sourceacademy.nus.edu.sg/sicpjs/4#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.3.2#p1","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/undefined"],"abstraction barriers":["https://sourceacademy.nus.edu.sg/sicpjs/2#p7","https://sourceacademy.nus.edu.sg/sicpjs/2.1.2#p1","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p1","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p6","https://sourceacademy.nus.edu.sg/sicpjs/2.5#p2","https://sourceacademy.nus.edu.sg/sicpjs/4.1.2#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.4.4#p34"],"abstract models for data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.3#footnote-1"],"abstract syntax":["https://sourceacademy.nus.edu.sg/sicpjs/4.1.1#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.4.4#p2"],"accelerated_sequence":["https://sourceacademy.nus.edu.sg/sicpjs/3.5.38"],"accumulate":["https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#ex-1.4","https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#ex-1.5","https://sourceacademy.nus.edu.sg/sicpjs/2.2.36","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-1.6","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-1.11"],"accumulate_n":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.325","https://sourceacademy.nus.edu.sg/sicpjs/2.2.363"],"accumulator":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#p4","https://sourceacademy.nus.edu.sg/sicpjs/3.1.1#ex-1.1","https://sourceacademy.nus.edu.sg/sicpjs/3.1.1#ex-1.4"],"Ackermann's function":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.1#ex-1.2","https://sourceacademy.nus.edu.sg/sicpjs/1.2.1#ex-1.2"],"acquire a mutex":["https://sourceacademy.nus.edu.sg/sicpjs/3.4.2#p16"],"actions, in register machine":["https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/undefined"],"actual_value":["https://sourceacademy.nus.edu.sg/sicpjs/4.2.22"],"Ada":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#ex-1.9","https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#ex-1.9"],"Adams, Norman I., IV":["https://sourceacademy.nus.edu.sg/sicpjs/4.1.7#footnote-1"],"add (generic)":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.11","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p10","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p12"],"add_action":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p8","https://sourceacademy.nus.edu.sg/sicpjs/3.3.413"],"add_complex":["https://sourceacademy.nus.edu.sg/sicpjs/2.4.13"],"add_complex_to_javascript_num":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.21"],"addend":["https://sourceacademy.nus.edu.sg/sicpjs/2.3.26"],"adder (primitive constraint)":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.58"],"adder":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p3","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p6","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#ex-1.3","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#ex-1.5"],"add_interval":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.41"],"additivity":["https://sourceacademy.nus.edu.sg/sicpjs/2#p10","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p4","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/2.5.1#p6"],"add_lists":["https://sourceacademy.nus.edu.sg/sicpjs/4.2.32"],"add_poly":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.31"],"add_rat":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.11"],"address":["https://sourceacademy.nus.edu.sg/sicpjs/5.3.1#p1"],"address arithmetic":["https://sourceacademy.nus.edu.sg/sicpjs/5.3.1#p1"],"add_rule_or_assertion":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.424"],"add_streams":["https://sourceacademy.nus.edu.sg/sicpjs/3.5.210"],"add_terms":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.32"],"add_to_agenda":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p15","https://sourceacademy.nus.edu.sg/sicpjs/3.3.429"],"add_vect":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.4#ex-1.3","https://sourceacademy.nus.edu.sg/sicpjs/2.2.4#ex-1.9"],"adjoin_arg":["https://sourceacademy.nus.edu.sg/sicpjs/5.4.214"],"adjoining to a list with pair":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.1#p7"],"adjoin_set":["https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#p2","https://sourceacademy.nus.edu.sg/sicpjs/2.3.32","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#ex-1.3","https://sourceacademy.nus.edu.sg/sicpjs/2.3.39","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#ex-1.8","https://sourceacademy.nus.edu.sg/sicpjs/2.3.45"],"adjoin_term":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p9","https://sourceacademy.nus.edu.sg/sicpjs/2.5.34"],"Adleman, Leonard":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.6#footnote-5"],"administrative assistant, importance of":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#p7"],"advance_pc":["https://sourceacademy.nus.edu.sg/sicpjs/5.2.35"],"after_delay":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p8","https://sourceacademy.nus.edu.sg/sicpjs/3.3.414"],"A'h-mose":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.4#footnote-4"],"algebraic expression":["https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2#p7","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2#p7","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/undefined","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p1"],"algebraic specification for data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.3#footnote-1"]}
{"abs":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.6#p1","https://sourceacademy.nus.edu.sg/sicpjs/1.1.6#p4"],"absolute value":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.6#p1"],"abstract data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1#p2"],"abstraction":["https://sourceacademy.nus.edu.sg/sicpjs/1.1.8#p3","https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#p3","https://sourceacademy.nus.edu.sg/sicpjs/4#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.3.2#p1","https://sourceacademy.nus.edu.sg/sicpjs/5.1.2","https://sourceacademy.nus.edu.sg/sicpjs/5.1.2"],"abstraction barriers":["https://sourceacademy.nus.edu.sg/sicpjs/2#p7","https://sourceacademy.nus.edu.sg/sicpjs/2.1.2#p1","https://sourceacademy.nus.edu.sg/sicpjs/2.1.2","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p1","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p6","https://sourceacademy.nus.edu.sg/sicpjs/2.5#p2","https://sourceacademy.nus.edu.sg/sicpjs/4.1.2#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.4.4#p34"],"abstract models for data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.3#footnote-1"],"abstract syntax":["https://sourceacademy.nus.edu.sg/sicpjs/4.1.1#p3","https://sourceacademy.nus.edu.sg/sicpjs/4.4.4#p2"],"accelerated_sequence":["https://sourceacademy.nus.edu.sg/sicpjs/3.5.3#p9"],"accumulate":["https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#ex-1.32","https://sourceacademy.nus.edu.sg/sicpjs/1.3.1#ex-1.33","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#p8","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-2.38","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-2.43"],"accumulate_n":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-2.36","https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#ex-2.43"],"accumulator":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.3#p4","https://sourceacademy.nus.edu.sg/sicpjs/3.1.1#ex-3.1","https://sourceacademy.nus.edu.sg/sicpjs/3.1.1#ex-3.4"],"Ackermann's function":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.1#ex-1.10","https://sourceacademy.nus.edu.sg/sicpjs/1.2.1#ex-1.10"],"acquire a mutex":["https://sourceacademy.nus.edu.sg/sicpjs/3.4.2#p16"],"actions, in register machine":["https://sourceacademy.nus.edu.sg/sicpjs/5.1.1","https://sourceacademy.nus.edu.sg/sicpjs/5.1.1"],"actual_value":["https://sourceacademy.nus.edu.sg/sicpjs/4.2.2#p6"],"Ada":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#ex-4.61","https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#ex-4.61"],"Adams, Norman I., IV":["https://sourceacademy.nus.edu.sg/sicpjs/4.1.7#footnote-1"],"add (generic)":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.1#p2","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p10","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p12"],"add_action":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p8","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p12"],"add_complex":["https://sourceacademy.nus.edu.sg/sicpjs/2.4.1#p6"],"add_complex_to_javascript_num":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.2#p2"],"addend":["https://sourceacademy.nus.edu.sg/sicpjs/2.3.2#p6"],"adder (primitive constraint)":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.5#p11"],"adder":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p3","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p6","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#ex-3.30","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#ex-3.32"],"add_interval":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.4#p4"],"additivity":["https://sourceacademy.nus.edu.sg/sicpjs/2#p10","https://sourceacademy.nus.edu.sg/sicpjs/2.4#p4","https://sourceacademy.nus.edu.sg/sicpjs/2.4.3","https://sourceacademy.nus.edu.sg/sicpjs/2.4.3","https://sourceacademy.nus.edu.sg/sicpjs/2.5.1#p6"],"add_lists":["https://sourceacademy.nus.edu.sg/sicpjs/4.2.3#p3"],"add_poly":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p6"],"add_rat":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.1#p4"],"address":["https://sourceacademy.nus.edu.sg/sicpjs/5.3.1#p1"],"address arithmetic":["https://sourceacademy.nus.edu.sg/sicpjs/5.3.1#p1"],"add_rule_or_assertion":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.4#p27"],"add_streams":["https://sourceacademy.nus.edu.sg/sicpjs/3.5.2#p7"],"add_terms":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p10"],"add_to_agenda":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p15","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p24"],"add_vect":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.4#ex-2.46","https://sourceacademy.nus.edu.sg/sicpjs/2.2.4#ex-2.52"],"adjoin_arg":["https://sourceacademy.nus.edu.sg/sicpjs/5.4.2#footnote-3"],"adjoining to a list with pair":["https://sourceacademy.nus.edu.sg/sicpjs/2.2.1#p7"],"adjoin_set":["https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#p2","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#p3","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#ex-2.61","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#p12","https://sourceacademy.nus.edu.sg/sicpjs/2.3.3#ex-2.66","https://sourceacademy.nus.edu.sg/sicpjs/2.3.4#p14"],"adjoin_term":["https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p9","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p16"],"Adleman, Leonard":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.6#footnote-5"],"administrative assistant, importance of":["https://sourceacademy.nus.edu.sg/sicpjs/4.4.1#p7"],"advance_pc":["https://sourceacademy.nus.edu.sg/sicpjs/5.2.3#p4"],"after_delay":["https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p8","https://sourceacademy.nus.edu.sg/sicpjs/3.3.4#p16"],"A'h-mose":["https://sourceacademy.nus.edu.sg/sicpjs/1.2.4#footnote-4"],"algebraic expression":["https://sourceacademy.nus.edu.sg/sicpjs/2.3.2","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2#p7","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2#p7","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2","https://sourceacademy.nus.edu.sg/sicpjs/2.3.2","https://sourceacademy.nus.edu.sg/sicpjs/2.5.3#p1"],"algebraic specification for data":["https://sourceacademy.nus.edu.sg/sicpjs/2.1.3#footnote-1"]}

0 comments on commit e88898c

Please sign in to comment.