internal static void NestContext(string linguisticsBaseDir,
                                         IDictionary <string, XElement> wellUsedElements,
                                         IDictionary <string, SortedDictionary <string, byte[]> > classData,
                                         Dictionary <string, string> guidToClassMapping)
        {
            var morphAndSynDir = Path.Combine(linguisticsBaseDir, SharedConstants.MorphologyAndSyntax);

            if (!Directory.Exists(morphAndSynDir))
            {
                Directory.CreateDirectory(morphAndSynDir);
            }

            var lexDb = wellUsedElements[SharedConstants.LexDb];

            if (lexDb != null)
            {
                // Write out LexDb's "MorphTypes" list, as per AndyB (7 Feb 2012).
                FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping,
                                                                lexDb, SharedConstants.MorphTypes,
                                                                Path.Combine(morphAndSynDir, SharedConstants.MorphTypesListFilename));
            }
            var langProjElement = wellUsedElements[SharedConstants.LangProject];
            // 1. Nest: LP's MorphologicalData(MoMorphData OA) (Also does MoMorphData's ProdRestrict(CmPossibilityList)
            //		Remove objsur node from LP.
            var morphologicalDataPropElement = langProjElement.Element("MorphologicalData");

            morphologicalDataPropElement.RemoveNodes();
            var morphDataElement = Utilities.CreateFromBytes(classData["MoMorphData"].Values.First());

            CmObjectNestingService.NestObject(
                false,
                morphDataElement,
                classData,
                guidToClassMapping);
            // Hold off writing it until its list is written.

            // 2. Nest: LP's MsFeatureSystem(FsFeatureSystem OA)
            //		Remove objsur node from LP.
            var morphFeatureSystemPropElement = langProjElement.Element("MsFeatureSystem");
            var morphFeatureSystemElement     = Utilities.CreateFromBytes(classData["FsFeatureSystem"][morphFeatureSystemPropElement.Element(SharedConstants.Objsur).Attribute(SharedConstants.GuidStr).Value]);

            morphFeatureSystemPropElement.RemoveNodes();
            CmObjectNestingService.NestObject(
                false,
                morphFeatureSystemElement,
                classData,
                guidToClassMapping);
            FileWriterService.WriteNestedFile(Path.Combine(morphAndSynDir, SharedConstants.MorphAndSynFeaturesFilename), new XElement(SharedConstants.FeatureSystem, morphFeatureSystemElement));

            // 3. Nest: LP's PartsOfSpeech(CmPossibilityList OA)
            //		Remove objsur node from LP.
            FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping,
                                                            langProjElement, SharedConstants.PartsOfSpeech,
                                                            Path.Combine(morphAndSynDir, SharedConstants.PartsOfSpeechFilename));

            // 4. Nest: LP's AnalyzingAgents(CmAgent OC) (use some new extension and a fixed name)
            //		Remove objsur node(s) from LP.
            var agents      = classData["CmAgent"];
            var rootElement = new XElement(SharedConstants.AnalyzingAgents);

            foreach (var agentGuid in BaseDomainServices.GetGuids(langProjElement, SharedConstants.AnalyzingAgents))
            {
                var agentElement = Utilities.CreateFromBytes(agents[agentGuid]);
                rootElement.Add(agentElement);
                CmObjectNestingService.NestObject(
                    false,
                    agentElement,
                    classData,
                    guidToClassMapping);
            }
            FileWriterService.WriteNestedFile(Path.Combine(morphAndSynDir, SharedConstants.AnalyzingAgentsFilename), rootElement);
            langProjElement.Element(SharedConstants.AnalyzingAgents).RemoveNodes();

            // A. Write: MoMorphData's ProdRestrict(CmPossibilityList OA) and write in its own .list file.
            //		Remove ProdRestrict node child in MoMorphData
            var prodRestrictPropElement = morphDataElement.Element("ProdRestrict");

            if (prodRestrictPropElement != null && prodRestrictPropElement.HasElements)
            {
                // NB: Write file, but only if morphDataElement has the list.
                FileWriterService.WriteNestedFile(Path.Combine(morphAndSynDir, "ProdRestrict." + SharedConstants.List), prodRestrictPropElement);
                prodRestrictPropElement.RemoveNodes();
            }

            // B. Write: LP's MorphologicalData(MoMorphData OA) in a new extension (morphdata)
            FileWriterService.WriteNestedFile(Path.Combine(morphAndSynDir, SharedConstants.MorphAndSynDataFilename), new XElement(SharedConstants.MorphAndSynData, morphDataElement));
        }
