dtuy84033 2018-12-15 17:55
浏览 33
已采纳

字符串词库:由于起始字符太多,因此需要使用不等于逻辑的拆分

I have a .dat file that is a dictionary/thesaurus containing about 300k lines

For each word, the following lines below it that have a word in brackets at the start of the string are the thesaurus' alternatives with the word in the brackets being the type. So a noun or adjective. For example:

acceptant|1
(adj)|acceptive|receptive 
acceptation|3
(noun)|acceptance
(noun)|word meaning|word sense|sense|signified
(noun)|adoption|acceptance|espousal|blessing|approval|approving
accepted|6
(adj)|recognized|recognised|acknowledged 
(adj)|undisputed|uncontroversial |noncontroversial
(adj)|standard 
(adj)|acceptable|standard |received
(adj)|established |constituted
(adj)|received|conventional 
accepting|1
(adj)|acceptive 

So in the above there are 4 words from the dictionary, but each word has multiple different entries for the thesaurus

I want to split the strings using:

strings.Split(dictionary, !"(")

Meaning anything that isn't the "(" character. This is because it's an extensive dictionary with slang and abbreviations and whatnot. But I can't work out how to use the not equal to operator

Does anyone know how to use split with not equal to logic? Or can anyone suggest some clever alternative ideas?

  • 写回答

2条回答 默认 最新

  • dongmei1911 2018-12-15 18:19
    关注
    package main
    
    import (
        "bufio"
        "fmt"
        "os"
        "strings"
    )
    
    func main() {
    
        file, _ := os.Open("dic.dat")
        scanner := bufio.NewScanner(file)
        for scanner.Scan() {
            line := scanner.Text()
            if strings.HasPrefix(line, "(") {
                continue
            }
            fmt.Println(line)
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题