コード例 #1
0
        internal static void FlattenContext(
            SortedDictionary <string, XElement> highLevelData,
            SortedDictionary <string, XElement> sortedData,
            string linguisticsBaseDir)
        {
            var lexiconDir = Path.Combine(linguisticsBaseDir, SharedConstants.Lexicon);

            if (!Directory.Exists(lexiconDir))
            {
                return;
            }

            var langProjElement = highLevelData[SharedConstants.LangProject];
            var langProjGuid    = langProjElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant();
            var lexDbPathnames  = new List <string>(Directory.GetFiles(lexiconDir, string.Format("{0}_??.{1}", SharedConstants.Lexicon, SharedConstants.Lexdb), SearchOption.TopDirectoryOnly));

            lexDbPathnames.Sort(StringComparer.InvariantCultureIgnoreCase);
            foreach (var lexDbPathname in lexDbPathnames)
            {
                var lexDbDoc       = XDocument.Load(lexDbPathname);
                var rootLexDbDoc   = lexDbDoc.Root;
                var headerLexDbDoc = rootLexDbDoc.Element(SharedConstants.Header);
                if (headerLexDbDoc != null)
                {
                    var lexDb = headerLexDbDoc.Element(SharedConstants.LexDb);
                    highLevelData[SharedConstants.LexDb] = lexDb;                     // Let MorphAndSyn access it to put "MorphTypes" back into lexDb.
                    foreach (var listPathname in Directory.GetFiles(lexiconDir, "*.list", SearchOption.TopDirectoryOnly))
                    {
                        var listDoc     = XDocument.Load(listPathname);
                        var listElement = listDoc.Root.Element(SharedConstants.CmPossibilityList);
                        var listFilenameSansExtension = Path.GetFileNameWithoutExtension(listPathname);
                        switch (listFilenameSansExtension)
                        {
                        default:
                            // In LexDB. Just add the list to the owning prop, and let it get flattened, normally.
                            lexDb.Element(listFilenameSansExtension).Add(listElement);
                            break;

                        case "SemanticDomainList":
                        case "AffixCategories":
                            // Flatten the LP list by itself, and add an appropriate surrogate.
                            CmObjectFlatteningService.FlattenOwnedObject(
                                listPathname,
                                sortedData,
                                listElement,
                                langProjGuid, langProjElement, listFilenameSansExtension);                                         // Restore 'ownerguid' to list.
                            break;
                        }
                    }
                    // Flatten lexDb.
                    CmObjectFlatteningService.FlattenOwnedObject(
                        lexDbPathname,
                        sortedData,
                        lexDb,
                        langProjGuid, langProjElement, SharedConstants.LexDb);                         // Restore 'ownerguid' to LexDb.
                }

                // Flatten all entries in root of lexDbDoc. (EXCEPT if it has a guid of Guid.Empty, in which case, just ignore it, and it will go away.)
                foreach (var entryElement in rootLexDbDoc.Elements(SharedConstants.LexEntry)
                         .Where(element => element.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant() != SharedConstants.EmptyGuid))
                {
                    CmObjectFlatteningService.FlattenOwnerlessObject(
                        lexDbPathname,
                        sortedData,
                        entryElement);
                }
            }
        }
