From ea72acc06a950c58a584f0441aeff816df112ea9 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Sun, 16 Aug 2020 17:39:15 -0600 Subject: [PATCH] list of nonterminals must be indexed identically to that of the rules --- cfg_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cfg_utils.py b/cfg_utils.py index fc8e271..0d5ebc2 100644 --- a/cfg_utils.py +++ b/cfg_utils.py @@ -361,10 +361,8 @@ if __name__ == '__main__': class CFGBoltzmann: def __init__(self, rules, nonterminals, terminals): self.unitary_rules = rules - print("nonterminal list is", nonterminals) self.nonterminals = nonterminals self.terminals = terminals - print("terminal list is", terminals) def preprocessor(self): unitary_rules = self.unitary_rules @@ -380,8 +378,12 @@ class CFGBoltzmann: rulepack_list = [] + list_of_terminals_in_sync_with_rulepack = [] for x in factorized_rulepack: rulepack_list.append((x, factorized_rulepack[x])) + list_of_terminals_in_sync_with_rulepack.append(x) + self.nonterminals_ordered = list_of_terminals_in_sync_with_rulepack + print("ORDERED nonterminal list is", self.nonterminals_ordered) self.processed_rulepack = rulepack_list @@ -447,6 +449,14 @@ class CFGBoltzmann: assert (xijk in self.nonterminals) print("xijk", xijk, "is a NONterminal!") print("lenghts of RHS In question is", len(RHS_in_question)) + if (how_far_into_the_RHS == (len(RHS_in_question) - 1)): + # CASE C + # we now calculate the index of nonterminal at index K + + new_nonterminal_index = self.nonterminals_ordered.index(xijk) + print("NEW NONTERMINAL INDDEX IS", new_nonterminal_index) + #reduct = self.Fzero() + return 0 -- GitLab