Beispiel #1
0
 public ruleSet copy()
 {
     ruleSet copyOfRuleSet = new ruleSet();
     foreach (string a in applySourceFiles)
         copyOfRuleSet.applySourceFiles.Add(a);
     foreach (string a in recognizeSourceFiles)
         copyOfRuleSet.recognizeSourceFiles.Add(a);
     copyOfRuleSet.choiceMethod = choiceMethod;
     copyOfRuleSet.finalCandidates = finalCandidates;
     copyOfRuleSet.generationAfterChoice = generationAfterChoice;
     copyOfRuleSet.generationAfterCycleLimit = generationAfterCycleLimit;
     copyOfRuleSet.generationAfterNormal = generationAfterNormal;
     copyOfRuleSet.generationAfterNoRules = generationAfterNoRules;
     copyOfRuleSet.generationAfterTriggerRule = generationAfterTriggerRule;
     copyOfRuleSet.interimCandidates = interimCandidates;
     copyOfRuleSet.name = name;
     foreach (string a in ruleFileNames)
         copyOfRuleSet.ruleFileNames.Add(a);
     foreach (grammarRule a in rules)
         copyOfRuleSet.rules.Add(a);
     copyOfRuleSet.rulesDir = rulesDir;
     copyOfRuleSet.ruleSetIndex = ruleSetIndex;
     copyOfRuleSet.triggerRuleNum = triggerRuleNum;
     return copyOfRuleSet;
 }
        /// <summary>
        ///   Returns a copy of this instance.
        /// </summary>
        /// <returns></returns>
        public ruleSet copy()
        {
            var copyOfRuleSet = new ruleSet();

            foreach (var a in applySourceFiles)
            {
                copyOfRuleSet.applySourceFiles.Add(a);
            }
            foreach (var a in recognizeSourceFiles)
            {
                copyOfRuleSet.recognizeSourceFiles.Add(a);
            }
            copyOfRuleSet.choiceMethod               = choiceMethod;
            copyOfRuleSet.finalCandidates            = finalCandidates;
            copyOfRuleSet.generationAfterChoice      = generationAfterChoice;
            copyOfRuleSet.generationAfterCycleLimit  = generationAfterCycleLimit;
            copyOfRuleSet.generationAfterNormal      = generationAfterNormal;
            copyOfRuleSet.generationAfterNoRules     = generationAfterNoRules;
            copyOfRuleSet.generationAfterTriggerRule = generationAfterTriggerRule;
            copyOfRuleSet.interimCandidates          = interimCandidates;
            copyOfRuleSet.name = name;
            foreach (var a in ruleFileNames)
            {
                copyOfRuleSet.ruleFileNames.Add(a);
            }
            foreach (var a in rules)
            {
                copyOfRuleSet.rules.Add(a);
            }
            copyOfRuleSet.rulesDir       = rulesDir;
            copyOfRuleSet.RuleSetIndex   = RuleSetIndex;
            copyOfRuleSet.TriggerRuleNum = TriggerRuleNum;
            return(copyOfRuleSet);
        }
        public ruleSetDisplay(ruleSet rules, string formTitle)
        {
            this.MdiParent = Program.main;
            InitializeComponent();

            ruleset = rules;
            this.Text = formTitle;

            rules.initPropertiesBag();
            this.propertyGrid1.SelectedObject = rules.Bag;
            this.GotFocus += new EventHandler(ruleSetDisplay_Enter);
            this.Enter += new EventHandler(ruleSetDisplay_Enter);
        }
 public static void saveRuleSetToXml(string filename, ruleSet rules)
 {
     StreamWriter ruleWriter = null;
     try
     {
         ruleWriter = new StreamWriter(filename);
         XmlSerializer ruleSerializer = new XmlSerializer(typeof(ruleSet));
         ruleSerializer.Serialize(ruleWriter, rules);
     }
     catch (Exception ioe)
     {
         MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     finally
     {
         if (ruleWriter != null) ruleWriter.Close();
     }
 }
Beispiel #5
0
        public static ruleSet openRuleSetFromXml(string filename, nextGenerationSteps[] defaultGenSteps)
        {
            ruleSet      newRuleSet = null;
            StreamReader ruleReader = null;

            try
            {
                ruleReader = new StreamReader(filename);
                XmlSerializer ruleDeserializer = new XmlSerializer(typeof(ruleSet));
                newRuleSet = (ruleSet)ruleDeserializer.Deserialize(ruleReader);
                SearchIO.output(Path.GetFileName(filename) + " successfully loaded.");
                newRuleSet.rulesDir = Path.GetDirectoryName(filename) + "\\";
                newRuleSet.loadRulesFromFileNames();
                newRuleSet.initializeFileWatcher(newRuleSet.rulesDir);
                if (newRuleSet.name == null)
                {
                    newRuleSet.name = Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x',
                                                                                      'm', 'l' });
                }

                for (int i = 0; i != 5; i++)
                {
                    if (newRuleSet.nextGenerationStep[i] == nextGenerationSteps.Unspecified)
                    {
                        newRuleSet.nextGenerationStep[i] = defaultGenSteps[i];
                    }
                }
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            finally
            {
                if (ruleReader != null)
                {
                    ruleReader.Close();
                }
            }

            return(newRuleSet);
        }
