From 61fd71f69e080790da722e0e03b71ecd7c2538a2 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 10 May 2016 16:02:45 -0400 Subject: General update --- .../main/java/bjc/utils/gen/WeightedGrammar.java | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java index 131e507..78db7d8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java @@ -7,8 +7,8 @@ import bjc.utils.data.IPair; import bjc.utils.data.Pair; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; /** * A random grammar, where certain rules will come up more often than @@ -28,7 +28,7 @@ public class WeightedGrammar { /** * The rules currently in this grammar */ - protected IFunctionalMap>> rules; + protected IMap>> rules; /** * The random number generator used for random numbers @@ -38,7 +38,7 @@ public class WeightedGrammar { /** * All of the subgrammars of this grammar */ - protected IFunctionalMap> subgrammars; + protected IMap> subgrammars; /** * Create a new weighted grammar. @@ -77,7 +77,7 @@ public class WeightedGrammar { * The case being added. */ public void addCase(E ruleName, int probability, - IFunctionalList cse) { + IList cse) { if (ruleName == null) { throw new NullPointerException("Rule name must be not null"); } else if (cse == null) { @@ -146,7 +146,7 @@ public class WeightedGrammar { * @return Whether or not the rule was succesfully added. */ public boolean addRule(E name, - WeightedRandom> cases) { + WeightedRandom> cases) { if (name == null) { throw new NullPointerException("Name must not be null"); } else if (cases == null) { @@ -222,15 +222,15 @@ public class WeightedGrammar { * The rule to test. * @return A set of sentances generated by the specified rule. */ - public IFunctionalList> generateDebugValues( + public IList> generateDebugValues( E ruleName) { if (ruleName == null) { throw new NullPointerException("Rule name must not be null"); } - IFunctionalList> returnedList = new FunctionalList<>(); + IList> returnedList = new FunctionalList<>(); - WeightedRandom> ruleGenerator = rules + WeightedRandom> ruleGenerator = rules .get(ruleName); for (int i = 0; i < 10; i++) { @@ -255,7 +255,7 @@ public class WeightedGrammar { * @return A randomly generated sentance from the specified initial * rule. */ - public IFunctionalList generateGenericValues(E initRule, + public IList generateGenericValues(E initRule, Function tokenTransformer, T spacer) { if (initRule == null) { throw new NullPointerException( @@ -266,7 +266,7 @@ public class WeightedGrammar { throw new NullPointerException("Spacer must not be null"); } - IFunctionalList returnedList = new FunctionalList<>(); + IList returnedList = new FunctionalList<>(); if (subgrammars.containsKey(initRule)) { subgrammars.get(initRule).generateGenericValues(initRule, @@ -309,7 +309,7 @@ public class WeightedGrammar { * @return A list of random grammar elements generated by the specified * rule. */ - public IFunctionalList generateListValues(E initRule, E spacer) { + public IList generateListValues(E initRule, E spacer) { return generateGenericValues(initRule, strang -> strang, spacer); } @@ -336,7 +336,7 @@ public class WeightedGrammar { * * @return The set of all rule names in this grammar */ - public IFunctionalList getRuleNames() { + public IList getRuleNames() { return rules.keyList(); } @@ -389,16 +389,16 @@ public class WeightedGrammar { "Number of times to prefix must be positive."); } - WeightedRandom> rule = rules.get(ruleName); + WeightedRandom> rule = rules.get(ruleName); - IFunctionalList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { - IFunctionalList> newRule = new FunctionalList<>(); + IList> newRule = new FunctionalList<>(); for (int i = 1; i <= numberOfTimes; i++) { - IFunctionalList newCase = pair.merge((left, right) -> { - IFunctionalList returnVal = new FunctionalList<>(); + IList newCase = pair.merge((left, right) -> { + IList returnVal = new FunctionalList<>(); for (E val : right.toIterable()) { returnVal.add(val); @@ -449,13 +449,13 @@ public class WeightedGrammar { "Prefix token must not be null"); } - WeightedRandom> rule = rules.get(ruleName); + WeightedRandom> rule = rules.get(ruleName); - IFunctionalList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((pair) -> { - IFunctionalList newCase = pair.merge((left, right) -> { - IFunctionalList returnVal = new FunctionalList<>(); + IList newCase = pair.merge((left, right) -> { + IList returnVal = new FunctionalList<>(); for (E val : right.toIterable()) { returnVal.add(val); @@ -503,13 +503,13 @@ public class WeightedGrammar { "Prefix token must not be null"); } - WeightedRandom> rule = rules.get(ruleName); + WeightedRandom> rule = rules.get(ruleName); - IFunctionalList>> newResults = new FunctionalList<>(); + IList>> newResults = new FunctionalList<>(); rule.getValues().forEach((par) -> { - IFunctionalList newCase = par.merge((left, right) -> { - IFunctionalList returnVal = new FunctionalList<>(); + IList newCase = par.merge((left, right) -> { + IList returnVal = new FunctionalList<>(); for (E val : right.toIterable()) { returnVal.add(val); -- cgit v1.2.3