Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/vale/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ func runTag(args []string, _ *core.CLIFlags) error {
return err
}

out := core.TextToContext(
out, err := core.TextToContext(
string(text), &nlp.Info{Lang: args[1], Endpoint: args[2]})
if err != nil {
return err
}

return printJSON(out)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/check/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s Scope) Matches(blk nlp.Block) bool {
// parent block too -- and that is the copy such a rule must see: a
// `scope: heading` rule reading a heading one fragment at a time reported
// `a.` as a whole heading (#1150).
fragment := strings.HasPrefix(blk.Scope, "sentence.")
fragment := blk.IsSentence()

for _, sel := range s.Selectors {
if fragment && !asksForSentence(sel) {
Expand Down
363 changes: 295 additions & 68 deletions internal/check/sequence.go

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions internal/check/sequence_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package check

import (
"testing"

"github.com/vale-cli/vale/v3/internal/core"
"github.com/vale-cli/vale/v3/internal/nlp"
)

// A plain (sentence-scoped) rule's Run call against a block Info.Compute
// already built as one segmenter piece -- the common case, and the one this
// PR's optimization targets. Local English tagging never touches a remote
// endpoint either way, so this isolates whatever local cost the skipped
// f.Sentences call itself carried (a map lookup into TokenCache.sentences
// after the first call, since the cache is keyed by exact text and this
// benchmark reuses the same block every iteration).
func BenchmarkSequenceRunPlainRuleSentenceBlock(b *testing.B) {
rule, err := NewSequence(testConfig(), baseCheck{
"extends": "sequence",
"name": "Bench.WidgetArrived",
"level": "error",
"ignorecase": true,
"message": "matched",
"tokens": []interface{}{
map[string]interface{}{"pattern": "widget"},
map[string]interface{}{"pattern": "arrived", "skip": 1},
},
}, "Bench.WidgetArrived")
if err != nil {
b.Fatalf("building rule: %v", err)
}

text := "I bought a widget that arrived promptly, said the courier."
f := &core.File{NLP: nlp.Info{Segmentation: true}}
blk := nlp.NewLinedBlock("", text, "sentence.text.md", 1)

b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, rerr := rule.Run(blk, f, testConfig()); rerr != nil {
b.Fatalf("running rule: %v", rerr)
}
}
}
Loading