Exemplo n.º 1
0
		/// <summary>
		/// Do whatever it takes to convert the input this processor knows about.
		/// </summary>
		public void Convert()
		{
			using (FWConverterDlg dlg = new FWConverterDlg())
			{
				dlg.ShowDialog();
				if (dlg.DialogResult == DialogResult.OK)
				{
					string catInfo = dlg.CatInfo;
					if (catInfo != null)
					{
						SqlConnection con = null;
						try
						{
							// 0 is the category id.
							// 1 is the entire connection string.
							string[] parts = catInfo.Split('^');
							con = new SqlConnection(parts[1]);
							con.Open();
							using (SqlCommand cmd = con.CreateCommand())
							{
								cmd.CommandType = CommandType.Text;
								string catIdQry;
								if (dlg.IncludeSubcategories)
								{
									catIdQry = string.Format("IN ({0}", parts[0]);
									cmd.CommandText = "SELECT Id\n" +
										string.Format("FROM fnGetOwnedIds({0}, 7004, 7004)", parts[0]);
									using (SqlDataReader reader = cmd.ExecuteReader())
									{
										while (reader.Read())
											catIdQry += string.Format(", {0}", reader.GetInt32(0));
									}
									catIdQry += ")";
								}
								else
								{
									catIdQry = string.Format("= {0}", parts[0]);
								}
								cmd.CommandText =
									"SELECT anal.Owner$ AS Wf_Id,\n" +
									"	anal.Id AS Anal_Id,\n" +
									"	mb.OwnOrd$ AS Mb_Ord,\n" +
									"	Mb.Sense AS Mb_Sense,\n" +
									"	mb.Morph AS Mb_Morph,\n" +
									"	mb.Msa AS Mb_Msa, msa.Class$ AS Msa_Class\n" +
									"FROM WfiAnalysis_ anal\n" +
									"--) Only use those that are human approved\n" +
									"JOIN CmAgentEvaluation eval ON eval.Target = anal.Id\n" +
									"JOIN CmAgent agt ON agt.Human = 1\n" +
									"JOIN CmAgent_Evaluations j_agt_eval ON agt.Id = j_agt_eval.Src AND j_agt_eval.Dst = eval.Id\n" +
									"--) Get morph bundles\n" +
									"JOIN WfiMorphBundle_ mb ON mb.Owner$ = anal.Id\n" +
									"--) Get MSA class\n" +
									"LEFT OUTER JOIN MoMorphSynAnalysis_ msa ON mb.msa = msa.Id\n" +
									String.Format("WHERE anal.Category {0} AND eval.Accepted = 1\n", catIdQry) +
									"ORDER BY anal.Owner$, anal.Id, mb.OwnOrd$";
								List<FwWordform> wordforms = new List<FwWordform>();
								using (SqlDataReader reader = cmd.ExecuteReader())
								{
									bool moreRows = reader.Read();
									while (moreRows)
									{
										/*
										 * Return values, in order are:
										 *	Wordform Id: int: 0
										 *	Analysis Id: int: 1
										 *	MorphBundle Ord: int: 2
										 *	Sense Id: int: 3
										 *	MoForm Id: int: 4
										 *	MSA Id: int: 5
										 *	MSA Class: int: 6
										*/
										FwWordform wordform = new FwWordform();
										moreRows = wordform.LoadFromDB(reader);
										wordforms.Add(wordform);
									}
								}
								// Convert all of the wordforms.
								Dictionary<string, FwMsa> prefixes = new Dictionary<string, FwMsa>();
								Dictionary<string, List<FwMsa>> stems = new Dictionary<string, List<FwMsa>>();
								Dictionary<string, FwMsa> suffixes = new Dictionary<string, FwMsa>();
								foreach (FwWordform wf in wordforms)
									wf.Convert(cmd, m_gd, prefixes, stems, suffixes);
							}
						}
						catch
						{
							// Eat exceptions.
						}
						finally
						{
							if (con != null)
								con.Close();
						}

						// Handle the processing and transforming here.
						string outputPathname = null;
						try
						{
							// Main processing.
							PositionAnalyzer anal = new PositionAnalyzer();
							anal.Process(m_gd);

							// Strip out all the _#### here.
							foreach (WordRecord wr in m_gd.WordRecords)
							{
								if (wr.Prefixes != null)
								{
									foreach (Affix afx in wr.Prefixes)
										afx.MIDREF = EatIds(afx.MIDREF);
								}

								wr.Stem.MIDREF = EatIds(wr.Stem.MIDREF);

								if (wr.Suffixes != null)
								{
									foreach (Affix afx in wr.Suffixes)
										afx.MIDREF = EatIds(afx.MIDREF);
								}
							}
							foreach (Morpheme morph in m_gd.Morphemes)
							{
								morph.MID = EatIds(morph.MID);
							}

							// Save, so it can be transformed.
							outputPathname = Path.GetTempFileName() + ".xml"; ;
							m_gd.SaveData(outputPathname);

							// Transform.
							XslCompiledTransform trans = new XslCompiledTransform();
							try
							{
								trans.Load(XSLPathname);
							}
							catch
							{
								MessageBox.Show("Could not load the XSL file.", "Information");
								return;
							}

							string htmlOutput = Path.GetTempFileName() + ".html";
							try
							{
								trans.Transform(outputPathname, htmlOutput);
							}
							catch
							{
								MessageBox.Show("Could not transform the input file.", "Information");
								return;
							}
							Process.Start(htmlOutput);
						}
						catch
						{
							// Eat exceptions.
						}
						finally
						{
							if (outputPathname != null && File.Exists(outputPathname))
								File.Delete(outputPathname);
						}
					}
				}
			}

			// Reset m_gd, in case it gets called for another file.
			m_gd = GAFAWSData.Create();
		}