Exemple #2
0
        internal static void NestContext(string linguisticsBaseDir,
                                         IDictionary <string, XElement> wellUsedElements,
                                         IDictionary <string, SortedDictionary <string, byte[]> > classData,
                                         Dictionary <string, string> guidToClassMapping)
        {
            var textCorpusBaseDir = Path.Combine(linguisticsBaseDir, SharedConstants.TextCorpus);

            if (!Directory.Exists(textCorpusBaseDir))
            {
                Directory.CreateDirectory(textCorpusBaseDir);
            }

            var langProjElement = wellUsedElements[SharedConstants.LangProject];

            // Write Genre list (owning atomic CmPossibilityList)
            FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping,
                                                            langProjElement, SharedConstants.GenreList,
                                                            Path.Combine(textCorpusBaseDir, SharedConstants.GenreListFilename));

            // Write text markup tags list (owning atomic CmPossibilityList)
            FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping,
                                                            langProjElement, SharedConstants.TextMarkupTags,
                                                            Path.Combine(textCorpusBaseDir, SharedConstants.TextMarkupTagsListFilename));

            // Handle the LP TranslationTags prop (OA-CmPossibilityList), if it exists.
            FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping,
                                                            langProjElement, SharedConstants.TranslationTags,
                                                            Path.Combine(textCorpusBaseDir, SharedConstants.TranslationTagsListFilename));

            var texts = classData["Text"];

            if (texts.Count == 0)
            {
                return;                 // No texts to process.
            }
            if (MetadataCache.MdCache.ModelVersion < 7000059)
            {
                // Backwards compatible code.
                var textGuidsInLangProj = BaseDomainServices.GetGuids(langProjElement, "Texts");
                if (textGuidsInLangProj.Count == 0)
                {
                    return;                     //  None owned by lang project. (Some can be owned by RnGenericRec.)
                }
                foreach (var textGuid in textGuidsInLangProj)
                {
                    var rootElement = new XElement("TextInCorpus");
                    var textElement = Utilities.CreateFromBytes(texts[textGuid]);
                    rootElement.Add(textElement);
                    CmObjectNestingService.NestObject(
                        false,
                        textElement,
                        classData,
                        guidToClassMapping);
                    FileWriterService.WriteNestedFile(
                        Path.Combine(textCorpusBaseDir, "Text_" + textGuid.ToLowerInvariant() + "." + SharedConstants.TextInCorpus),
                        rootElement);
                }
                // Remove child objsur nodes from owning LangProg
                langProjElement.Element("Texts").RemoveNodes();
            }
            else
            {
                foreach (var textGuid in texts.Keys.ToArray())                 // Needs a copy, since the dictionary is changed.
                {
                    var rootElement = new XElement("TextInCorpus");
                    var textElement = Utilities.CreateFromBytes(texts[textGuid]);
                    rootElement.Add(textElement);
                    CmObjectNestingService.NestObject(
                        false,
                        textElement,
                        classData,
                        guidToClassMapping);
                    FileWriterService.WriteNestedFile(
                        Path.Combine(textCorpusBaseDir, "Text_" + textGuid.ToLowerInvariant() + "." + SharedConstants.TextInCorpus),
                        rootElement);
                }
            }
        }