IESM项目实训十二——姓名成绩语音录入方式改进,学生成绩显示

IESM项目实训十二

姓名成绩语音录入方式改进

之前使用拼音相同来寻找所录入学生,虽较直接结果对比成功率高,但是识别错误的情况也存在。查找百度提供包中可用内容,发现它提供了百度提供了一个工具,可以从拼音角度判断相似度,score越小说明拼音越相似,挺好用,非常适合本项目中已知姓名列表将识别结果从中匹配。使用该工具会进一步提高正确率。百度提供工具类Search,将其添加方法写作工具类。
首先添加拼音依赖:

        <dependency>
			<groupId>com.github.stuxuhai</groupId>
			<artifactId>jpinyin</artifactId>
			<version>1.1.8</version>
		</dependency>

工具类具体内容:

package org.jeecg.modules.demo.ScoresInput.controller;

import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Search {
    final List<Word> targets = new ArrayList<Word>();

    public Search(String[] list) throws PinyinException {
        for (String s : list) {
            Word w = new Word(s);
            targets.add(w);
        }
    }


    public List<Score> search(String input, int limit) throws PinyinException {
        Word w = new Word(input);
        return targets.stream().map(x -> {
            Score s = new Score();
            s.word = x;
            s.score = x.compareTo(w);
            return s;
        }).sorted().limit(limit).collect(Collectors.toList());
    }


    public static int getEditDistance(String s, String t) {
        int d[][]; // matrix
        int n; // length of s
        int m; // length of t
        int i; // iterates through s
        int j; // iterates through t
        char s_i; // ith character of s
        char t_j; // jth character of t
        int cost; // cost
        // Step 1
        n = s.length();
        m = t.length();
        if (n == 0) {
            return m;
        }
        if (m == 0) {
            return n;
        }
        d = new int[n + 1][m + 1];

        // Step 2
        for (i = 0; i <= n; i++) {
            d[i][0] = i;
        }
        for (j = 0; j <= m; j++) {
            d[0][j] = j;
        }

        // Step 3
        for (i = 1; i <= n; i++) {
            s_i = s.charAt(i - 1);
            // Step 4
            for (j = 1; j <= m; j++) {
                t_j = t.charAt(j - 1);
                // Step 5
                cost = (s_i == t_j) ? 0 : 1;
                // Step 6
                d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1,
                        d[i - 1][j - 1] + cost);
            }
        }
        // Step 7
        return d[n][m];
    }

    private static int Minimum(int a, int b, int c) {
        int im = a < b ? a : b;
        return im < c ? im : c;
    }

    class Word implements Comparable {
        final String word;
        final String pinyin1;
        final String pinyin2;

        Word(String word) throws PinyinException {
            this.word = word;
            this.pinyin1 = PinyinHelper.convertToPinyinString(word, ",", PinyinFormat.WITH_TONE_NUMBER);
            this.pinyin2 = PinyinHelper.convertToPinyinString(word, ",", PinyinFormat.WITHOUT_TONE);
        }

        @Override
        public String toString() {
            return word;
        }

        @Override
        public int compareTo(Object o) {
            if (o instanceof Word) {
                Word o1 = (Word) o;
                int score1 = getEditDistance(this.pinyin1, o1.pinyin1);
                int score2 = getEditDistance(this.pinyin2, o1.pinyin2);
                return score1 + score2;
            }
            return 0;
        }
    }

    class Score implements Comparable {
        Word word;
        int score;

        @Override
        public int compareTo(Object o) {
            if (o instanceof Score) {
                return score - ((Score) o).score;
            }
            return 0;
        }

//词组和相似度
        @Override
        public String toString() {
            return "{" +
                    "word=" + word +
                    ", score=" + score +
                    '}';
        }
    }

//将姓名数组和识别结果传入,得到最相似的结果
    public static String getSimilarWord(String input,String[] arr){
        try {
            Search d = new Search(arr);
            List<Search.Score> list=d.search(input,10);
            System.out.println("拼音相似度列表:"+list);
            if(list!=null&&list.size()>0){
                Search.Score score=list.get(0);
                return score.word.toString();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}

使用getSimilarWord(String input,String[] arr)每次语音录入都会有最相似得匹配结果,不会录入无效内容。

学生成绩显示

SELECT les_name,a.les_id,a.les_ord,a.sch_sem,les_time,tea_name,les_credit,teach_type,les_shuxing,test_type,les_type,a.exam_scores,a.usual_scores,a.scores,a.gpa,a.gpa_level
FROM all_stu_scores a,all_scores
where a.les_ord=all_scores.les_ord
  and a.les_id=all_scores.les_id
  and a.stu_id= '#{sys_user_code}'
  and not exists(
        SELECT *
        FROM all_stu_scores c
        where a.stu_id=c.stu_id
          and c.create_time>a.create_time
    )

在这里插入图片描述
该部分通过低代码平台在线报表配置完成,没有编写具体页面。
在这里插入图片描述
需要调试SQL语句,确保能达到自己效果。第一次解析语句不要太过复杂,可能会失败无法加载动态报表配置明细。加载成功后再添加复杂的条件,在下方选择需要显示的列,配置是否可以查询,和下拉框菜单字典。
在这里插入图片描述
在系统管理->数据字典中配置字典。
在这里插入图片描述
字典配置中添加字典内容:
在这里插入图片描述
添加到报表中,效果如下:
在这里插入图片描述
项目目中代码生成时,其中成绩总库和成绩录入信息页面都包含字典,与报表不太相同。需要在数据库中建表,添加数据,再将配置加到需要下拉框菜单的表中,不再详细描述过程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值