Exemplo n.º 2
0
        /// <summary>
        /// Do whatever it takes to convert the input this processor knows about.
        /// </summary>
        public void Convert()
        {
            using (FWConverterDlg dlg = new FWConverterDlg())
            {
                dlg.ShowDialog();
                if (dlg.DialogResult == DialogResult.OK)
                {
                    string catInfo = dlg.CatInfo;
                    if (catInfo != null)
                    {
                        SqlConnection con = null;
                        try
                        {
                            // 0 is the category id.
                            // 1 is the entire connection string.
                            string[] parts = catInfo.Split('^');
                            con = new SqlConnection(parts[1]);
                            con.Open();
                            using (SqlCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandType = CommandType.Text;
                                string catIdQry;
                                if (dlg.IncludeSubcategories)
                                {
                                    catIdQry        = string.Format("IN ({0}", parts[0]);
                                    cmd.CommandText = "SELECT Id\n" +
                                                      string.Format("FROM fnGetOwnedIds({0}, 7004, 7004)", parts[0]);
                                    using (SqlDataReader reader = cmd.ExecuteReader())
                                    {
                                        while (reader.Read())
                                        {
                                            catIdQry += string.Format(", {0}", reader.GetInt32(0));
                                        }
                                    }
                                    catIdQry += ")";
                                }
                                else
                                {
                                    catIdQry = string.Format("= {0}", parts[0]);
                                }
                                cmd.CommandText =
                                    "SELECT anal.Owner$ AS Wf_Id,\n" +
                                    "	anal.Id AS Anal_Id,\n"+
                                    "	mb.OwnOrd$ AS Mb_Ord,\n"+
                                    "	Mb.Sense AS Mb_Sense,\n"+
                                    "	mb.Morph AS Mb_Morph,\n"+
                                    "	mb.Msa AS Mb_Msa, msa.Class$ AS Msa_Class\n"+
                                    "FROM WfiAnalysis_ anal\n" +
                                    "--) Only use those that are human approved\n" +
                                    "JOIN CmAgentEvaluation eval ON eval.Target = anal.Id\n" +
                                    "JOIN CmAgent agt ON agt.Human = 1\n" +
                                    "JOIN CmAgent_Evaluations j_agt_eval ON agt.Id = j_agt_eval.Src AND j_agt_eval.Dst = eval.Id\n" +
                                    "--) Get morph bundles\n" +
                                    "JOIN WfiMorphBundle_ mb ON mb.Owner$ = anal.Id\n" +
                                    "--) Get MSA class\n" +
                                    "LEFT OUTER JOIN MoMorphSynAnalysis_ msa ON mb.msa = msa.Id\n" +
                                    String.Format("WHERE anal.Category {0} AND eval.Accepted = 1\n", catIdQry) +
                                    "ORDER BY anal.Owner$, anal.Id, mb.OwnOrd$";
                                List <FwWordform> wordforms = new List <FwWordform>();
                                using (SqlDataReader reader = cmd.ExecuteReader())
                                {
                                    bool moreRows = reader.Read();
                                    while (moreRows)
                                    {
                                        /*
                                         * Return values, in order are:
                                         *	Wordform Id: int: 0
                                         *	Analysis Id: int: 1
                                         *	MorphBundle Ord: int: 2
                                         *	Sense Id: int: 3
                                         *	MoForm Id: int: 4
                                         *	MSA Id: int: 5
                                         *	MSA Class: int: 6
                                         */
                                        FwWordform wordform = new FwWordform();
                                        moreRows = wordform.LoadFromDB(reader);
                                        wordforms.Add(wordform);
                                    }
                                }
                                // Convert all of the wordforms.
                                Dictionary <string, FwMsa>         prefixes = new Dictionary <string, FwMsa>();
                                Dictionary <string, List <FwMsa> > stems    = new Dictionary <string, List <FwMsa> >();
                                Dictionary <string, FwMsa>         suffixes = new Dictionary <string, FwMsa>();
                                foreach (FwWordform wf in wordforms)
                                {
                                    wf.Convert(cmd, m_gd, prefixes, stems, suffixes);
                                }
                            }
                        }
                        catch
                        {
                            // Eat exceptions.
                        }
                        finally
                        {
                            if (con != null)
                            {
                                con.Close();
                            }
                        }

                        // Handle the processing and transforming here.
                        string outputPathname = null;
                        try
                        {
                            // Main processing.
                            PositionAnalyzer anal = new PositionAnalyzer();
                            anal.Process(m_gd);

                            // Strip out all the _#### here.
                            foreach (WordRecord wr in m_gd.WordRecords)
                            {
                                if (wr.Prefixes != null)
                                {
                                    foreach (Affix afx in wr.Prefixes)
                                    {
                                        afx.MIDREF = EatIds(afx.MIDREF);
                                    }
                                }

                                wr.Stem.MIDREF = EatIds(wr.Stem.MIDREF);

                                if (wr.Suffixes != null)
                                {
                                    foreach (Affix afx in wr.Suffixes)
                                    {
                                        afx.MIDREF = EatIds(afx.MIDREF);
                                    }
                                }
                            }
                            foreach (Morpheme morph in m_gd.Morphemes)
                            {
                                morph.MID = EatIds(morph.MID);
                            }

                            // Save, so it can be transformed.
                            outputPathname = Path.GetTempFileName() + ".xml";;
                            m_gd.SaveData(outputPathname);

                            // Transform.
                            XslCompiledTransform trans = new XslCompiledTransform();
                            try
                            {
                                trans.Load(XSLPathname);
                            }
                            catch
                            {
                                MessageBox.Show("Could not load the XSL file.", "Information");
                                return;
                            }

                            string htmlOutput = Path.GetTempFileName() + ".html";
                            try
                            {
                                trans.Transform(outputPathname, htmlOutput);
                            }
                            catch
                            {
                                MessageBox.Show("Could not transform the input file.", "Information");
                                return;
                            }
                            Process.Start(htmlOutput);
                        }
                        catch
                        {
                            // Eat exceptions.
                        }
                        finally
                        {
                            if (outputPathname != null && File.Exists(outputPathname))
                            {
                                File.Delete(outputPathname);
                            }
                        }
                    }
                }
            }

            // Reset m_gd, in case it gets called for another file.
            m_gd = GAFAWSData.Create();
        }