GolangNote

Golang笔记

英文分词 Porter & Porter2 stemmer 算法的 Golang 库及性能对比

Permalink

英文分词的难点是词形还原(Lemmatization)和词干提取(Stemming)。

  • 词性还原:does,done,doing,did 需要通过词性还原恢复成 do
  • 词干提取:cities,children,teeth 这些词,需要转换为 city,child,tooth”这些基本形态

目前使用的三种主要词干算法是 Porter、Snowball(Porter2) 和 Lancaster (Paice-Husk),攻击性连续统基本上遵循相同的路线。

  • Porter: 是最常用的词干提取器,也是最温和的词干提取器之一,也是最古老的词干算法。
  • Porter2: 被普遍认为是对 Porter 的改进。事实上,波特本人承认它比他原来的算法要好,计算时间比 porter 快一点。
  • Lancaster: 非常激进的词干算法,有时会出错。对于 porter 和 snowball,词干表示对读者来说通常是相当直观的,而 Lancaster 则不然,因为许多较短的单词会变得完全混淆。

Porter 拥有最多的实现,通常是默认的首选算法,但如果可以,请使用 Snowball(Porter2)。

go 库

这里精选一些 Porter & Porter2 的 go 实现

性能比较

plaintext: Benchmark
1
2
3
4
5
agonopol/go-stem       91	  12549579 ns/op
a2800276/porter      217	   5502990 ns/op
surgebase/porter2      177	   6765206 ns/op
shabbyrobe/go-porter2      273	   4401323 ns/op
shabbyrobe/go-porter2(byte)      286	   4097922 ns/op

其它相关库

其它非 go 实现的英文分词工具

其中 jdkato/prose 库功能强大,性能也很棒

Go: Named-Entity Recognition (NER)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main

import (
	"fmt"
	"github.com/jdkato/prose/v2"
)

func main() {
	doc, _ := prose.NewDocument("Lebron James plays basketball in Los Angeles.")
	for _, ent := range doc.Entities() {
		fmt.Println(ent.Text, ent.Label)
		// Lebron James PERSON
		// Los Angeles GPE
	}
}

本文网址: https://golangnote.com/topic/291.html 转摘请注明来源

Write a Comment to "英文分词 Porter & Porter2 stemmer 算法的 Golang 库及性能对比"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 1ms