Beispiel #1
0
        private static bool RenderNameGroup(
            Interpreter interpreter,
            IFormatting?formatting,
            NameGroup group,
            NameGroup?previousGroup,
            string?subsequentAuthorSubstitute,
            SubsequentAuthorSubstituteRules?subsequentAuthorSubstituteRule,
            NameElement name,
            EtAlElement?etAl,
            LabelElement?label)
        {
            var result = false;

            // complete subsequent author substitution?
            var isComplete = subsequentAuthorSubstituteRule.HasValue &&
                             previousGroup?.Names != null &&
                             group.Names.Count == previousGroup.Names.Count &&
                             Enumerable.Range(0, group.Names.Count).All(i => NameGroup.AreNamesEqual(group.Names[i], previousGroup.Names[i]));

            if (isComplete && subsequentAuthorSubstituteRule !.Value == SubsequentAuthorSubstituteRules.CompleteAll)
            {
                // substitute subsequent author
                result = true;
                interpreter.Push(subsequentAuthorSubstitute, formatting);
            }
Beispiel #2
0
        private static bool RenderNameGroups(
            Interpreter interpreter,
            IFormatting?formatting,
            string[] variables,
            TermName?[] terms,
            bool suppress,
            string?subsequentAuthorSubstitute,
            SubsequentAuthorSubstituteRules?subsequentAuthorSubstituteRule,
            NameElement name,
            EtAlElement?etAl,
            LabelElement?label)
        {
            var groups = new List <NameGroup>();

            for (int i = 0; i < terms.Length; i++)
            {
                var variable = variables[i];
                var names    = interpreter.Variable(variable);
                if (names is INamesVariable namesVariable)
                {
                    var group = new NameGroup(variable, terms[i], namesVariable);
                    groups.Add(group);
                }
            }

            if (suppress)
            {
                foreach (var variable in variables)
                {
                    interpreter.SuppressVariable(variable);
                }
            }

            var editors     = groups.SingleOrDefault(x => x.Term.HasValue && x.Term.Value == TermName.Editor);
            var translators = groups.SingleOrDefault(x => x.Term.HasValue && x.Term.Value == TermName.Translator);

            if (editors != null && translators != null)
            {
                // identical?
                if (editors.Names.Select(x => x.ToString()).SequenceEqual(translators.Names.Select(x => x.ToString())))
                {
                    // insert
                    groups.Insert(groups.IndexOf(editors), new NameGroup(null, TermName.EditorTranslator, editors.Names));
                    groups.Remove(editors);
                    groups.Remove(translators);
                }
            }

            // create results
            if (name.Format == NameFormat.Count)
            {
                // count
                var count = groups
                            .Select(x => x.Names.Count >= name.EtAlMin ? Math.Max(name.EtAlUseFirst, interpreter.DisambiguationContext.MinAddNames) : x.Names.Count)
                            .Sum();

                interpreter.Push(count > 0 ? count.ToString() : string.Empty, formatting);
                return(true);
            }
            else
            {
                bool result = false;

                for (int i = 0; i < groups.Count; i++)
                {
                    var group = groups[i];

                    NameGroup?previousGroup = null;

                    // subsequent author substitution?
                    if (subsequentAuthorSubstituteRule.HasValue)
                    {
                        // todo
                        // find match from previous entry in bibliography
                        previousGroup = interpreter.Previous == null || interpreter.Previous.FirstBibliographyNameGroups.Count <= i ? null : interpreter.Previous.FirstBibliographyNameGroups[i];
                    }

                    // render name group
                    var groupResult = RenderNameGroup(interpreter, formatting, group, previousGroup, subsequentAuthorSubstitute, subsequentAuthorSubstituteRule, name, etAl, label);

                    if (groupResult)
                    {
                        result = true;
                    }
                }
                // set result
                if (subsequentAuthorSubstituteRule.HasValue)
                {
                    interpreter.FirstBibliographyNameGroups = groups.ToArray();
                }

                return(result);
            }
        }