dongye9191 2014-04-27 04:13
浏览 71
已采纳

GoLang PoS Tagger脚本花费的时间比应该的要长,并且终端没有输出

This script is compling without errors in play.golang.org: http://play.golang.org/p/Hlr-IAc_1f

But when I run in on my machine, much longer than I expect happens with nothing happening in the terminal.

What I am trying to build is a PartOfSpeech Tagger.

I think the longest part is loading lexicon.txt into a map and then comparing each word with every word there to see if it has already been tagged in the lexicon. The lexicon only contains verbs. But doesn't every word need to be checked to see if it is a verb.

The larger problem is that I don't know how to determine if a word is a verb with an easy heuristic like adverbs, adjectives, etc.

  • 写回答

2条回答 默认 最新

  • dsadsadsa1231 2014-04-27 07:24
    关注

    You've got a large array argument in this function:

    func stringInArray(a string, list [214]string) bool{
        for _, b := range list{
            if b == a{
                return true;
            }
        }
        return false
    }
    

    The array of stopwords gets copied each time you call this function.

    Mostly in Go, you should uses slices rather than arrays most of the time. Change the definition of this to be list []string and define stopWords as a slice rather than an array:

    stopWords := []string{
        "and", "or", ...
    }
    

    Probably an even better approach would be to build a map of the stopWords:

    isStopWord := map[string]bool{}
    for _, sw := range stopWords {
        isStopWord[sw] = true
    }
    

    and then you can check if a word is a stopword quickly:

    if isStopWord[word] { ... }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c