forked from advancedlogic/go-freeling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
punts.go
47 lines (39 loc) · 1.15 KB
/
punts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package nlp
import (
"container/list"
"strings"
"unicode"
)
const PUNTS_OTHER = "<Other>"
type Punts struct {
tagOthers string
*Database
}
func NewPunts(puntFile string) *Punts {
this := Punts{}
this.Database = NewDatabaseFromFile(puntFile)
this.tagOthers = this.accessDatabase(PUNTS_OTHER)
return &this
}
func (this *Punts) analyze(se *Sentence) {
var form string
var i *list.Element
for i = se.Front(); i != nil; i = i.Next() {
form = i.Value.(*Word).getForm()
TRACE(3, "Checking form "+form, MOD_PUNTS)
data := this.accessDatabase(form)
if data != "" {
TRACE(3, " ["+form+"] found in map: known punctuation", MOD_PUNTS)
lemma := data[0:strings.Index(data, " ")]
tag := data[strings.Index(data, " ")+1:]
i.Value.(*Word).setAnalysis(NewAnalysis(lemma, tag))
i.Value.(*Word).lockAnalysis()
} else {
TRACE(3, " ["+form+"] not found in map: known punctuation", MOD_PUNTS)
if !(unicode.IsNumber(rune(form[0])) || unicode.IsLetter(rune(form[0]))) {
TRACE(3, " ["+form+"] no alphanumeric char found. tag as "+this.tagOthers, MOD_PUNTS)
i.Value.(*Word).setAnalysis(NewAnalysis(form, this.tagOthers))
}
}
}
}