From 95b270416709717696e3cd1cbab143f1b19590dc Mon Sep 17 00:00:00 2001 From: Martin Eberlein <33397273+martineberlein@users.noreply.github.com> Date: Mon, 6 Feb 2023 18:39:40 +0100 Subject: [PATCH] Update expansion_key to handle empty alternatives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the ProbabilisticGrammarMiner to learn the probability distribution from a set of given inputs, the miner does not return the correct probabilistic grammar. In particular, this bug occurs whenever a grammar is used with a production rule that has an "empty" alternative: ⟨maybe_minus⟩ ::= "" | "-". Somehow the miner does not account for the empty ("") derivation sequence. See Issue #153 --- docs/code/GrammarCoverageFuzzer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/code/GrammarCoverageFuzzer.py b/docs/code/GrammarCoverageFuzzer.py index 78320e11e..2118ebfde 100755 --- a/docs/code/GrammarCoverageFuzzer.py +++ b/docs/code/GrammarCoverageFuzzer.py @@ -196,6 +196,10 @@ def expansion_key(symbol: str, if isinstance(expansion, tuple): # Expansion or single derivation tree expansion, _ = expansion + + # Check for empty list expansion + if isinstance(expansion, list) and not expansion: + expansion = "" if not isinstance(expansion, str): # Derivation tree