Esempio n. 1
0
 private void AddSharedNodesToAlphaConfigurations(DictionaryConfigurationModel model)
 {
     if (model.SharedItems.Any())
     {
         m_logger.WriteLine("Not adding shared nodes because some already exist:");
         m_logger.IncreaseIndent();
         model.SharedItems.ForEach(si => m_logger.WriteLine(DCM.BuildPathStringFromNode(si)));
         m_logger.DecreaseIndent();
         return;
     }
     DCM.PerformActionOnNodes(model.Parts, SetReferenceItem);
     if (model.IsReversal)
     {
         var reversalSubEntries = FindMainEntryDescendant(model, "SubentriesOS");
         AddSubsubNodeIfNeeded(reversalSubEntries);
         DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, reversalSubEntries, "allreversalsubentries");
     }
     else             // is Configured Dictionary
     {
         var mainEntrySubSenseNode = FindMainEntryDescendant(model, "SensesOS", "SensesOS");
         AddSubsubNodeIfNeeded(mainEntrySubSenseNode);
         DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, mainEntrySubSenseNode, "mainentrysubsenses");
         var mainEntrySubEntries = FindMainEntryDescendant(model, "Subentries");
         AddSubsubEntriesOptionsIfNeeded(mainEntrySubEntries);
         DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, mainEntrySubEntries, "mainentrysubentries");
     }
     // Remove direct children from nodes with referenced children
     DCM.PerformActionOnNodes(model.PartsAndSharedItems, n => { if (!string.IsNullOrEmpty(n.ReferenceItem))
                                                                {
                                                                    n.Children = null;
                                                                }
                              });
 }
Esempio n. 2
0
 /// <summary>LT-18288: Change Headword to HeadwordRef for All "Referenced Sense Headword" to allow users to select WS</summary>
 private static void ChangeReferenceSenseHeadwordFieldName(ConfigurableDictionaryNode oldConfigPart)
 {
     DCM.PerformActionOnNodes(oldConfigPart.Children, node =>
     {
         if (node.Label == "Referenced Sense Headword")
         {
             node.FieldDescription = "HeadWordRef";
         }
     });
 }
Esempio n. 3
0
 /// <summary>LT-18286: One Sharing Parent in Hybrid erroneously got direct children (from a migration step). Remove them.</summary>
 private static void RemoveHiddenChildren(ConfigurableDictionaryNode parent, ISimpleLogger logger)
 {
     DCM.PerformActionOnNodes(parent.Children, p =>
     {
         if (p.ReferencedNode != null && p.Children != null && p.Children.Any())
         {
             logger.WriteLine(DCM.BuildPathStringFromNode(p) + " contains both Referenced And Direct Children. Removing Direct Children.");
             p.Children = new List <ConfigurableDictionaryNode>();
         }
     });
 }
Esempio n. 4
0
 private static void RemoveReferencedHeadwordSubField(ConfigurableDictionaryNode part)
 {
     DCM.PerformActionOnNodes(part.Children, node =>
     {
         // AllReversalSubentries under Referenced Headword field is ReversalName
         if (node.FieldDescription == "ReversalName" && node.SubField == "MLHeadWord")
         {
             node.SubField = null;
         }
     });
 }
Esempio n. 5
0
 private static void RemoveMostOfGramInfoUnderRefdComplexForms(ConfigurableDictionaryNode part)
 {
     DCM.PerformActionOnNodes(part.Children, node =>
     {
         // GramInfo under (Other) Ref'd Complex Forms is MorphoSystaxAnalyses
         // GramInfo under Senses  is MorphoSyntaxAnalysisRA and should not lose any children
         if (node.FieldDescription == "MorphoSyntaxAnalyses")
         {
             node.Children.RemoveAll(child => child.FieldDescription != "MLPartOfSpeech");
         }
     });
 }
Esempio n. 6
0
 private static void RemoveNonLoadableData(IEnumerable <ConfigurableDictionaryNode> nodes)
 {
     DCM.PerformActionOnNodes(nodes, node =>
     {
         node.ReferenceItem = null;
         var rsOptions      = node.DictionaryNodeOptions as DictionaryNodeReferringSenseOptions;
         if (rsOptions != null)
         {
             node.DictionaryNodeOptions = rsOptions.WritingSystemOptions;
         }
     });
 }
