zoukankan      html  css  js  c++  java
  • stop_token.go

    package engine

    import (
        "bufio"
        "log"
        "os"
    )

    type StopTokens struct {
        stopTokens map[string]bool
    }

    // 从stopTokenFile中读入停用词,一个词一行
    // 文档索引建立时会跳过这些停用词
    func (st *StopTokens) Init(stopTokenFile string) {
        st.stopTokens = make(map[string]bool)
        if stopTokenFile == "" {
            return
        }

        file, err := os.Open(stopTokenFile)
        if err != nil {
            log.Fatal(err)
        }
        defer file.Close()

        scanner := bufio.NewScanner(file)
        for scanner.Scan() {
            text := scanner.Text()
            if text != "" {
                st.stopTokens[text] = true
            }
        }

    }

    func (st *StopTokens) IsStopToken(token string) bool {
        _, found := st.stopTokens[token]
        return found
    }

  • 相关阅读:
    不是结束,而是刚刚开始
    第七次作业
    用类做封装
    用户故事
    团队编程--MP3播放器
    结对编程作业
    四则运算
    四、小电视自动抽奖
    三、wss连接B站弹幕
    一、基础设计
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7461679.html
Copyright © 2011-2022 走看看