Exemple #1
0
        protected void SetUp()
        {
            string server   = Environment.MachineName + "\\SILFW";
            string database = "TestLangProj";

            string cnxString = "Server=" + server
                               + "; Database=" + database
                               + "; User ID=FWDeveloper;"
                               + "Password=careful; Pooling=false;";

            m_connection = new SqlConnection(cnxString);
            m_connection.Open();
            SqlCommand command = m_connection.CreateCommand();

            command.CommandText = "select top 1 Dst "
                                  + "from LangProject_CurVernWss "
                                  + "order by Ord";
            m_vernacularWS      = (int)command.ExecuteScalar();
            command             = m_connection.CreateCommand();
            command.CommandText = "select top 1 Id "
                                  + "from WordformInventory";
            m_wfiID = (int)command.ExecuteScalar();
            m_filer = new ParseFiler(m_connection, AnalyzingAgentId);
        }
        protected void ConvertMorphs(XmlDocument doc, string sNodeListToFind, bool fIdsInAttribute)
        {
            XmlNodeList nl = doc.SelectNodes(sNodeListToFind);

            if (nl != null)
            {
                foreach (XmlNode node in nl)
                {
                    XmlNode alloid;
                    if (fIdsInAttribute)
                    {
                        alloid = node.Attributes.GetNamedItem("alloid");
                    }
                    else
                    {
                        alloid = node.SelectSingleNode("MoForm/@DbRef");
                    }
                    int hvo  = Convert.ToInt32(alloid.InnerText);
                    var obj  = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvo);
                    var form = obj as IMoForm;
                    if (form == null)
                    {
                        // This is one of the null allomorphs we create when building the
                        // input for the parser in order to still get the Word Grammar to have something in any
                        // required slots in affix templates.
                        var lexEntryInflType = obj as ILexEntryInflType;
                        if (lexEntryInflType != null)
                        {
                            ConvertLexEntryInflType(doc, node, lexEntryInflType);
                            continue;
                        }
                    }
                    string sLongName;
                    string sForm;
                    string sGloss;
                    string sCitationForm;
                    if (form != null)
                    {
                        sLongName = form.LongName;
                        int iFirstSpace = sLongName.IndexOf(" (");
                        int iLastSpace  = sLongName.LastIndexOf("):") + 2;
                        sForm = sLongName.Substring(0, iFirstSpace);
                        XmlNode msaid;
                        if (fIdsInAttribute)
                        {
                            msaid = node.Attributes.GetNamedItem("morphname");
                        }
                        else
                        {
                            msaid = node.SelectSingleNode("MSI/@DbRef");
                        }
                        string sMsaHvo       = msaid.InnerText;
                        var    indexOfPeriod = ParseFiler.IndexOfPeriodInMsaHvo(ref sMsaHvo);
                        int    hvoMsa        = Convert.ToInt32(sMsaHvo);
                        var    msaObj        = m_cache.ServiceLocator.GetObject(hvoMsa);
                        if (msaObj.ClassID == LexEntryTags.kClassId)
                        {
                            var entry = msaObj as ILexEntry;
                            if (entry.EntryRefsOS.Count > 0)
                            {
                                var           index       = ParseFiler.IndexOfLexEntryRef(msaid.Value, indexOfPeriod);
                                var           lexEntryRef = entry.EntryRefsOS[index];
                                ITsIncStrBldr sbGlossPrepend;
                                ITsIncStrBldr sbGlossAppend;
                                var           sense   = FDO.DomainServices.MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                                var           glossWs = m_cache.ServiceLocator.WritingSystemManager.Get(m_cache.DefaultAnalWs);
                                FDO.DomainServices.MorphServices.JoinGlossAffixesOfInflVariantTypes(lexEntryRef.VariantEntryTypesRS,
                                                                                                    glossWs,
                                                                                                    out sbGlossPrepend, out sbGlossAppend);
                                ITsIncStrBldr sbGloss = sbGlossPrepend;
                                sbGloss.Append(sense.Gloss.BestAnalysisAlternative.Text);
                                sbGloss.Append(sbGlossAppend.Text);
                                sGloss = sbGloss.Text;
                            }
                            else
                            {
                                sGloss = ParserUIStrings.ksUnknownGloss;
                            }
                        }
                        else
                        {
                            var msa = msaObj as IMoMorphSynAnalysis;
                            if (msa != null)
                            {
                                sGloss = msa.GetGlossOfFirstSense();
                            }
                            else
                            {
                                sGloss = sLongName.Substring(iFirstSpace, iLastSpace - iFirstSpace).Trim();
                            }
                        }
                        sCitationForm = sLongName.Substring(iLastSpace).Trim();
                        sLongName     = String.Format(ParserUIStrings.ksX_Y_Z, sForm, sGloss, sCitationForm);
                    }
                    else
                    {
                        sForm         = ParserUIStrings.ksUnknownMorpheme;                 // in case the user continues...
                        sGloss        = ParserUIStrings.ksUnknownGloss;
                        sCitationForm = ParserUIStrings.ksUnknownCitationForm;
                        sLongName     = String.Format(ParserUIStrings.ksX_Y_Z, sForm, sGloss, sCitationForm);
                        throw new ApplicationException(sLongName);
                    }
                    XmlNode tempNode = CreateXmlElement(doc, "shortName", node);
                    tempNode.InnerXml = CreateEntities(sLongName);
                    tempNode          = CreateXmlElement(doc, "alloform", node);
                    tempNode.InnerXml = CreateEntities(sForm);
                    switch (form.ClassID)
                    {
                    case MoStemAllomorphTags.kClassId:
                        ConvertStemName(doc, node, form, tempNode);
                        break;

                    case MoAffixAllomorphTags.kClassId:
                        ConvertAffixAlloFeats(doc, node, form, tempNode);
                        ConvertStemNameAffix(doc, node, tempNode);
                        break;
                    }
                    tempNode          = CreateXmlElement(doc, "gloss", node);
                    tempNode.InnerXml = CreateEntities(sGloss);
                    tempNode          = CreateXmlElement(doc, "citationForm", node);
                    tempNode.InnerXml = CreateEntities(sCitationForm);
                }
            }
        }
        protected void CreateMsaXmlElement(XmlNode node, XmlDocument doc, XmlNode morphNode, string sHvo)
        {
            XmlNode attr;

            // morphname contains the hvo of the msa
            attr = node.SelectSingleNode(sHvo);
            if (attr != null)
            {
                string sObjHvo = attr.Value;
                // Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef
                var       indexOfPeriod = ParseFiler.IndexOfPeriodInMsaHvo(ref sObjHvo);
                ICmObject obj           = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(Convert.ToInt32(sObjHvo));
                switch (obj.GetType().Name)
                {
                default:
                    throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name));

                case "MoStemMsa":
                    IMoStemMsa stemMsa = obj as IMoStemMsa;
                    CreateStemMsaXmlElement(doc, morphNode, stemMsa);
                    break;

                case "MoInflAffMsa":
                    IMoInflAffMsa inflMsa = obj as IMoInflAffMsa;
                    CreateInflectionClasses(doc, morphNode);
                    CreateInflMsaXmlElement(doc, morphNode, inflMsa);
                    break;

                case "MoDerivAffMsa":
                    IMoDerivAffMsa derivMsa = obj as IMoDerivAffMsa;
                    CreateDerivMsaXmlElement(doc, morphNode, derivMsa);
                    break;

                case "MoUnclassifiedAffixMsa":
                    IMoUnclassifiedAffixMsa unclassMsa = obj as IMoUnclassifiedAffixMsa;
                    CreateUnclassifedMsaXmlElement(doc, morphNode, unclassMsa);
                    break;

                case "LexEntry":
                    // is an irregularly inflected form
                    // get the MoStemMsa of its variant
                    var entry = obj as ILexEntry;
                    if (entry.EntryRefsOS.Count > 0)
                    {
                        var index       = ParseFiler.IndexOfLexEntryRef(attr.Value, indexOfPeriod);
                        var lexEntryRef = entry.EntryRefsOS[index];
                        var sense       = FDO.DomainServices.MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef);
                        stemMsa = sense.MorphoSyntaxAnalysisRA as IMoStemMsa;
                        CreateStemMsaXmlElement(doc, morphNode, stemMsa);
                    }
                    break;

                case "LexEntryInflType":
                    // This is one of the null allomorphs we create when building the
                    // input for the parser in order to still get the Word Grammar to have something in any
                    // required slots in affix templates.
                    CreateInflMsaForLexEntryInflType(doc, morphNode, obj as ILexEntryInflType);
                    break;
                }
            }
        }