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中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