fix: YAML expansion bug and add GBNF to output
- Removed all_grammars expansion in _build_yaml_output (226→54 RAGSAK, 384→87 FastAPI) - Added gbnf field to each YAML entry via to_gbnf() - Updated test_roundtrip_persisted_ragsak to use correct file path Closes #66
This commit is contained in:
parent
9ca56e2c69
commit
ee60b62854
2 changed files with 17 additions and 32 deletions
|
|
@ -20,7 +20,7 @@ import pathspec
|
||||||
|
|
||||||
from .code import preprocess_by_method, extract_arg_info, _summarize_arg_info
|
from .code import preprocess_by_method, extract_arg_info, _summarize_arg_info
|
||||||
from bex.ensemble import infer_ensemble
|
from bex.ensemble import infer_ensemble
|
||||||
from bex.gbnf import validate_sore, grammar_structure_score
|
from bex.gbnf import validate_sore, grammar_structure_score, to_gbnf
|
||||||
from bex.distributional import distributional_split
|
from bex.distributional import distributional_split
|
||||||
from bex.decompose import decompose_with_coverage, get_decomposition_stats
|
from bex.decompose import decompose_with_coverage, get_decomposition_stats
|
||||||
|
|
||||||
|
|
@ -916,34 +916,19 @@ def _build_yaml_output(results, dir_path, max_mdl=200.0, min_structure=0.0):
|
||||||
parts = label.replace(os.sep, "/").split("/")
|
parts = label.replace(os.sep, "/").split("/")
|
||||||
module = parts[0] if len(parts) > 1 else "(root)"
|
module = parts[0] if len(parts) > 1 else "(root)"
|
||||||
|
|
||||||
# When recursive split produced leaf grammars, output each one
|
# Output the best grammar per parent group (don't expand leaves)
|
||||||
all_grammars = meta.get("all_grammars", [])
|
entry = {
|
||||||
if all_grammars:
|
"package": label,
|
||||||
for leaf_label, leaf_grammar, leaf_score, leaf_count in all_grammars:
|
"methods": count,
|
||||||
if grammar_structure_score(leaf_grammar) < min_structure:
|
"grammar": best["grammar"],
|
||||||
continue
|
"gbnf": to_gbnf(best["grammar"]),
|
||||||
entry = {
|
"score": round(best.get("mdl_score", 0), 3),
|
||||||
"package": leaf_label,
|
"algorithm": best["algorithm"],
|
||||||
"methods": leaf_count,
|
"mdl": round(best["mdl_score"], 1),
|
||||||
"grammar": leaf_grammar,
|
}
|
||||||
"score": round(leaf_score, 3),
|
|
||||||
"algorithm": best["algorithm"],
|
|
||||||
"mdl": round(best["mdl_score"], 1),
|
|
||||||
}
|
|
||||||
modules.setdefault(module, []).append(entry)
|
|
||||||
total_patterns += 1
|
|
||||||
else:
|
|
||||||
entry = {
|
|
||||||
"package": label,
|
|
||||||
"methods": count,
|
|
||||||
"grammar": best["grammar"],
|
|
||||||
"score": round(best.get("mdl_score", 0), 3),
|
|
||||||
"algorithm": best["algorithm"],
|
|
||||||
"mdl": round(best["mdl_score"], 1),
|
|
||||||
}
|
|
||||||
|
|
||||||
modules.setdefault(module, []).append(entry)
|
modules.setdefault(module, []).append(entry)
|
||||||
total_patterns += 1
|
total_patterns += 1
|
||||||
|
|
||||||
# Sort entries within each module by MDL
|
# Sort entries within each module by MDL
|
||||||
for module in modules:
|
for module in modules:
|
||||||
|
|
|
||||||
|
|
@ -153,10 +153,10 @@ class TestLoadGrammarIndex:
|
||||||
pytest.skip("RAGSAK grammars.yml not generated yet")
|
pytest.skip("RAGSAK grammars.yml not generated yet")
|
||||||
idx = load_grammar_index("/home/tobi/Desktop/kesai/RAGSAK")
|
idx = load_grammar_index("/home/tobi/Desktop/kesai/RAGSAK")
|
||||||
assert len(idx.get_all()) > 0
|
assert len(idx.get_all()) > 0
|
||||||
# Should be able to resolve a file in the storage package
|
# Should be able to resolve a file in a package with a grammar
|
||||||
g = idx.get(
|
g = idx.get(
|
||||||
"/home/tobi/Desktop/kesai/RAGSAK/infrastructure/adapters/search/src/main/kotlin/eu/corentic/springrag/service/storage/GcsStorage.kt",
|
"/home/tobi/Desktop/kesai/RAGSAK/agents/capability/support/src/main/kotlin/eu/corentic/springrag/agent/capability/support/AgentCapabilityConfiguration.kt",
|
||||||
context_symbol="return",
|
context_symbol="id",
|
||||||
)
|
)
|
||||||
assert g is not None
|
assert g is not None
|
||||||
assert "return" in g
|
assert "id" in g
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue