コード例 #1
0
        private string ApplyGafawsAlgorithm(string gafawsFile)
        {
            var    pa = new PositionAnalyzer();
            string gafawsInputFile = Path.Combine(Path.GetTempPath(), gafawsFile);

            return(pa.Process(gafawsInputFile));
        }
コード例 #2
0
        protected string ApplyGafawsAlgorithm(string sGafawsFile)
        {
            var    pa = new PositionAnalyzer();
            string sGafawsInputFile = Path.Combine(m_outputDirectory, sGafawsFile);

            return(pa.Process(sGafawsInputFile));
        }
コード例 #3
0
		private string ApplyGafawsAlgorithm(string gafawsFile)
		{
			var pa = new PositionAnalyzer();
			string gafawsInputFile = Path.Combine(Path.GetTempPath(), gafawsFile);
			return pa.Process(gafawsInputFile);
		}
コード例 #4
0
ファイル: FWConverter.cs プロジェクト: sillsdev/WorldPad
        /// <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();
        }
コード例 #5
0
ファイル: ANAConverter.cs プロジェクト: sillsdev/WorldPad
        /// <summary>
        /// Do whatever it takes to convert the input this processor knows about.
        /// </summary>
        public void Convert()
        {
            using (ANAConverterDlg dlg = new ANAConverterDlg())
            {
                dlg.ShowDialog();
                if (dlg.DialogResult == DialogResult.OK)
                {
                    string outputPathname     = null;
                    string parametersPathname = null;
                    try
                    {
                        parametersPathname = dlg.ParametersPathname;
                        string anaPathname = dlg.ANAPathname;
                        using (StreamReader reader = new StreamReader(anaPathname))                         // Client to catch any exception.
                        {
                            ANARecord record = null;
                            string    line   = reader.ReadLine();
                            ANARecord.SetParameters(parametersPathname);
                            ANAObject.DataLayer = m_gd;

                            // Sanity checks.
                            if (line == null)
                            {
                                ThrowFileLoadException(reader, anaPathname, "ANA File is empty");
                            }

                            while (!line.StartsWith("\\a"))
                            {
                                line = line.Trim();
                                if ((line != "") || ((line = reader.ReadLine()) == null))
                                {
                                    ThrowFileLoadException(reader, anaPathname, "Does not appear to be an ANA file.");
                                }
                            }

                            while (line != null)
                            {
                                switch (line.Split()[0])
                                {
                                case "\\a":
                                {
                                    if (record != null)
                                    {
                                        record.Convert();
                                    }
                                    record = new ANARecord(line.Substring(3));
                                    break;
                                }

                                case "\\w":
                                {
                                    record.ProcessWLine(line.Substring(3));
                                    break;
                                }

                                case "\\u":
                                {
                                    record.ProcessOtherLine(LineType.kUnderlyingForm, line.Substring(3));
                                    break;
                                }

                                case "\\d":
                                {
                                    record.ProcessOtherLine(LineType.kDecomposition, line.Substring(3));
                                    break;
                                }

                                case "\\cat":
                                {
                                    record.ProcessOtherLine(LineType.kCategory, line.Substring(5));
                                    break;
                                }

                                default:
                                    // Eat this line.
                                    break;
                                }
                                line = reader.ReadLine();
                            }
                            Debug.Assert(record != null);
                            record.Convert();                             // Process last record.
                        }

                        // Main processing.
                        PositionAnalyzer anal = new PositionAnalyzer();
                        anal.Process(m_gd);

                        // Do any post-analysis processing here, if needed.
                        // End of any optional post-processing.

                        // Save, so it can be transformed.
                        outputPathname = GetOutputPathname(anaPathname);
                        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);
                    }
                    finally
                    {
                        if (parametersPathname != null && File.Exists(parametersPathname))
                        {
                            File.Delete(parametersPathname);
                        }
                        if (outputPathname != null && File.Exists(outputPathname))
                        {
                            File.Delete(outputPathname);
                        }
                    }
                }
            }

            // Reset m_gd, in case it gets called for another file.
            m_gd = GAFAWSData.Create();
        }
コード例 #6
0
        /// <summary>
        /// Do whatever it takes to convert the input this processor knows about.
        /// </summary>
        public void Convert()
        {
            string outputPathname = null;

            OpenFileDialog openFileDlg = new OpenFileDialog();

            openFileDlg.InitialDirectory = "c:\\";
            openFileDlg.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDlg.FilterIndex      = 2;
            openFileDlg.Multiselect      = false;

            if (openFileDlg.ShowDialog() == DialogResult.OK)
            {
                string sourcePathname = openFileDlg.FileName;
                if (File.Exists(sourcePathname))
                {
                    // Try to convert it.
                    using (StreamReader reader = new StreamReader(sourcePathname))
                    {
                        string line = reader.ReadLine();
                        Dictionary <string, bool> dictPrefixes = new Dictionary <string, bool>();
                        Dictionary <string, bool> dictStems    = new Dictionary <string, bool>();
                        Dictionary <string, bool> dictSuffixes = new Dictionary <string, bool>();
                        while (line != null)
                        {
                            line = line.Trim();
                            if (line != String.Empty)
                            {
                                int openAngleLocation = line.IndexOf("<", 0);
                                if (openAngleLocation < 0)
                                {
                                    continue;
                                }
                                int closeAngleLocation = line.IndexOf(">", openAngleLocation + 1);
                                if (closeAngleLocation < 0)
                                {
                                    continue;
                                }
                                WordRecord wrdRec = new WordRecord();
                                m_gd.WordRecords.Add(wrdRec);

                                // Handle prefixes, if any.
                                string prefixes = null;
                                if (openAngleLocation > 0)
                                {
                                    prefixes = line.Substring(0, openAngleLocation);
                                }
                                if (prefixes != null)
                                {
                                    if (wrdRec.Prefixes == null)
                                    {
                                        wrdRec.Prefixes = new List <Affix>();
                                    }
                                    foreach (string prefix in prefixes.Split('-'))
                                    {
                                        if (prefix != null && prefix != "")
                                        {
                                            Affix afx = new Affix();
                                            afx.MIDREF = prefix;
                                            wrdRec.Prefixes.Add(afx);
                                            if (!dictPrefixes.ContainsKey(prefix))
                                            {
                                                m_gd.Morphemes.Add(new Morpheme(MorphemeType.prefix, prefix));
                                                dictPrefixes.Add(prefix, true);
                                            }
                                        }
                                    }
                                }

                                // Handle stem.
                                string sStem = null;
                                // Stem has content, so use it.
                                sStem = line.Substring(openAngleLocation + 1, closeAngleLocation - openAngleLocation - 1);
                                if (sStem.Length == 0)
                                {
                                    sStem = "stem";
                                }
                                Stem stem = new Stem();
                                stem.MIDREF = sStem;
                                wrdRec.Stem = stem;
                                if (!dictStems.ContainsKey(sStem))
                                {
                                    m_gd.Morphemes.Add(new Morpheme(MorphemeType.stem, sStem));
                                    dictStems.Add(sStem, true);
                                }

                                // Handle suffixes, if any.
                                string suffixes = null;
                                if (line.Length > closeAngleLocation + 2)
                                {
                                    suffixes = line.Substring(closeAngleLocation + 1);
                                }
                                if (suffixes != null)
                                {
                                    if (wrdRec.Suffixes == null)
                                    {
                                        wrdRec.Suffixes = new List <Affix>();
                                    }
                                    foreach (string suffix in suffixes.Split('-'))
                                    {
                                        if (suffix != null && suffix != "")
                                        {
                                            Affix afx = new Affix();
                                            afx.MIDREF = suffix;
                                            wrdRec.Suffixes.Add(afx);
                                            if (!dictSuffixes.ContainsKey(suffix))
                                            {
                                                m_gd.Morphemes.Add(new Morpheme(MorphemeType.suffix, suffix));
                                                dictSuffixes.Add(suffix, true);
                                            }
                                        }
                                    }
                                }
                            }
                            line = reader.ReadLine();
                        }

                        // Main processing.
                        PositionAnalyzer anal = new PositionAnalyzer();
                        anal.Process(m_gd);

                        // Do any post-analysis processing here, if needed.
                        // End of any optional post-processing.

                        // Save, so it can be transformed.
                        outputPathname = GetOutputPathname(sourcePathname);
                        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;
                        }
                        finally
                        {
                            if (outputPathname != null && File.Exists(outputPathname))
                            {
                                File.Delete(outputPathname);
                            }
                        }
                        Process.Start(htmlOutput);
                    }                     // end 'using'
                }
            }

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