Esempio n. 7
0
 /// <summary>LT-18920: Change Referringsenses to Senses for all the reversal index configurations.</summary>
 private static void ChangeReferringsensesToSenses(ConfigurableDictionaryNode part)
 {
     if (part.FieldDescription == "ReversalIndexEntry" || part.FieldDescription == "SubentriesOS")
     {
         DCM.PerformActionOnNodes(part.Children, node =>
         {
             if (node.FieldDescription == "ReferringSenses")
             {
                 node.FieldDescription = "SensesRS";
             }
         });
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Earlier versions of Hybrid mistakenly used VisibleComplexFormBackRefs instead of ComplexFormsNotSubentries. Correct this mistake.
 /// Referenced Complex Forms should be *Other* Referenced Complex Forms whenever they are siblings of Subentries
 /// </summary>
 private static void ChooseAppropriateComplexForms(DictionaryConfigurationModel migratingModel)
 {
     if (!migratingModel.IsHybrid)
     {
         return;
     }
     DCM.PerformActionOnNodes(migratingModel.Parts, parentNode =>
     {
         if (parentNode.ReferencedOrDirectChildren != null && parentNode.ReferencedOrDirectChildren.Any(node => node.FieldDescription == "Subentries"))
         {
             parentNode.ReferencedOrDirectChildren.Where(sib => sib.FieldDescription == "VisibleComplexFormBackRefs").ForEach(sib =>
             {
                 sib.Label            = "Other Referenced Complex Forms";
                 sib.FieldDescription = "ComplexFormsNotSubentries";
             });
         }
     });
 }
Esempio n. 9
0
 private static void UseConfigReferencedEntriesAsPrimary(ConfigurableDictionaryNode part)
 {
     if (part.FieldDescription == "ReversalIndexEntry" || part.FieldDescription == "SubentriesOS")
     {
         DCM.PerformActionOnNodes(part.Children, node =>
         {
             if (node.DisplayLabel == "Primary Entry References" && node.FieldDescription == "EntryRefsWithThisMainSense")
             {
                 node.FieldDescription = "MainEntryRefs";
                 node.HideCustomFields = true;
                 node.Before           = "  (";
                 node.After            = ")";
             }
             if (node.DisplayLabel == "Primary Entry(s)" && node.FieldDescription == "PrimarySensesOrEntries")
             {
                 node.FieldDescription     = "ConfigReferencedEntries";
                 node.CSSClassNameOverride = "referencedentries";
             }
         });
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Case FirstAlphaMigrator.VersionAlpha3 above will pull in all the new nodes in the Etymology cluster by Label.
        /// Gloss is the only pre-existing node that doesn't have a new name, so it won't be replaced.
        /// It needs to be marked Enabled. The main Etymology node needs several modifications.
        /// Three old nodes will need deleting: Etymological Form, Comment and Source
        /// </summary>
        /// <param name="oldConfigPart"></param>
        /// <param name="oldConfig"></param>
        private static void UpgradeEtymologyCluster(ConfigurableDictionaryNode oldConfigPart, DictionaryConfigurationModel oldConfig)
        {
            if (oldConfigPart.Children == null || oldConfigPart.Children.Count == 0)
            {
                return;                 // safety net
            }
            var etymNodes = new List <ConfigurableDictionaryNode>();

            DCM.PerformActionOnNodes(oldConfigPart.Children, node =>
            {
                if (node.Label == "Etymology")
                {
                    etymNodes.Add(node);                     // since we have to do some node deleting, just collect up the relevant nodes
                }
            });

            foreach (var node in etymNodes)
            {
                if (node.IsCustomField)           // Unfortunately there are some pathological users who have ancient custom fields named etymology
                {
                    continue;                     // Leave them be
                }
                // modify main node
                var etymSequence = "EtymologyOS";
                if (oldConfig.IsReversal)
                {
                    node.SubField         = etymSequence;
                    node.FieldDescription = "Entry";
                    node.IsEnabled        = true;
                }
                else
                {
                    node.FieldDescription = etymSequence;
                    node.IsEnabled        = !oldConfig.IsHybrid;
                }
                node.CSSClassNameOverride = "etymologies";
                node.Before  = "(";
                node.Between = " ";
                node.After   = ") ";

                if (node.Children == null)
                {
                    continue;
                }

                // enable Gloss node
                var glossNode = node.Children.Find(n => n.Label == "Gloss");
                if (glossNode != null)
                {
                    glossNode.IsEnabled = true;
                }

                // enable Source Language Notes
                var notesList = node.Children.Find(n => n.FieldDescription == "LanguageNotes");
                if (notesList != null)                // ran into some cases where this node didn't exist in reversal config!
                {
                    notesList.IsEnabled = true;
                }

                // remove old children
                var nodesToRemove = new[] { "Etymological Form", "Comment", "Source" };
                node.Children.RemoveAll(n => nodesToRemove.Contains(n.Label));
            }
            // Etymology changed too much to be matched in the PreHistoricMigration and was marked as custom
            DCM.PerformActionOnNodes(etymNodes, n => { n.IsCustomField = false; });
        }
Esempio n. 11
0
        /// <remarks>
        /// Handles various kinds of configuration node changes that happened post-8.3Alpha1.
        /// It should no longer be necessary to add changes in two places
        /// [except: see caveat on PreHistoricMigrator.HandleChildNodeRenaming()]
        /// </remarks>
        private static void HandleNodewiseChanges(IEnumerable <ConfigurableDictionaryNode> nodes, ISimpleLogger logger, int version, bool isReversal)
        {
            var newHeadword = isReversal ? "ReversalName" : "HeadWordRef";

            switch (version)
            {
            case 2:
                DCM.PerformActionOnNodes(nodes, n =>
                {
                    if (n.FieldDescription == "OwningEntry" && n.SubField == "MLHeadWord")
                    {
                        n.SubField = newHeadword;
                    }
                });
                break;

            case 3:
                DCM.PerformActionOnNodes(nodes, n =>
                {
                    if (n.Label == "Gloss (or Summary Definition)")
                    {
                        n.FieldDescription = "GlossOrSummary";
                    }
                    if (n.Parent == null)
                    {
                        return;
                    }
                    if (n.Parent.FieldDescription == "ExamplesOS" && n.FieldDescription == "Example")
                    {
                        n.Label = "Example Sentence";
                    }
                    else if (n.Parent.FieldDescription == "ReferringSenses")
                    {
                        if (n.FieldDescription == "Owner" && n.SubField == "Bibliography")
                        {
                            n.Label = "Bibliography (Entry)";
                        }
                        else if (n.FieldDescription == "Bibliography")
                        {
                            n.Label = "Bibliography (Sense)";
                        }
                    }
                });
                break;

            case 4:
                DCM.PerformActionOnNodes(nodes, n =>
                {
                    switch (n.FieldDescription)
                    {
                    case "TranslationsOC":
                        n.CSSClassNameOverride = "translationcontents";
                        break;

                    case "ExamplesOS":
                        n.CSSClassNameOverride  = "examplescontents";
                        n.StyleType             = ConfigurableDictionaryNode.StyleTypes.Character;
                        n.DictionaryNodeOptions = new DictionaryNodeListAndParaOptions();                                         // allow to be shown in paragraph
                        break;
                    }
                });
                break;

            case VersionAlpha2:
                DCM.PerformActionOnNodes(nodes, n =>
                {
                    if (n.FieldDescription == null)
                    {
                        logger.WriteLine(string.Format("Warning: '{0}' reached the Alpha2 migration with a null FieldDescription.", DCM.BuildPathStringFromNode(n)));
                        return;
                    }
                    if (n.FieldDescription == "VisibleVariantEntryRefs" && n.Label == "Variant Of")
                    {
                        n.Label = "Variant of";
                    }
                    else if (n.FieldDescription.Contains("EntryType"))
                    {
                        var parentFd = n.Parent.FieldDescription;
                        if (n.FieldDescription == ConfiguredXHTMLGenerator.LookupComplexEntryType ||
                            isReversal && (n.FieldDescription == "VariantEntryTypesRS" || n.FieldDescription == "ComplexEntryTypesRS"))
                        {
                            if (parentFd == "ComplexFormEntryRefs")
                            {
                                // set type children to RevAbbr/RevName
                                SetEntryTypeChildrenBackward(n);
                            }
                            else
                            {
                                // set type children to Abbr/Name
                                SetEntryTypeChildrenForward(n);
                            }
                        }
                        else if (parentFd.EndsWith("BackRefs") || parentFd == "ComplexFormsNotSubentries")
                        {
                            // set type children to Abbr/Name
                            SetEntryTypeChildrenForward(n);
                        }
                        else
                        {
                            // set type children to RevAbbr/RevName
                            SetEntryTypeChildrenBackward(n);
                        }
                    }
                    else if ((n.Label == "Headword" && n.Parent.FieldDescription == "ReferringSenses") ||
                             (n.Label == "Form" && n.Parent.Label.StartsWith("Subentry Under")))
                    {
                        n.Label = "Referenced Headword";
                    }
                    else if (n.Label == "Subsenses" && n.Parent.FieldDescription == "SensesOS")
                    {
                        var senseNode = (DictionaryNodeSenseOptions)n.DictionaryNodeOptions;
                        if (senseNode != null)
                        {
                            senseNode.ParentSenseNumberingStyle = "%.";
                            senseNode.NumberingStyle            = "%d";
                            n.DictionaryNodeOptions             = senseNode;
                        }
                    }
                    else if (n.Label == "Allomorphs" && n.FieldDescription == "Owner")
                    {
                        n.FieldDescription = "Entry";
                    }
                    if (n.Label == "Referenced Headword")
                    {
                        n.FieldDescription = newHeadword;
                        if (isReversal && n.DictionaryNodeOptions == null)
                        {
                            n.DictionaryNodeOptions = new DictionaryNodeWritingSystemOptions
                            {
                                WsType  = DictionaryNodeWritingSystemOptions.WritingSystemType.Vernacular,
                                Options = new List <DictionaryNodeListOptions.DictionaryNodeOption>
                                {
                                    new DictionaryNodeListOptions.DictionaryNodeOption {
                                        Id = "vernacular", IsEnabled = true
                                    }
                                }
                            }
                        }
                        ;
                    }
                });
                break;

            case 6:
                DCM.PerformActionOnNodes(nodes, n =>
                {
                    if (isReversal && n.Label == "Pronunciation" && n.Parent.Label == "Pronunciations")
                    {
                        var parent     = n.Parent;
                        parent.Before  = "[";
                        parent.Between = " ";
                        parent.After   = "] ";
                        n.Before       = "";
                        n.Between      = "";
                        n.After        = " ";
                    }
                    UpdatePicturesChildren(n);
                });
                break;
            }
        }