Beispiel #6
0
        public static void saveRuleSetToXml(string filename, ruleSet rules)
        {
            StreamWriter ruleWriter = null;

            try
            {
                ruleWriter = new StreamWriter(filename);
                XmlSerializer ruleSerializer = new XmlSerializer(typeof(ruleSet));
                ruleSerializer.Serialize(ruleWriter, rules);
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                if (ruleWriter != null)
                {
                    ruleWriter.Close();
                }
            }
        }
Beispiel #7
0
        public static Boolean CompileSourceFiles(ruleSet[] rulesets, List<string> allSourceFiles,
            out CompilerResults cr, string rulesDir, string execDir, string compiledparamRules)
        {
            cr = null;
            try
            {
                CSharpCodeProvider c = new CSharpCodeProvider();
               // c.CreateCompiler();
            //                ICodeCompiler icc = c.CreateCompiler();
                CompilerParameters cp = new CompilerParameters();

                cp.ReferencedAssemblies.Add("system.dll");
                cp.ReferencedAssemblies.Add("system.xml.dll");
                cp.ReferencedAssemblies.Add("system.data.dll");
                cp.ReferencedAssemblies.Add("system.windows.forms.dll");
                cp.ReferencedAssemblies.Add(execDir + "GraphSynth.exe");
                cp.ReferencedAssemblies.Add(execDir + "Representation.dll");

                cp.CompilerOptions = "/t:library";
                cp.GenerateInMemory = true;
                cp.OutputAssembly = rulesDir + compiledparamRules;
                string[] allSourceFilesArray = allSourceFiles.ToArray();

                cr = c.CompileAssemblyFromFile(cp, allSourceFilesArray);

                //cr = icc.CompileAssemblyFromFileBatch(cp, allSourceFilesArray);
                if (cr.Errors.Count > 0) throw new Exception();
                else return true;
            }
            catch
            {
                MessageBox.Show("Error Compiling C# recognize and apply source files.",
                    "Compilation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (CompilerError e in cr.Errors)
                    SearchIO.output(e.ToString(), 1);
                return false;
            }
        }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply, Boolean _display,
      Boolean recompileRules, string execDir, string compiledparamRules)
     :
     this(_seed, _rulesets, null, _display, recompileRules, execDir, compiledparamRules)
 {
     maxNumOfCalls = new int[numOfRuleSets];
     for (int i = 0; i != numOfRuleSets; i++)
         maxNumOfCalls[i] = _maxRulesToApply;
 }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls)
     : this(_seed, _rulesets, _maxNumOfCalls, false) { }
