文档详情

Web数据管理综合设计实验报告课案.docx

发布:2017-05-24约8.28千字共23页下载文档
文本预览下载声明
学生学号 实验课成绩学 生 实 验 报 告 书 实验课程名称Web数据管理综合设计开课学院计算机科学与技术学院指导教师姓名学生姓名学生专业班级 --学年第学期实验课程名称: Web数据管理综合设计 实验项目名称实验成绩实验者专业班级组别同组者实验日期 年 月 日第一部分:实验分析与设计(可加页) 实验内容描述(问题域描述) Consider the following documents: d1=I like to watch the sun set with my friend. d2=The Best Places To Watch The Sunset. d3=My friend watches the sun come up. Write a program which can output the document ID given by an input word. 实验基本原理与设计(包括实验方案设计,实验手段的确定,试验步骤等,用硬件逻辑或者算法描述) 设计方案:将定义的三个字符串d1,d2,d3转换成字符串数组stringArrd1、stringArrd2、stringArrd3,获得键盘输入的关键字keyword之后逐个在三个字符串数组中查找,如果输入的是多个keyword,同样首先转换成字符串数组,然后逐个与stringArrd1,stringArrd2,stringArrd3匹配。 实验步骤: 定义字符串存储d1,d2,d3,并且将之转换为字符串数组 //字符串存储d1,d2,d3 var d1 = I like to watch the sun set with my friend; var d2 = The Best Places To Watch The Sunset; var d3 = My friend watches the sun come up; //将d1,d2,d3转换成数组 var stringArrd1 = d1.toLowerCase().split( ); var stringArrd2 = d2.toLowerCase().split( ); var stringArrd3 = d3.toLowerCase().split( ); 获取输入的内容 //引入readline模块 var readline = require(readline); var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question(Please input the keywords:\n, function(answer) { //将输入的关键词转化为数组 var arrKeyWords = answer.toLowerCase().split( );//后面代码省略 rl.close(); }); 将输入的内容与字符串数组stringArrd1、stringArrd2、stringArrd3匹配,并输出相应结果 //判断关键词所在的句子 if(checkArr(arrKeyWords,stringArrd1)) { result += d1; } if(checkArr(arrKeyWords,stringArrd2)) { result += d2; } if(checkArr(arrKeyWords,stringArrd3)) { result += d3; } //打印结果 if(result) { console.log(found in + result); }else{ console.log(no found); } 4.匹配函数checkArr: //判断关键词是否在给定的句子中 function checkArr(arrKeyWords,stringArr) { var flag = 0; for(var i=0;iarrKeyWords.length;i++) { for(var j=0;jstringArr.length;j++) { if(arrKeyWords[i] == stringArr[j]) {
显示全部
相似文档