コード例 #2
0
        internal static void FlattenContext(
            SortedDictionary <string, XElement> highLevelData,
            SortedDictionary <string, XElement> sortedData,
            string linguisticsBaseDir)
        {
            var textCorpusBaseDir = Path.Combine(linguisticsBaseDir, SharedConstants.TextCorpus);

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

            var langProjElement = highLevelData[SharedConstants.LangProject];
            var langProjGuid    = langProjElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant();

            // Put the Genre list back in the right place.
            var pathname = Path.Combine(textCorpusBaseDir, SharedConstants.GenreListFilename);
            var doc      = XDocument.Load(pathname);

            BaseDomainServices.RestoreElement(pathname, sortedData, langProjElement, SharedConstants.GenreList, doc.Root.Element(SharedConstants.CmPossibilityList));
            // Put the markup tags list back in the right place.
            pathname = Path.Combine(textCorpusBaseDir, SharedConstants.TextMarkupTagsListFilename);
            doc      = XDocument.Load(pathname);
            BaseDomainServices.RestoreElement(pathname, sortedData, langProjElement, SharedConstants.TextMarkupTags, doc.Root.Element(SharedConstants.CmPossibilityList));
            // Put the translation tags list back in the right place.
            pathname = Path.Combine(textCorpusBaseDir, SharedConstants.TranslationTagsListFilename);
            doc      = XDocument.Load(pathname);
            BaseDomainServices.RestoreElement(pathname, sortedData, langProjElement, SharedConstants.TranslationTags, doc.Root.Element(SharedConstants.CmPossibilityList));

            if (MetadataCache.MdCache.ModelVersion < 7000059)
            {
                // Backwards compatible code.
                // Put Texts back into LP.
                var sortedTexts = new SortedDictionary <string, XElement>(StringComparer.OrdinalIgnoreCase);
                foreach (var textPathname in Directory.GetFiles(textCorpusBaseDir, "*." + SharedConstants.TextInCorpus, SearchOption.TopDirectoryOnly))
                {
                    var textDoc = XDocument.Load(textPathname);
                    // Put texts back into index's Entries element.
                    var root        = textDoc.Root;
                    var textElement = root.Elements().First();
                    CmObjectFlatteningService.FlattenOwnedObject(
                        textPathname,
                        sortedData,
                        textElement,
                        langProjGuid, sortedTexts);                         // Restore 'ownerguid' to text.
                }
                // Restore LP Texts property in sorted order.
                if (sortedTexts.Count == 0)
                {
                    return;
                }
                var langProjOwningProp = langProjElement.Element("Texts");
                foreach (var sortedTextObjSurElement in sortedTexts.Values)
                {
                    langProjOwningProp.Add(sortedTextObjSurElement);
                }
            }
            else
            {
                // Put Texts (all unowned now) all in 'sortedData'.
                foreach (var textPathname in Directory.GetFiles(textCorpusBaseDir, "*." + SharedConstants.TextInCorpus, SearchOption.TopDirectoryOnly))
                {
                    var textDoc     = XDocument.Load(textPathname);
                    var root        = textDoc.Root;
                    var textElement = root.Elements().First();
                    CmObjectFlatteningService.FlattenOwnerlessObject(
                        textPathname,
                        sortedData,
                        textElement);
                }
            }
        }