Beispiel #10
0
        public static Boolean FindSourceFiles(ruleSet[] rulesets, List<string> allSourceFiles,
            string rulesDirectory)
        {
            Boolean filesFound = true;

            foreach (ruleSet a in rulesets)
            {
                foreach (string file in a.recognizeSourceFiles)
                {
                    if (File.Exists(rulesDirectory + file))
                        allSourceFiles.Add(rulesDirectory + file);
                    else
                    {
                        MessageBox.Show("Missing source file: " + file +
                            ". Cancelling compilation of C# recognize source file.",
                            "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        filesFound = false;
                        break;
                    }
                }
                foreach (string file in a.applySourceFiles)
                {
                    if (File.Exists(rulesDirectory + file))
                        allSourceFiles.Add(rulesDirectory + file);
                    else
                    {
                        MessageBox.Show("Missing source file: " + file +
                            ". Cancelling compilation of C# apply source file.",
                            "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        filesFound = false;
                        break;
                    }
                }
            }
            if (allSourceFiles.Count == 0) filesFound = false;
            return filesFound;
        }
Beispiel #11
0
 private static Boolean compiledFunctionsAlreadyLoaded(ruleSet[] rulesets)
 {
     foreach (ruleSet set in rulesets)
         if (set != null)
         {
             foreach (grammarRule rule in set.rules)
                 if (rule.recognizeFuncs.Count + rule.applyFuncs.Count !=
                     rule.recognizeFunctions.Count + rule.applyFunctions.Count)
                     return false;
         }
     return true;
 }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply, Boolean _display)
     : base(_seed, _rulesets, _maxRulesToApply, _display) { }
Beispiel #13
0
 public void addAndShowRuleSetDisplay(ruleSet rs, string title)
 {
     ruleSetDisplays.Add(new ruleSetDisplay(rs, title));
     ruleSetDisplays[ruleSetChildCount].Show();
 }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls)
     : base(_seed, _rulesets, _maxNumOfCalls, false) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, Boolean _display)
     : base(_seed, _rulesets, -1, _display) { }
        /* a constructor like these are needed to invoke the main constructor in RecognizeChooseApply.cs */
        public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply,
            Boolean recompileRules, string execDir, string compiledparamRules)
            : base(_seed, _rulesets, _maxRulesToApply, false, recompileRules, execDir,
compiledparamRules) { }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets)
     : this(_seed, _rulesets, -1, false) { }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, Boolean _display)
     : this(_seed, _rulesets, -1, _display) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display,
      Boolean recompileRules, string execDir, string compiledparamRules)
     : base(_seed, _rulesets, _maxNumOfCalls, _display, recompileRules, execDir, compiledparamRules) { }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply)
     : this(_seed, _rulesets, _maxRulesToApply, false) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets)
     : base(_seed, _rulesets, -1, false) { }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply, Boolean _display)
     : this(_seed, _rulesets, null, _display)
 {
     maxNumOfCalls = new int[numOfRuleSets];
     for (int i = 0; i != numOfRuleSets; i++)
         maxNumOfCalls[i] = _maxRulesToApply;
 }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply)
     : base(_seed, _rulesets, _maxRulesToApply, false) { }
 public RecognizeChooseApply(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display)
 {
     SearchIO.output("initializing generation:", 4);
     this.numOfRuleSets = _rulesets.GetLength(0);
     this.rulesets = new ruleSet[numOfRuleSets];
     for (int i = 0; i != numOfRuleSets; i++)
         rulesets[i] = _rulesets[i].copy();
     SearchIO.output("There are " + numOfRuleSets + " rule sets.", 4);
     this.seed = new candidate(_seed.copy(), numOfRuleSets);
     SearchIO.output("Seed = " + seed.graph.name, 4);
     maxNumOfCalls = _maxNumOfCalls;
     this.display = _display;
     SearchIO.output("It is " + display.ToString() + " that the SearchIO will be displayed.", 4);
 }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display)
     : base(_seed, _rulesets, _maxNumOfCalls, _display) { }
Beispiel #26
0
        public static void loadAndCompileSourceFiles(ruleSet[] rulesets, Boolean recompileRules, 
            string compiledparamRules, string execDir)
        {
            object compiledFunctions = null;
            List<string> allSourceFiles = new List<string>();
            CompilerResults cr = null;
            string rulesDirectory = rulesets[0].rulesDir;

            if (compiledFunctionsAlreadyLoaded(rulesets)) return;
            try
            {
                if (recompileRules)
                {
                    if (FindSourceFiles(rulesets, allSourceFiles, rulesDirectory))
                    {
                        if (CompileSourceFiles(rulesets, allSourceFiles, out cr,
                            rulesDirectory, execDir, compiledparamRules))
                        {
                            System.Reflection.Assembly a = cr.CompiledAssembly;
                            compiledFunctions = a.CreateInstance("GraphSynth.ParamRules.ParamRules");
                        }
                    }
                }
                else
                {
                    /* load .dll since compilation crashed */
                    string[] filename = Directory.GetFiles(rulesDirectory, "*"
                        + compiledparamRules + "*");
                    if (filename.GetLength(0) > 1)
                        throw new Exception("More than one compiled library (*.dll) similar to "
                            + compiledparamRules + "in" + rulesDirectory);
                    else if (filename.GetLength(0) == 0)
                        throw new Exception("Compiled library: "
                            + compiledparamRules + "not found in" + rulesDirectory);
                    else
                        compiledFunctions = Assembly.Load(filename[0]);
                }
                if (compiledFunctions != null)
                {
                    Type t = compiledFunctions.GetType();
                    foreach (ruleSet set in rulesets)
                        foreach (grammarRule rule in set.rules)
                        {
                            rule.DLLofFunctions = compiledFunctions;
                            foreach (string function in rule.recognizeFunctions)
                                rule.recognizeFuncs.Add(t.GetMethod(function));
                            foreach (string function in rule.applyFunctions)
                                rule.applyFuncs.Add(t.GetMethod(function));
                        }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Compilation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }