Files
HomeAgent/internal/nlp/fallback.go
JianFeeeee 4e70b8d5d8 refactor(module): 核心仓 Go module 路径改为 github.com/JianFeeeee/HologramAgent
批 1,不含 SDK 仓与目录改名。

- go.mod 第 1 行 module 路径
- 366 个 .go 文件的完整前缀 github.com/JianFeeeee/HomeAgent 机械替换
  (857 处,仅完整前缀;展示名/注释里的 HomeAgent 字样留给批 5)
- 未改:third_party 目录名、SDK 自身 go.mod module、go.mod replace 目标、
  homed/waiter 可执行名、.hmap 后缀
2026-10-21 12:17:19 +08:00

54 lines
946 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package nlp
import (
"strings"
"github.com/JianFeeeee/HologramAgent/internal/memory"
)
// fallbackParser 使用 gojieba 分词 + POS 做降级句法分析
// 返回解析结果中只填充 Tokens 和 POS,Heads/DepRels 留空
type fallbackParser struct{}
func newFallbackParser() *fallbackParser {
return &fallbackParser{}
}
func (p *fallbackParser) Parse(text string) (*ParseResult, error) {
if text == "" {
return &ParseResult{}, nil
}
x := memory.GetJieba()
if x == nil {
return nil, nil
}
tagged := x.Tag(text)
var tokens, pos []string
for _, t := range tagged {
// Tag() 返回 "word/POS" 格式
idx := strings.LastIndex(t, "/")
if idx < 0 {
continue
}
word := t[:idx]
tag := t[idx+1:]
if word == "" {
continue
}
tokens = append(tokens, word)
pos = append(pos, tag)
}
if len(tokens) == 0 {
return &ParseResult{}, nil
}
return &ParseResult{
Tokens: tokens,
POS: pos,
}, nil
}