コード例 #3
0
        internal static void FlattenContext(
            SortedDictionary <string, XElement> highLevelData,
            SortedDictionary <string, XElement> sortedData,
            string generalBaseDir)
        {
            var langProjPathname = Path.Combine(generalBaseDir, SharedConstants.LanguageProjectFilename);
            var langProjDoc      = XDocument.Load(langProjPathname);
            var langProjElement  = langProjDoc.Root.Element(SharedConstants.LangProject);

            // Add LP to highLevelData.
            highLevelData.Add(SharedConstants.LangProject, langProjElement);
            // Flatten it.
            CmObjectFlatteningService.FlattenOwnerlessObject(
                langProjPathname,
                sortedData,
                langProjElement);

            // Add stuff LP owns that is here, then flatten it.
            // LP AnnotationDefs (OA-CmPossibilityList).
            var currentPathname = Path.Combine(generalBaseDir, SharedConstants.AnnotationDefsListFilename);

            if (File.Exists(currentPathname))
            {
                // Flatten it here to get the right pathname into the method.
                BaseDomainServices.RestoreElement(
                    currentPathname,
                    sortedData,
                    langProjElement,
                    SharedConstants.AnnotationDefs,
                    XDocument.Load(currentPathname).Root.Element(SharedConstants.CmPossibilityList));
            }

            // LP Styles (OC-StStyle)
            var langProjGuid   = langProjElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant();
            var sortedElements = new SortedDictionary <string, XElement>(StringComparer.OrdinalIgnoreCase);

            currentPathname = Path.Combine(generalBaseDir, SharedConstants.FLExStylesFilename);
            XDocument doc;

            if (File.Exists(currentPathname))
            {
                doc = XDocument.Load(currentPathname);
                foreach (var styleElement in doc.Root.Elements(SharedConstants.StStyle))
                {
                    // Put style back into LP's Styles element.
                    CmObjectFlatteningService.FlattenOwnedObject(
                        currentPathname,
                        sortedData,
                        styleElement,
                        langProjGuid, sortedElements);                         // Restore 'ownerguid' to style.
                }
                // Restore LP Styles property in sorted order.
                var langProjOwningProp = langProjElement.Element(SharedConstants.Styles);
                foreach (var sortedTextObjSurElement in sortedElements.Values)
                {
                    langProjOwningProp.Add(sortedTextObjSurElement);
                }
            }

            // LP Filters (OC-CmFilter)
            currentPathname = Path.Combine(generalBaseDir, SharedConstants.FLExFiltersFilename);
            if (File.Exists(currentPathname))
            {
                sortedElements = new SortedDictionary <string, XElement>(StringComparer.OrdinalIgnoreCase);
                doc            = XDocument.Load(currentPathname);
                foreach (var filterElement in doc.Root.Elements("CmFilter"))
                {
                    // Put CmFilter back into LP's Filters element.
                    CmObjectFlatteningService.FlattenOwnedObject(
                        currentPathname,
                        sortedData,
                        filterElement,
                        langProjGuid, sortedElements);                         // Restore 'ownerguid' to style.
                }
                // Restore LP Filters property in sorted order.
                var langProjOwningProp = langProjElement.Element(SharedConstants.Filters);
                foreach (var sortedTextObjSurElement in sortedElements.Values)
                {
                    langProjOwningProp.Add(sortedTextObjSurElement);
                }
            }

            // LP Annotations (OC-CmAnnotation). [Odd elements like in Discourse.]
            currentPathname = Path.Combine(generalBaseDir, SharedConstants.FLExAnnotationsFilename);
            if (File.Exists(currentPathname))
            {
                sortedElements = new SortedDictionary <string, XElement>(StringComparer.OrdinalIgnoreCase);
                doc            = XDocument.Load(currentPathname);
                foreach (var annotationElement in doc.Root.Elements(SharedConstants.CmAnnotation))
                {
                    // Put CmAnnotation back into LP's Annotations element.
                    var classAttr = annotationElement.Attribute(SharedConstants.Class);
                    annotationElement.Name = classAttr.Value;
                    classAttr.Remove();
                    CmObjectFlatteningService.FlattenOwnedObject(
                        currentPathname,
                        sortedData,
                        annotationElement,
                        langProjGuid, sortedElements);                         // Restore 'ownerguid' to style.
                }
                // Restore LP Annotations property in sorted order.
                var owningProp = langProjElement.Element(SharedConstants.Annotations);
                foreach (var sortedTextObjSurElement in sortedElements.Values)
                {
                    owningProp.Add(sortedTextObjSurElement);
                }
            }

            // No VirtualOrdering instances are owned.
            if (MetadataCache.MdCache.ModelVersion > MetadataCache.StartingModelVersion)
            {
                currentPathname = Path.Combine(generalBaseDir, SharedConstants.FLExVirtualOrderingFilename);
                doc             = XDocument.Load(currentPathname);
                foreach (var orderingElement in doc.Root.Elements(SharedConstants.VirtualOrdering))
                {
                    CmObjectFlatteningService.FlattenOwnerlessObject(
                        currentPathname,
                        sortedData,
                        orderingElement);
                }
            }

            // Some CmPicture instances may not be owned.
            currentPathname = Path.Combine(generalBaseDir, SharedConstants.FLExUnownedPicturesFilename);
            doc             = XDocument.Load(currentPathname);
            foreach (var pictureElement in doc.Root.Elements(SharedConstants.CmPicture))
            {
                CmObjectFlatteningService.FlattenOwnerlessObject(
                    currentPathname,
                    sortedData,
                    pictureElement);
            }
        }