private static void ComplexMovementTest() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("CP", "N"); // no overt POS here, head of IP is V. grammar.AddProjectionTypeToTypeDictionary("IP", "N"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] { "CP" }, 0, 0)); grammar.AddRule(new Rule(1, "START", new[] { "IP" }, 0, 0)); //grammar.AddRule(new Rule(1, "CP", new[] { "IP" }, 0, 0)); //grammar.AddRule(new Rule(1, "IP", new[] { "NP" }, 0, 0)); //grammar.AddRule(new Rule(1, "VP", new[] { "V1", "NP" }, 0, 1)); //grammar.AddRule(new Rule(1, "VP", new[] { "V2", "PP" }, 0, 1)); //grammar.AddRule(new Rule(1, "PP", new[] { "P", "NP" }, 0, 1)); //grammar.AddRule(new Rule(1, "NP", new[] { "D", "N" }, 1, 0)); grammar.AddNonTerminalToLandingSites("CP"); grammar.AddNonTerminalToLandingSites("IP"); grammar.AddMoveable("NP"); grammar.AddMoveable("PP"); grammar.GenerateDerivedRulesFromSchema(); var parser = new Parser(grammar, true); var n = parser.ParseSentence("Who Who Who"); n.Print(); }
static void Main(string[] args) { GrammarWorkTesting.RunGrammarTests(3); Grammar grammar = new Grammar(); Rule r1 = new Rule("S", new List <Symbol>() { "S", "a", "S", "b" }); Rule r2 = new Rule("S", new List <Symbol>() { "e" }); grammar.AddRule(r1); grammar.AddRule(r2); grammar.SetStartSym("S"); GrammarValidationReport report = grammar.PrecomputeGrammar(); if (report.isSuccessfull) { MarpaParser mp = new MarpaParser(grammar); // RecogniseReport rr = mp.CheckString("eaeaeaeaeaeaebbbbbb"); } }
internal Grammar GetInitialGrammar_old() { var initialGrammar = new Grammar(voc); initialGrammar.NonTerminalsTypeDictionary = nonTerminalTypeDic; initialGrammar.POSTypes = posTypes; foreach (var sentence in sentencesWithCounts.Keys) { var words = sentence.Split(); //assume unamibigous interpretation of words. take the first POS for each word. var posList = words.Select(x => voc[x].First()).ToArray(); if (posList.Length < 2) { continue; } var lastRuleName = initialGrammar.AddRule(new Rule(0, null, new[] { posList[0], posList[1] }, 1, 0)); for (var i = 0; i < posList.Length - 2; i++) { lastRuleName = initialGrammar.AddRule(new Rule(0, null, new[] { lastRuleName, posList[i + 2] }, 1, 0)); } initialGrammar.AddRule(new Rule(0, initialGrammar.StartSymbol, new[] { lastRuleName }, 0, 0)); } return(initialGrammar); }
// Use this for initialization void Start() { SOPoint sop = SOPoint.CreatePoint(); SOPoint[] sops = new SOPoint[2]; sops[0] = SOPoint.CreatePoint(); sops[1] = SOPoint.CreatePoint(new Vector3(-30, 0, -40)); float[] hs = new float[2]; hs[0] = 60; hs[1] = 16; float[] ws = new float[2]; ws[0] = 30; ws[1] = 45; Building[] buildings = new Building[2]; for (int i = 0; i < sops.Length; i++) { buildings[i] = new Building(); Grammar g1 = new Grammar(); buildings[i].AddGrammar(g1); g1.name = "g1"; g1.assignedObjects.Add(sops[i]); g1.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20)), false); g1.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(ws[i], hs[i], 20)), false); g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"), false); g1.AddRule(new Rules.SingleLoaded("SL", "APT"), false); g1.AddRule(new Rules.DoubleLoaded("DL", "APT"), false); g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false); Grammar g2 = new Grammar(); g2.name = "AptFormA"; g2.category = GraphNode.Category.Bd_Massing; g2.inputs.names.Add("APT"); g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false); g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false); g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false); g1.AddRule(g2, false); g1.AddRule(new Rules.CalBuildingParams(new string[] { "APT" }), false); g1.AddRule(new Rules.ExtractFace(new string[] { "APT" }, "TOP", "TOP"), false); g1.AddRule(new Rules.DivideToFTFH("APT", new string[] { "APTL", "APTLM" }, 4), false); g1.AddRule(new Rules.PivotMirror("APTLM", "APTL", 0), false); g1.AddRule(new Rules.CspFlrToUnitsAbstract(new string[] { "APTL" }), false); g1.AddRule(new Rules.DcpFace5("APTL", new string[] { "F", "DELETE", "S", "DELETE", "BT" }), false); g1.AddRule(new Rules.Extrude("BT", "BT", -0.1f), false); g1.AddRule(new Rules.AggCW01("F", "F", 3, 4), false); g1.AddRule(new Rules.AggBasicSimp("S", "S", 3, 4), false); g1.Execute(); } buildings[0].Invalidate(); buildings[1].Invalidate(); //SceneManager.buildingParamEditor.SetBuilding(buildings[0]); //SceneManager.SelectedGrammar = g1; }
public static Grammar SimpleSquare() { var grammar = new Grammar(); grammar.name = "SimpleSquare"; grammar.backgroundColor = new HsvColor() { h = 20, s = 0.7f, v = 0.9f }; { var initRule = new Rule(); initRule.name = "init"; var s1 = new Replacement(); s1.id = "square"; s1.color = new HsvColor() { h = 100, s = 0.5f, v = 0.5f }; var s2 = new Replacement(); s2.id = "square"; s2.color = new HsvColor() { h = 200, s = 0.7f, v = 0.7f, a = 0.5f }; s2.transform *= Matrix4x4.Scale(new Vector3(0.5f, 0.5f, 1)); /* * var s3 = new ShapeDesc(); * s3.id = "square"; * s3.color = new HsvColor() { a = 1, h = 150, s = 0.2f, v = 0.1f }; * s3.transform *= Matrix4x4.Scale(new Vector3(0.2f, 0.2f, 0.2f)); */ initRule.replacements = new[] { s1, s2 }; grammar.startShape = "init"; grammar.AddRule(initRule); } { var squareRule = new Rule(); squareRule.name = "square"; var s1 = new Replacement(); s1.SetSquare(); s1.transform = Matrix4x4.Rotate(Quaternion.Euler(new Vector3(0, 0, 45))); s1.color = new HsvColor() { h = 45 }; squareRule.replacements = new[] { s1 }; grammar.AddRule(squareRule); } return(grammar); }
void Passed_BisectMirror(ShapeObject so) { Grammar g1 = new Grammar(); g1.name = "g1"; g1.assignedObjects.Add(so); g1.AddRule(new Rules.BisectMirror("A", new string[] { "A", "A" }, 0.4f, 0)); g1.AddRule(new Rules.Bisect("A", new string[] { "B", "C" }, 0.2f, 0)); }
public static void CreateCanonicalMovementGrammar(Grammar grammar) { AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] { "IP" }, 0, 0)); grammar.AddRule(new Rule(1, "START", new[] { "CP" }, 0, 0)); grammar.AddRule(new Rule(0, "CP", new[] { "C", "IP" }, 0, 1)); grammar.AddRule(new Rule(0, "IP", new[] { "NP", "VP" }, 1, 1)); grammar.AddRule(new Rule(0, "VP", new[] { "V1", "NP" }, 0, 1)); grammar.AddRule(new Rule(0, "VP", new[] { "V2", "PP" }, 0, 1)); grammar.AddRule(new Rule(2, "VP", new[] { "V3", "CP" }, 0, 1)); grammar.AddRule(new Rule(0, "NP", new[] { "D", "N" }, 1, 0)); grammar.AddRule(new Rule(0, "PP", new[] { "P", "NP" }, 0, 1)); grammar.AddNonTerminalToLandingSites("CP"); grammar.AddMoveable("NP"); grammar.AddMoveable("PP"); }
void Start() { Vector3[] pts1 = initShape1(); Polygon pg1 = new Polygon(pts1); Extrusion f1 = pg1.Extrude(new Vector3(0, 40, 0)); //ShapeObject so = ShapeObject.CreateMeshable(f1); //so.name = "A"; ShapeObject so = SOPoint.CreatePoint(); Building building = new Building(); g1 = new Grammar(); building.AddGrammar(g1); g1.name = "g1"; so.SetGrammar(g1); //g1.AddRule(new Rules.CreateBox("A", new Vector3(0, 0, 0), new Vector3(10, 10, 10), new Vector3(0,0,0))); g1.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20))); g1.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(40, 30, 20))); g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV")); g1.AddRule(new Rules.SingleLoaded("SL", "APT")); g1.AddRule(new Rules.DoubleLoaded("DL", "APT")); g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2")); Grammar g2 = new Grammar(); g2.name = "AptFormA"; g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false); g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false); g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false); g2.inputs.names.Add("APT"); g1.AddRule(g2); //g1.AddRule(new Rules.DivideTo("APT", "APTL", 4, 1)); //g1.AddRule(new Rules.DivideTo("APT2", "APTL", 4, 1)); g1.AddRule(new Rules.DcpFace2("APT", new string[] { "APT", "APT" })); g1.AddRule(new Rules.DcpFace2("APT2", new string[] { "APT", "APT" })); //g1.AddRule(new Rules.DivideToFTFH("APT2", "APTL", 4)); //g1.AddRule(new Rules.DivideToFTFH("APT", "APTL", 4)); //g1.AddRule(new Rules.DcpFace2("APTL", new string[] { "Top", "Side" })); g1.Execute(); SceneManager.SelectedGrammar = g1; }
public Grammar GA(bool addToScene = true) { Grammar g = new Grammar(addToScene); g.category = GraphNode.Category.Bd_Massing; g.inputs.names.Add("APT"); g.name = "AptFormA"; g.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false); g.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false); g.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false); return(g); }
public static Grammar OffStatic(ShapeObject so) { so.name = "A"; Grammar g1 = new Grammar(); g1.name = "g2"; g1.assignedObjects.Add(so); g1.AddRule(new Rules.SizeOffice3D("A", "A", so.Size), false); g1.AddRule(new Rules.OfficeFilter("A", "SL", "DL", "CV"), false); g1.AddRule(new Rules.SingleLoaded("SL", "APT"), false); g1.AddRule(new Rules.DoubleLoaded("DL", "APT"), false); g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false); return(g1); }
Grammar G2(ShapeObject so) { so.name = "A"; Grammar g1 = new Grammar(); g1.name = "g2"; g1.assignedObjects.Add(so); g1.AddRule(new Rules.SizeBuilding3D("A", "A", so.Size), false); g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"), false); g1.AddRule(new Rules.SingleLoaded("SL", "APT"), false); g1.AddRule(new Rules.DoubleLoaded("DL", "APT"), false); g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false); return(g1); }
private static Grammar InfiniteMovementGrammar1() { var voc = Vocabulary.GetVocabularyFromFile(@"..\..\..\Input\Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddRule(new Rule(1, "START", new[] { "NP" }, 0, 0)); grammar.AddRule(new Rule(1, "NP", new[] { "PP", "NP" }, 1, 0)); grammar.AddRule(new Rule(1, "PP", new[] { "NP", "PP" }, 1, 0)); grammar.AddRule(new Rule(1, "PP", new[] { "V2", "P" }, 1, 0)); var does = grammar.DoesGrammarAllowInfiniteMovement(); return(grammar); }
private void btnGerar_Click(object sender, EventArgs e) { g = new Grammar(); g.Variables.Clear(); g.Variables.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, false))); g.Terminals.Clear(); g.Terminals.AddRange(txtVariaveis.Text.Select(c => new Symbol(-1, c, true, c))); string[] regras = txtRegras.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < regras.Length; i++) { char variavel = regras[i].ToUpper()[0]; string prod = regras[i].Substring(2).Trim(); string[] prods = prod.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < prods.Length; j++) { var symbols = new SymbolList(); symbols = symbols.AddRange(prods[j].Select(prd => new Symbol(-1, prd, prd.IsTerminal(), prd))); g.AddRule(g.Variables.Find(variavel), symbols); } } }
public bool InsertRuleWithANewSymbol(Grammar grammar) { for (var i = 0; i < NumberOfRetries; i++) { var existingLHSNonTerminal = grammar.GetRandomRule().Name.NonTerminal; if (existingLHSNonTerminal == grammar.StartSymbol) { continue; } var newLHSNonTerminal = grammar.GetNextAvailableProjectionName(); var typeOfExistingLHS = grammar.NonTerminalsTypeDictionary[existingLHSNonTerminal]; grammar.AddProjectionTypeToTypeDictionary(newLHSNonTerminal, typeOfExistingLHS); //grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal, grammar.StartSymbol }, 0, 1)); // grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal }, 0, 0)); grammar.AddRule(new Rule(0, newLHSNonTerminal, new[] { existingLHSNonTerminal }, 0, 0)); return(true); } return(false); }
public Grammar GC(bool addToScene = true) { Grammar g = new Grammar(addToScene); g.category = GraphNode.Category.Bd_Massing; g.inputs.names.Add("APT"); g.name = "AptFormC"; //g2.AddRule(new Rules.Divide("APT", new string[] { "APT_A", "APT_B" }, new float[] { 0.2f, 0.6f, 0.2f }, 0), false); //g2.AddRule(new Rules.DivideTo("APT", "APT_B" , 8,0)); g.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.6f, 1), false); g.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.35f, 0), false); g.AddRule(new Rules.Scale3D("C", "C", new Vector3(1.05f, 1, 1.05f), null, Alignment.NE), false); g.AddRule(new Rules.BisectLength("C", new string[] { "C", "APT" }, 4, 1), false); g.AddRule(new Rules.Scale3D("C", "APT", new Vector3(0.8f, 1, 0.8f), null, Alignment.NE), false); return(g); }
public override void ExitRule_expression(CfgGramParser.Rule_expressionContext context) { var rule = RulesStack.Pop(); rule.Template = Template; rule.ExtensionType = ExtensionType; rule.ExtensionQuery = ExtensionQuery; if (rule.Template == null && rule.Items.Any(x => x.HasLocalName)) { var templItems = new List <TemplateItemBase>(); foreach (var item in rule.Items.Where(x => x.HasLocalName)) { var propMame = string.Join( string.Empty, item.LocalName .Split('_') .Select(x => x.First().ToString().ToUpper() + x.Substring(1) ) ); templItems.Add(new TemplateItem <(string, string)>(propMame, (item.LocalName, null), TemplateValueType.NameRef)); } rule.Template = new Template(templItems); } ExtensionType = null; ExtensionQuery = null; Grammar.AddRule(rule); }
public Grammar GenSite(ShapeObject initSo) { //#3 "position":0.19 //#5 "position":0.14 Grammar gs = new Grammar(); gs.inputs.shapes.Add(initSo); gs.name = "Site"; //gs.AddRule(new Rules.BisectMirror("A", new string[] { "A", "A" }, 0.45f, 1)); gs.AddRule(new Rules.Bisect("A", new string[] { "A", "C" }, 0.2f, 0)); gs.AddRule(new Rules.PivotMirror("C", "A", 0)); gs.AddRule(new Rules.Bisect("A", new string[] { "B", "C" }, 0.2f, 0)); gs.AddRule(new Rules.PivotTurn("C", "C", 1)); //gs.AddRule(new Rules.Divide("A", new string[] { "A" }, new float[] { 0.2f, 0.3f, 0.5f }, 0)); //gs.AddRule(new Rules.DivideTo("A", new string[] { "B", "C" }, 20f, 0)); return(gs); }
public Grammar GB(bool addToScene = true) { Grammar g = new Grammar(addToScene); g.category = GraphNode.Category.Bd_Massing; g.inputs.names.Add("APT"); g.name = "AptFormB"; g.AddRule(new Rules.DivideTo("APT", "APT", 30, 0)); g.AddRule(new Rules.Divide("APT", new string[] { "APT", "B" }, new float[] { 0.2f, 0.6f, 0.2f }, 0), false); //g2.AddRule(new Rules.DivideTo("APT", "APT_B" , 8,0)); //g2.AddRule(new Rules.PivotMirror("APT_B", "APT_B", 2)); g.AddRule(new Rules.Scale3D("B", "B", new Vector3(1f, 1.1f, 1.2f), null, Alignment.N), false); g.AddRule(new Rules.Bisect("B", new string[] { "B", "APT" }, 0.4f, 1), false); g.AddRule(new Rules.Scale3D("B", "APT", new Vector3(1.2f, 1f, 1.2f), null, Alignment.N), false); return(g); }
internal Grammar GetInitialGrammar() { var initialGrammar = new Grammar(voc); initialGrammar.NonTerminalsTypeDictionary = nonTerminalTypeDic; initialGrammar.POSTypes = posTypes; var posInText = voc.POSWithPossibleWords.Keys; foreach (var pos in posInText) { initialGrammar.AddRule(new Rule(1, initialGrammar.StartSymbol, new[] { pos, initialGrammar.StartSymbol }, 0, 1)); initialGrammar.AddRule(new Rule(1, initialGrammar.StartSymbol, new[] { pos }, 0, 0)); } return(initialGrammar); }
public static Grammar SimpleBubble() { var grammar = new Grammar(); grammar.name = "SimpleBubble"; { var initRule = new Rule(); initRule.name = "BULB"; var s1 = new Replacement(); s1.id = "WHEEL"; var s2 = new Replacement(); s2.id = "BULB"; s2.transform *= Matrix4x4.Translate(new Vector3(2f, 0, 0)); s2.transform *= Matrix4x4.Rotate(Quaternion.Euler(new Vector3(0, 0, 95))); s2.transform *= Matrix4x4.Scale(new Vector3(0.9f, 0.9f, 1f)); initRule.replacements = new[] { s1, s2 }; grammar.startShape = "BULB"; grammar.AddRule(initRule); } { var squareRule = new Rule(); squareRule.name = "WHEEL"; var s1 = new Replacement(); s1.SetCircle(); var s2 = new Replacement(); s2.SetCircle(); s2.color = new HsvColor() { v = 1 }; s2.transform *= Matrix4x4.Scale(new Vector3(0.9f, 0.9f, 1f)); squareRule.replacements = new[] { s1, s2 }; grammar.AddRule(squareRule); } return(grammar); }
private static Grammar InfiniteMovementGrammar2() { var voc = Vocabulary.GetVocabularyFromFile(@"..\..\..\Input\Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("CP", "V"); // no overt POS here, head of IP is V. grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] { "CP" }, 0, 0)); grammar.AddRule(new Rule(1, "CP", new[] { "NP", "IP" }, 1, 1)); grammar.AddRule(new Rule(1, "IP", new[] { "NP", "CP" }, 1, 1)); grammar.AddRule(new Rule(1, "PP", new[] { "V2", "P" }, 1, 0)); grammar.AddRule(new Rule(1, "NP", new[] { "D", "N" }, 1, 0)); var does = grammar.DoesGrammarAllowInfiniteMovement(); return(grammar); }
ShapeObject createBuilding() { ShapeObject so = SOPoint.CreatePoint(); Grammar g = new Grammar(); Building bp = new Building(); bp.AddGrammar(g); so.SetGrammar(g); float h = Random.Range(9, 80); float w = Random.Range(30, 50); float d = Random.Range(15, 25); if (h < 30) { w = Random.Range(40, 60); d = Random.Range(30, 50); } g.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20))); g.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(w, h, d))); g.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV")); g.AddRule(new Rules.SingleLoaded("SL", "APT")); g.AddRule(new Rules.DoubleLoaded("DL", "APT")); g.AddRule(new Rules.CentralVoid("CV", "APT", "APT2")); Grammar g2 = new Grammar(); g2.category = GraphNode.Category.Bd_Massing; g2.name = "AptFormA"; g2.inputs.names.Add("APT"); g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false); g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false); g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false); g.AddRule(g2); //g.AddRule(new Rules.ExtractFace(new string[] { "APT" }, "TOP", "TOP"), false); //g.AddRule(new Rules.DivideToFTFH("APT", "APTL", 4)); //g.AddRule(new Rules.DivideToFTFH("APT2", "APTL", 4)); //g.AddRule(new Rules.DcpA("A", 9, 3)); return(so); }
private static void TestAmbiguityGrammar() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddRule(new Rule(0, "START", new[] { "VP" }, 0, 0)); grammar.AddRule(new Rule(1, "VP", new[] { "V1", "NP" }, 0, 1)); grammar.AddRule(new Rule(1, "VP", new[] { "VP", "NP" }, 0, 0)); grammar.AddRule(new Rule(0, "NP", new[] { "NP", "NP" }, 0, 0)); var parser = new Parser(grammar, true); var n = parser.ParseSentence("kissed John David"); n.Print(); }
//generate a new rule from random existing productions. public bool InsertRule(Grammar grammar) { for (var i = 0; i < NumberOfRetries; i++) { var productions = new List <string>(); var randomDaughter = grammar.StartSymbol; while (randomDaughter == grammar.StartSymbol) { randomDaughter = grammar.GetRandomNonTerminal(); //the first daughter is never the start symbol. } productions.Add(randomDaughter); if (_rand.NextDouble() < 0.5f) { productions.Add(grammar.GetRandomNonTerminal()); } var newRule = new Rule(); newRule.Occurrences = 1; newRule.Production = productions.Select(x => new NonTerminalObject(x)).ToArray(); newRule.HeadPosition = _rand.Next(newRule.Production.Length); newRule.ComplementPosition = _rand.Next(newRule.Production.Length); if (newRule.HeadTerm == grammar.StartSymbol) { //never let the head be the start symbol. the start symbol can only be the second term(see above). newRule.HeadPosition = 0; } var ruleName = grammar.StartSymbol; if (_rand.NextDouble() < 0.9f) //90% probability of projecting regular head stucture. 10% allow to project to the START symbol. { try { ruleName = grammar.NonTerminalsTypeDictionary[newRule.HeadTerm] + "P"; } catch { throw new Exception(string.Format("rule head term not found", newRule.HeadTerm)); } } newRule.Name = new NonTerminalObject(ruleName); if (grammar.AreHeadRelationsConsistent(newRule)) { grammar.AddRule(newRule); return(true); } } return(false); }
// Use this for initialization void Start() { Vector3[] pts = new Vector3[5]; pts[0] = new Vector3(-80, 0, 46); pts[1] = new Vector3(-80, 0, -11); pts[2] = new Vector3(-10, 0, -54); pts[3] = new Vector3(103, 0, 25); pts[4] = new Vector3(96, 0, 70); Polyline pl = new Polyline(pts); Polygon pg = new Polygon(pts); Form f = pg.ExtrudeToForm(new Vector3(0, 30, 0)); ShapeObject init = ShapeObject.CreateMeshable(f); Grammar g1 = new Grammar(); g1.assignedObjects.Add(init); g1.AddRule(new Rules.Bisect("A", new string[] { "B", "C" }, 0.4f, 0), false); g1.AddRule(new Rules.Bisect("B", new string[] { "B", "C" }, 0.4f, 2), false); g1.AddRule(new Rules.Scale("C", "C", 1.5f, 1), false); g1.Execute(); }
private static void TestMovement2() { var voc = Vocabulary.GetVocabularyFromFile(@"Vocabulary.json"); var grammar = new Grammar(voc); Program.AddTypesToGrammar(grammar); grammar.AddProjectionTypeToTypeDictionary("CP", "V"); // no overt POS here, head of IP is V. grammar.AddProjectionTypeToTypeDictionary("IP", "V"); // no overt POS here, head of IP is V. grammar.AddRule(new Rule(1, "START", new[] { "VP", "VP" }, 1, 1)); grammar.AddRule(new Rule(1, "VP", new[] { "VP", "PP" }, 0, 1)); grammar.AddRule(new Rule(1, "VP", new[] { "NP", "V1" }, 1, 0)); grammar.AddRule(new Rule(1, "PP", new[] { "V2", "P" }, 1, 0)); grammar.AddRule(new Rule(1, "NP", new[] { "D", "N" }, 1, 0)); var parser = new Parser(grammar, true); var n = parser.ParseSentence("the man arrived to Mary"); //supposed to fail in parsing!! n.Print(); }
public Grammar JsPollock(ShapeObject initSo) { Grammar gs = new Grammar(); gs.inputs.shapes.Add(initSo); gs.name = "Site"; //gs.AddRule(new Rules.BisectMirror("A", new string[] { "A", "A" }, 0.45f, 1)); gs.AddRule(new Rules.DivideTo("A", new string[] { "A", "B" }, 60, 0)); gs.AddRule(new Rules.PivotTurn("B", "A", 2)); for (int i = 0; i < 3; i++) { int orientation = (i + 1) % 2; if (orientation == 1) { orientation = 2; } gs.AddRule(new Rules.Bisect("A", new string[] { "B", "A" }, 0.4f, orientation)); gs.AddRule(new Rules.PivotTurn("B", "A", 2)); //gs.AddRule(new Rules.Bisect("A", new string[] { "B", "A" }, 0.4f, 2)); //gs.AddRule(new Rules.PivotTurn("B", "A", 2)); } gs.AddRule(new Rules.NamesByAreaEdges("A", "Building", 800, 4)); gs.AddRule(new Rules.Scale3D("Building", "Building", new Vector3(1, 25, 1), new Vector2(-0.2f, 0.1f))); //gs.AddRule(new Rules.DcpA("Building", 6, 3)); //gs.AddRule(new Rules.BisectLength("Building", new string[] { "Tower", "Podium"}, 20, 2)); //gs.AddRule(new Rules.Scale3D("Tower", "Tower", new Vector3(0.6f, 3, 1))); //gs.AddRule(new Rules.DubTop("Building")); return(gs); }
public void updateDesign() { if (initShape == null) { initShape = ShapeObject.CreateBasic(); } Polygon pg = new Polygon(boundaryPts); initShape.SetMeshable(pg); if (grammar == null) { grammar = new Grammar(); grammar.inputs.shapes.Add(initShape); grammar.AddRule(new Rules.PivotTurn("A", "A", 2)); grammar.AddRule(new Rules.DivideTo("A", new string[] { "A", "B" }, 30, 2), false); grammar.AddRule(new Rules.DivideTo("A", new string[] { "A", "A" }, 60, 0), false); grammar.AddRule(new Rules.Hide(new string[] { "B" }), false); grammar.AddRule(new Rules.Extrude("A", "A", 30), false); grammar.AddRule(new Rules.CreateBuilding("A", pm3, particleSystem), false); } grammar.Execute(); }
// Use this for initialization void Start() { Vector3[] pts = initShape2(); ShapeObject so = ShapeObject.CreateExtrusion(pts, 30); Grammar g1 = new Grammar(); g1.inputs.shapes.Add(so); g1.AddRule(new Rules.Scale3D("A", "A", new Vector3(1, 1, 1))); Properties buildingA = new BuildingProperties(); buildingA.AddGrammar(g1); }
private CompilerFuzzy Compiler4() { //LR(1) //0. S //0 → S$ //1. S → V = E //2. S → E //3. E → V //4. V → x //5. V → ∗E List <RecognitionToken> recs = new List <RecognitionToken>(); var requal = new RecognitionToken(1, "equal", "=", "#7bf6b6", norm, conorm); var rast = new RecognitionToken(2, "ast", "*", "#f28686", norm, conorm); var rx = new RecognitionToken(3, "x", "x", "#fbdb65", norm, conorm); recs.Add(requal); recs.Add(rast); recs.Add(rx); Grammar grammar = new Grammar(); var x = new Symbol(1, "x", true, 'x'); x.SetCustomValue("RecToken", rx); var ast = new Symbol(2, "*", true, '*'); ast.SetCustomValue("RecToken", rast); var equal = new Symbol(3, "=", true, '='); equal.SetCustomValue("RecToken", requal); var S = new Symbol(4, "S", false); var V = new Symbol(5, "V", false); var V1 = new Symbol(7, "V1", false); var E = new Symbol(6, "E", false); grammar.Terminals.AddRange(new SymbolList(x, ast, equal)); grammar.Variables.AddRange(new SymbolList(S, V, E, V1)); grammar.VariableStart = S; grammar.AddRule(S, V, equal, E); grammar.AddRule(S, E); grammar.AddRule(E, V); grammar.AddRule(E, V1).Pertinence = 0.8; var ruleV = grammar.AddRule(V, x); grammar.AddRule(V1, equal).Parent = ruleV; grammar.AddRule(V, ast, E); return(new CompilerFuzzy(recs, grammar, null, null, norm, conorm)); }