func getSimilarity(a: String, b: String) -> Double{ let distance = embedding.distance(between: a, and: b) return distance }
收集数据
JSON题库
作为测试,我暂且只录入三道题目。之后我会从这三个题目中选择其中一个,并测试能否检索出正确的题目。
使用JSON格式可以很方便的管理收录的文本:
1 2 3 4 5 6 7 8
{ "IG Chemistry 1C":{ "paper": "IG Chemistry 1C", "1": "This question is about mixtures and compounds.(a) The box gives some methods used to separate mixtures.chromatography crystallisation fractional distillation simple distillationChoose methods from the box to answer the following questions.Each method may be used once, more than once or not at all.(i) Identify a method to separate a single food dye from a mixture of food dyes.(b) The diagram represents a molecule.Explain why this molecule is a compound.(2)(c) The molecular formula of another compound is C3H5N3O9 (i) State the number of different elements in C3H5N3O9(1)(ii) Determine the number of atoms in a molecule of C3H5N3O9(Total for Question 1 = 7 marks)", "2": "2 This question is about rusting.(a) A simplified formula for rust is Fe2O3(i) Name the two substances needed for iron to rust.(2)12(ii) Give the chemical name for rust.(iii) What type of reaction occurs in the rusting of iron?A combustionB neutralisationC oxidationD thermal decomposition(b) Some iron objects are coated with a layer of zinc to prevent rusting. (i) Name this type of rust prevention.(1)(1)(ii) Explain how this type of rust prevention continues to protect iron when the layer of zinc is damaged.(2)(iii) Give two other methods used to prevent iron from rusting.(2)12(Total for Question 2 = 9 marks)", "3": "3This question is about states of matter.(a) The box gives words relating to changes of state.Complete the table by giving the correct word from the box for each change of state.condensation cooling evaporation freezing melting sublimation(3)Change of stateName of changesolid to liquidsolid to gasliquid to solid(b) When ammonia gas and hydrogen chloride gas mix, they react together to form a white solid called ammonium chloride.The equation for the reaction isNH3(g) + HCl(g) → NH4Cl(s)A teacher soaks a piece of cotton wool in concentrated ammonia solution and another piece of cotton wool in concentrated hydrochloric acid.The teacher places the two pieces of cotton wool at opposite ends of a glass tube at the same time.After several minutes, a white ring of solid ammonium chloride forms.cotton wool soaked in concentrated ammonia solutionwhite ring of ammonium chloridecotton wool soaked in concentrated hydrochloric acid (i) State the name given to the spreading out of gas particles.(1) (ii) State how the diagram shows that the particles of ammonia gas are travellingat higher speeds than the particles of hydrogen chloride gas.(1)(iii) Gas particles travel at high speeds.Give a reason why the white ring of ammonium chloride takes several minutes to form.(1)(iv) Concentrated ammonia solution and concentrated hydrochloric acid are corrosive.Give one safety precaution the teacher should take.(1)(Total for Question 3 = 7 marks)", }, }
我们定义一个结构体用来存放从JSON文件中读取的数据
1 2 3 4 5 6
structExamQuestion: Codable { let paper: String let questions: [String: String] let ms: [String: String] let n: [String: String] }
Codable 允许我们轻松地将数据类型(如结构体或类)编码为或解码自外部表示形式(如JSON)
let paper: String 试卷名称 let questions: [String: String] 题目内容 let ms: [String: String] 答案编号 let n: [String: String] 答案图片数量(应对可能出现的多张答案图片的情况)