mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 09:28:14 +00:00
- 重写 extractor.go: 分句、17条 POS 模板、依存模板 + COO 链、ATT合并 - parser.go: 分句循环 + TransE 向量验证(h+r≈t) - fallback.go: jieba POS 降级解析器 - bridge.go: nlp.Triple ↔ memory.Triple 转换 - pipeline.go: extractKeyTriples 改用 NLP 提取器, 删除5条旧前缀规则 - distill.go: docToTriples 改用 NLP 提取器 - reorgGraph: 语义相似度增强检测, 保持纯 LLM 决断 - Provider 接口加 MaxContextTokens() + 模型窗口映射表 - tokenbudget.go: 中文 token 估算器 + budget 分配(80%利用率) - process.go/buildSystemPrompt: 按 token 预算截断 memory+timeline
54 lines
943 B
Go
54 lines
943 B
Go
package nlp
|
||
|
||
import (
|
||
"strings"
|
||
|
||
"gitcode.com/JianFeeeee/HomeAgent/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
|
||
}
|