private static List <Person> GetPersonsDisplayed(Template template, Reference reference) { if (reference == null) { return(null); } if (template == null) { return(null); } if (template.ComponentParts == null || template.ComponentParts.Count == 0) { return(null); } //check for 1st PersonFieldElement in citation's template IEnumerable <IElement> elements = template.ComponentParts.SelectMany(part => part.Elements); PersonFieldElement firstPersonFieldElement = elements.FirstOrDefault(item => item is PersonFieldElement) as PersonFieldElement; if (firstPersonFieldElement == null) { return(null); } return(GetPersonsDisplayed(firstPersonFieldElement, reference)); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } #region BeforeFormatPerson: BeforeFormatPersonEventArgs bfp; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { bfp = (BeforeFormatPersonEventArgs)e; if (bfp.Person == null) { return; } if (string.IsNullOrEmpty(bfp.Person.FullName)) { return; } if (bfp.Person.FullName.Any(c => IsChinese(c))) { // if required, Chinese names can have a different name order than other persons in the group // otherwise, pls. comment out the following line using to slashes // bfp.NameOrder = PersonNameOrder.FirstNameLastName; bfp.SpaceBetwenLastAndFirstnames = ""; // used for PersonNameOrder = FirstNameLastName bfp.LastNameFirstNameSeparator = ""; // used for PersonNameOrder = LastNameFirstName or LastNameFirstNameCompact; } }; #endregion return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (componentPart == null) { return(null); } if (citation == null || citation.Reference == null) { return(null); } PersonFieldElement personFieldElement = componentPart.GetFieldElements().OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } IEnumerable <Person> persons = personFieldElement.GetPersons(citation.Reference); if (persons == null || !persons.Any()) { return(null); } bool found = false; TextUnitCollection textUnits = personFieldElement.GetTextUnits(citation, template); if (textUnits == null) { return(null); } foreach (ITextUnit textUnit in textUnits) { if (textUnit.Text.Contains(" ")) { found = true; textUnit.Text = textUnit.Text.Replace(" ", "\u00A0"); } } if (found) { componentPart.Elements.ReplaceItem(personFieldElement, textUnits.TextUnitsToLiteralElements(componentPart)); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } #region BeforeFormatPerson BeforeFormatPersonEventArgs b; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { b = (BeforeFormatPersonEventArgs)e; if (b.Person == null) { return; } if (string.IsNullOrEmpty(b.Person.LastNameForSorting)) { return; } var sortNamePerson = new Person(b.Person.Project, b.Person.LastNameForSorting); b.Person = sortNamePerson; }; #endregion return(null); }
private static PersonFieldElement GetPreviousPersonFieldElement(PersonFieldElement thisPersonFieldElement, Template template, Citation citation) { if (thisPersonFieldElement == null) { return(null); } if (template == null || template.ComponentParts == null || !template.ComponentParts.Any()) { return(null); } IEnumerable <PersonFieldElement> allPersonFieldElements = template.ComponentParts.SelectMany(part => part.Elements).OfType <PersonFieldElement>().ToList(); if (allPersonFieldElements == null || !allPersonFieldElements.Any()) { return(null); } int thisIndex = allPersonFieldElements.FindIndex <PersonFieldElement>(item => item.Id == thisPersonFieldElement.Id); if (thisIndex == -1 || thisIndex == 0) { return(null); } for (int i = thisIndex - 1; i >= 0; i--) { PersonFieldElement previousPersonFieldElement = allPersonFieldElements.ElementAtOrDefault <PersonFieldElement>(i) as PersonFieldElement; if (previousPersonFieldElement == null) { continue; } IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { continue; } return(previousPersonFieldElement); } return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null) { return(null); } if (citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement authorsOrEditorsOrOrganizationsFieldElement = componentPart.Elements.OfType <PersonFieldElement>() .Where(element => element.PropertyId == ReferencePropertyId.AuthorsOrEditorsOrOrganizations) .FirstOrDefault() as PersonFieldElement; if (authorsOrEditorsOrOrganizationsFieldElement == null) { return(null); } if ( citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Editor && citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Organization ) { return(null); } authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (Hrsg.)"; //authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.FontStyle = FontStyle.Bold; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (Hrsg.)"; //authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.FontStyle = FontStyle.Bold; handled = false; return(null); }
private static List <Person> GetPersonsDisplayed(ComponentPart componentPart, Reference reference) { if (reference == null) { return(null); } if (componentPart == null) { return(null); } //check for 1st PersonFieldElement in ComponentPart PersonFieldElement firstPersonFieldElement = componentPart.Elements.FirstOrDefault(item => item is PersonFieldElement) as PersonFieldElement; if (firstPersonFieldElement == null) { return(null); } return(GetPersonsDisplayed(firstPersonFieldElement, reference)); }
private static IEnumerable <Person> GetPersonsOfLastPersonFieldElement(Citation citation) { if (citation == null) { return(null); } if (citation.Reference == null) { return(null); } if (citation.Template == null) { return(null); } if (citation.Template.PersonFieldElements == null || !citation.Template.PersonFieldElements.Any()) { return(null); } PersonFieldElement personFieldElement = citation.Template.PersonFieldElements.LastOrDefault(); if (personFieldElement == null) { return(null); } var componentPartScope = personFieldElement.ComponentPart != null ? personFieldElement.ComponentPart.Scope : ComponentPartScope.Reference; IEnumerable <Person> persons = null; if (componentPartScope == ComponentPartScope.Reference) { persons = citation.Reference.GetValue(personFieldElement.PropertyId) as IList <Person>; } else if (componentPartScope == ComponentPartScope.ParentReference && citation.Reference.ParentReference != null) { persons = citation.Reference.ParentReference.GetValue(personFieldElement.PropertyId) as IList <Person>; } return(persons); }
private static List <Person> GetPersonsDisplayed(PersonFieldElement element, Reference reference) { if (element == null) { return(null); } if (reference == null) { return(null); } ReferencePersonCollection personCollection = reference.GetValue(element.PropertyId) as ReferencePersonCollection; if (personCollection == null || personCollection.Count == 0) { return(null); } List <Person> persons = new List <Person>(personCollection); return(persons); }
//Version 1.0a Add initials if there are other authors with the same last name (FIRST PERSON ONLY) public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { PersonNameOrder nameOrderForAmbiguityResolution = PersonNameOrder.LastNameFirstName; NameFormat firstNameFormatForAmbiguityResolution = NameFormat.Abbreviated; handled = false; if (componentPart == null) { return(null); } if (citation == null || citation.CitationManager == null) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } PersonFieldElement personFieldElement = componentPart.GetFieldElements().OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } IEnumerable <Person> persons = personFieldElement.GetPersons(reference); if (persons == null || !persons.Any()) { return(null); } Guid firstPersonId = persons.First <Person>().Id; #region BeforeFormatPerson BeforeFormatPersonEventArgs b; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { b = (BeforeFormatPersonEventArgs)e; if (b.Person == null) { return; } if (!b.Person.Id.Equals(firstPersonId)) { return; } if (citation.CitationManager.IsCitedPersonLastNameAmbiguous(b.Person.LastName)) { b.NameOrder = nameOrderForAmbiguityResolution; b.FirstNameFormat = firstNameFormatForAmbiguityResolution; } }; #endregion return(null); }
public int Compare(Citation x, Citation y) { /* * This is an example of a custom sort macro that sorts all references of type 'internet document' on top of the bibliography. * The internet documents themselves are sorted according to a different logic than the rest of the cited documents. * Return values: * 0: x is considered the same as y sorting-wise, so we cannot tell a difference based on the algorithm below * > 0 (positive): x should go after y, x is greater than y * < 0 (negative): x should go before y, x is less than */ if (x == null || y == null) { return(0); } Reference xReference = x.Reference; Reference yReference = y.Reference; if (xReference == null || yReference == null) { return(0); } ReferenceType xReferenceType = xReference.ReferenceType; ReferenceType yReferenceType = yReference.ReferenceType; BibliographyCitation xBibliographyCitation = x as BibliographyCitation; BibliographyCitation yBibliographyCitation = y as BibliographyCitation; if (xBibliographyCitation == null || yBibliographyCitation == null) { return(0); } Template xTemplate = x.GetTemplateForCitation(); Template yTemplate = y.GetTemplateForCitation(); if (xTemplate == null || yTemplate == null) { return(0); } PersonFieldElement xPersonFieldElement = xTemplate.StructuralPersonFieldElement; PersonFieldElement yPersonFieldElement = yTemplate.StructuralPersonFieldElement; IEnumerable <Person> xPersons = xPersonFieldElement != null?xPersonFieldElement.GetPersonsCited(x) : Enumerable.Empty <Person>(); IEnumerable <Person> yPersons = yPersonFieldElement != null?yPersonFieldElement.GetPersonsCited(y) : Enumerable.Empty <Person>(); int xPersonsCount = 0; int yPersonsCount = 0; if (xPersons != null) { xPersonsCount = xPersons.Count(); } if (yPersons != null) { yPersonsCount = yPersons.Count(); } string xTitleForSorting = GetTitleForSorting(xReference); string yTitleForSorting = GetTitleForSorting(yReference); string xVolume = xReference.Volume; string yVolume = yReference.Volume; string xSeriesTitleForSorting = GetSeriesTitleForSorting(xReference); string ySeriesTitleForSorting = GetSeriesTitleForSorting(yReference); string xNumber = xReference.Number; string yNumber = yReference.Number; StringComparer defaultStringComparer = StringComparer.Create(_cultureForSorting, true); int personsCompareResult = 0; int personsCountCompareResult = 0; int titleCompareResult = 0; int seriesTitleCompareResult = 0; int volumeCompareResult = 0; int numberCompareResult = 0; int yearCompareResult = 0; int editionCompareResult = 0; if (xPersonsCount == 0 && yPersonsCount == 0) { //compare Titles titleCompareResult = xTitleForSorting.CompareTo(yTitleForSorting); if (titleCompareResult != 0) { return(titleCompareResult); } seriesTitleCompareResult = xSeriesTitleForSorting.CompareTo(ySeriesTitleForSorting); if (seriesTitleCompareResult != 0) { return(seriesTitleCompareResult); } } else if (xPersonsCount == 0 && yPersonsCount > 0) { //compare xTitle with yFirstAuthor titleCompareResult = defaultStringComparer.Compare(xTitleForSorting, yPersons.ElementAt(0).FullName); if (titleCompareResult != 0) { return(titleCompareResult); } } else if (xPersonsCount > 0 && yPersonsCount == 0) { //compare xFirstAuthor with yTitle titleCompareResult = defaultStringComparer.Compare(xPersons.ElementAt(0).FullName, yTitleForSorting); if (titleCompareResult != 0) { return(titleCompareResult); } } else { /* * 1. Single Author Group * 2. Author + Single Co-Author Group * 3. Author + Multiple-Co-Authors Group */ //compare by first author personsCompareResult = ComparePersons(xPersons.ElementAt(0), yPersons.ElementAt(0)); if (personsCompareResult != 0) { return(personsCompareResult); } //still here? then both have same first author if ((xPersonsCount == 1 && yPersonsCount > 1) || (xPersonsCount == 2 && yPersonsCount > 2)) { //x before y return(-1); } if ((xPersonsCount > 1 && yPersonsCount == 1) || (xPersonsCount > 2 && yPersonsCount == 2)) { //x after y return(1); } if (xPersonsCount == 2 && yPersonsCount == 2) { //compare by co-author personsCompareResult = ComparePersons(xPersons.ElementAt(1), yPersons.ElementAt(1)); if (personsCompareResult != 0) { return(personsCompareResult); } } //still here? //both have either exactly one identical author OR //both have exactly two identical authors OR //more than 2 authors with identical first author //we continue with year comparison } #region Year yearCompareResult = YearComparer.Compare(x, y); if (yearCompareResult != 0) { return(yearCompareResult); } #endregion Year #region Title titleCompareResult = defaultStringComparer.Compare(xTitleForSorting, yTitleForSorting); if (titleCompareResult != 0) { return(titleCompareResult); } #endregion Title #region Volume if ( xReferenceType == yReferenceType && xReference.HasCoreField(ReferenceTypeCoreFieldId.Volume) && yReference.HasCoreField(ReferenceTypeCoreFieldId.Volume) && HasFieldElement(xTemplate, ReferencePropertyId.Volume) && HasFieldElement(yTemplate, ReferencePropertyId.Volume) ) { NumberStringComparer volumeComparer = new NumberStringComparer() { CompareMode = NumberStringCompareMode.ByTextAndNumbersSegmentwise, UseAbsoluteNumbersOnly = true }; volumeCompareResult = volumeComparer.Compare(xVolume, yVolume); if (volumeCompareResult != 0) { return(volumeCompareResult); } } #endregion Volume #region Number if ( xReferenceType == yReferenceType && xReference.HasCoreField(ReferenceTypeCoreFieldId.Number) && yReference.HasCoreField(ReferenceTypeCoreFieldId.Number) && HasFieldElement(xTemplate, ReferencePropertyId.Number) && HasFieldElement(yTemplate, ReferencePropertyId.Number) ) { NumberStringComparer numberComparer = new NumberStringComparer() { CompareMode = NumberStringCompareMode.ByTextAndNumbersSegmentwise, UseAbsoluteNumbersOnly = true }; numberCompareResult = numberComparer.Compare(xNumber, yNumber); if (numberCompareResult != 0) { return(numberCompareResult); } } #endregion #region Edition if ( xReference.HasCoreField(ReferenceTypeCoreFieldId.Edition) && yReference.HasCoreField(ReferenceTypeCoreFieldId.Edition) && HasFieldElement(xTemplate, ReferencePropertyId.Edition) && HasFieldElement(yTemplate, ReferencePropertyId.Edition) ) { var xEdition = xReference.EditionNumberResolved; var yEdition = yReference.EditionNumberResolved; bool xHasEdition = !string.IsNullOrEmpty(xEdition); bool yHasEdition = !string.IsNullOrEmpty(yEdition); if (xHasEdition && yHasEdition) { NumberStringComparer editionComparer = new NumberStringComparer() { CompareMode = NumberStringCompareMode.ByTextAndNumbersSegmentwise, UseAbsoluteNumbersOnly = true }; editionCompareResult = editionComparer.Compare(xEdition, yEdition); if (editionCompareResult != 0) { return(editionCompareResult); } } else if (xHasEdition && !yHasEdition) //y before x { return(1); } else if (!xHasEdition && yHasEdition) //x before y { return(-1); } } #endregion return(0); }
private static List <Person> GetPersonsDisplayed(PersonFieldElement element, Reference reference) { if (element == null) { return(null); } if (element.ComponentPart == null) { return(null); } List <Person> persons = null; ComponentPartScope scope = element.ComponentPart.Scope; Reference referenceInScope = null; if (scope == ComponentPartScope.Reference) { referenceInScope = reference; } else { referenceInScope = reference.ParentReference; } if (referenceInScope == null) { return(null); } switch (element.PropertyId) { #region Authors case ReferencePropertyId.Authors: { if (referenceInScope.Authors != null) { persons = new List <Person>(referenceInScope.Authors); } } break; #endregion Authors #region Editors case ReferencePropertyId.Editors: { if (referenceInScope.Editors != null) { persons = new List <Person>(referenceInScope.Editors); } } break; #endregion Editors #region AuthorsEditorsOrganizations case ReferencePropertyId.AuthorsOrEditorsOrOrganizations: { if (referenceInScope.AuthorsOrEditorsOrOrganizations != null) { persons = new List <Person>(referenceInScope.AuthorsOrEditorsOrOrganizations); } } break; #endregion AuthorsEditorsOrganizations #region Collaborators case ReferencePropertyId.Collaborators: { if (referenceInScope.Collaborators != null) { persons = new List <Person>(referenceInScope.Collaborators); } } break; #endregion Collaborators #region Organizations case ReferencePropertyId.Organizations: { if (referenceInScope.Organizations != null) { persons = new List <Person>(referenceInScope.Organizations); } } break; #endregion Organizations #region OthersInvolved case ReferencePropertyId.OthersInvolved: { if (referenceInScope.OthersInvolved != null) { persons = new List <Person>(referenceInScope.OthersInvolved); } } break; #endregion OthersInvolved } return(persons); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //change the following to "true", if you want "ders."/"dies." written in italics or other font styles var outputInItalics = true; var outputInSmallCaps = false; var outputInBold = false; var outputUnderlined = false; //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg)", you can define them as group prefix and suffix on the field element inside the component part editor handled = false; if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } if (citation == null) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } Reference parentReference = citation.Reference.ParentReference; #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetPersonFieldElement(componentPart); if (thisPersonFieldElement == null) { return(null); } #endregion #region ThesePersons List <Person> thesePersons = GetPersonsDisplayed(thisPersonFieldElement, reference); #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, reference); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons List <Person> previousPersons = GetPersonsDisplayed(previousPersonFieldElement, reference); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion bool usePlural = thesePersons.Count > 1; PersonEquality equality = CheckPersonEquality(thesePersons, previousPersons); if (equality == PersonEquality.None) { return(null); } //we DO have some equality, so let's check what we need to output instead of the person's name(s) var textIdem = string.Empty; switch (equality) { case PersonEquality.M: case PersonEquality.N: textIdem = "ders."; break; default: //all others textIdem = "dies."; break; } TextUnitCollection output = new TextUnitCollection(); #region GroupPrefix if (usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupPrefixPlural.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupPrefixPlural.Text, thisPersonFieldElement.GroupPrefixPlural.FontStyle)); } else if (!usePlural & !string.IsNullOrEmpty(thisPersonFieldElement.GroupPrefixSingular.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupPrefixSingular.Text, thisPersonFieldElement.GroupPrefixSingular.FontStyle)); } #endregion GroupPrefix SwissAcademic.Drawing.FontStyle fontStyle; fontStyle = SwissAcademic.Drawing.FontStyle.Neutral; if (outputInItalics) { fontStyle |= SwissAcademic.Drawing.FontStyle.Italic; } if (outputInSmallCaps) { fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps; } if (outputInBold) { fontStyle |= SwissAcademic.Drawing.FontStyle.Bold; } if (outputUnderlined) { fontStyle |= SwissAcademic.Drawing.FontStyle.Underline; } var fontStyleNeutral = SwissAcademic.Drawing.FontStyle.Neutral; output.Add(new LiteralTextUnit(textIdem, fontStyle)); #region GroupSuffix if (usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupSuffixPlural.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupSuffixPlural.Text, thisPersonFieldElement.GroupSuffixPlural.FontStyle)); } else if (!usePlural && !string.IsNullOrEmpty(thisPersonFieldElement.GroupSuffixSingular.Text)) { output.Add(new LiteralTextUnit(thisPersonFieldElement.GroupSuffixSingular.Text, thisPersonFieldElement.GroupSuffixSingular.FontStyle)); } #endregion GroupSuffix //inject this as LiteralElements into the componentPart, replacing the editors person field element componentPart.Elements.ReplaceItem(thisPersonFieldElement, TextUnitsToLiteralElements(output, componentPart)); //for some reason this does not work //all literal elements should always be output: foreach (LiteralElement literalElement in componentPart.Elements.OfType <LiteralElement>()) { literalElement.ApplyCondition = ElementApplyCondition.Always; } handled = false; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //return handled = true if this macro generates the output (as an IEnumerable<ITextUnit>); the standard output will be suppressed //return handled = false if you want Citavi to produce the standard output; handled = false; var useNonBreakingSpacesInAndBetweenFirstAndMiddleNames = false; //if true, then e.g. Meyers, J.°R. var useNonBreakingSpaceBetweenLastAndFirstName = false; //if true, then e.g. Meyers,°John Richard var useNonBreakingSpaceBetweenPrefixAndName = false; //if true, then e.g. von°Bülow, V. var useNonBreakingHyphenInFirstAndMiddleName = false; //if true, then e.g. Ewing, J.-R. if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetFirstPersonFieldElement(componentPart); if (thisPersonFieldElement == null || thisPersonFieldElement.SuppressOutput) { return(null); } #endregion #region ThesePersons IEnumerable <Person> thesePersons = thisPersonFieldElement.GetPersons(citation); if (thesePersons == null || !thesePersons.Any()) { return(null); } #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, citation); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion IEnumerable <PersonFieldElement> personFieldElements = componentPart.Elements.OfType <PersonFieldElement>(); if (personFieldElements == null || personFieldElements.Count() == 0) { return(null); } PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) //return null; [old version without useNonBreakingSpace...] { foreach (PersonFieldElement element in personFieldElements) { if (useNonBreakingSpacesInAndBetweenFirstAndMiddleNames) { element.FirstGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.LastPersonUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; } if (useNonBreakingSpaceBetweenLastAndFirstName) { element.FirstGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.SecondGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.LastPersonUseNonBreakingSpaceBetweenLastAndFirstName = true; } if (useNonBreakingSpaceBetweenPrefixAndName) { element.FirstGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.SecondGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.LastPersonUseNonBreakingSpaceBetweenPrefixAndName = true; } if (useNonBreakingHyphenInFirstAndMiddleName) { element.FirstGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.LastPersonUseNonBreakingHyphenInFirstAndMiddleNames = true; } } //for downward compatibility of this script we make sure the separator is just a comma and not "comma + space" var currentVersion = SwissAcademic.Environment.InformationalVersion; var maxVersionForWorkaround = new Version(6, 3, 5, 0); if (currentVersion <= maxVersionForWorkaround) { foreach (PersonFieldElement element in personFieldElements) { element.FirstGroupLastNameFirstNameSeparator.Text = ","; element.SecondGroupLastNameFirstNameSeparator.Text = ","; element.LastPersonLastNameFirstNameSeparator.Text = ","; } } //Citavi will do the rest, no need to return any output, since PersonTeamsIdentity.None = true return(null); } bool handleAlsoPartialIdentity = true; //if true, all of the following cases (1) - (3) will be treated. Otherwise, //if false, only case (2) will be treated bool confineReplacementToSingleAuthorOnPartialIdentity = true; //ignored if handleAlsoPartialIdentity = false; //if true, only cases (1) and (2) will be treated //(1) Watson, Mary, »An interesting contribution«, in: eadem / Smith, Emma (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(3) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } if (compareResult.Identity == PersonTeamsIdentity.Partial && previousPersons.Count() > 1 && confineReplacementToSingleAuthorOnPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("Ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("Dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("Dies.", FontStyle.Neutral); //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg.)", you can define them as group prefix and suffix on the field element inside the component part editor //CAUTION: This script will get more complex, if the separators between persons differ from group to group of for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); } else { afp.TextUnits.Insert(0, personSeparator); } } #endregion }; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null) { return(null); } if (componentPart == null) { return(null); } if (!componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } Reference parentReference = reference.ParentReference; string language = string.Empty; if (componentPart.Scope == ComponentPartScope.Reference) { language = reference.Language.ToUpperInvariant(); } else if (componentPart.Scope == ComponentPartScope.ParentReference) { if (parentReference == null) { return(null); } language = parentReference.Language.ToUpperInvariant(); } if (string.IsNullOrEmpty(language)) { return(null); } PersonFieldElement editorFieldElement = componentPart.Elements.OfType <PersonFieldElement>().Where(field => field.PropertyId == ReferencePropertyId.Editors).FirstOrDefault() as PersonFieldElement; if (editorFieldElement == null) { return(null); } #region English if (language.Contains("EN")) { editorFieldElement.GroupPrefixSingular.Text = "ed. by "; editorFieldElement.GroupPrefixPlural.Text = "ed. by "; editorFieldElement.GroupSuffixSingular.Text = ""; editorFieldElement.GroupSuffixPlural.Text = ""; return(null); } #endregion #region French if (language.Contains("FR")) { editorFieldElement.GroupPrefixSingular.Text = "publ. par "; editorFieldElement.GroupPrefixPlural.Text = "publ. par "; editorFieldElement.GroupSuffixSingular.Text = ""; editorFieldElement.GroupSuffixPlural.Text = ""; return(null); } #endregion #region Italian if (language.Contains("IT")) { editorFieldElement.GroupPrefixSingular.Text = "a cura di "; editorFieldElement.GroupPrefixPlural.Text = "a cura di "; editorFieldElement.GroupSuffixSingular.Text = ""; editorFieldElement.GroupSuffixPlural.Text = ""; return(null); } #endregion return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null) { return(null); } if (componentPart == null) { return(null); } if (!componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } Reference parentReference = reference.ParentReference; string language = string.Empty; if (componentPart.Scope == ComponentPartScope.Reference) { language = reference.Language.ToUpperInvariant(); } else if (componentPart.Scope == ComponentPartScope.ParentReference) { if (parentReference == null) { return(null); } language = parentReference.Language.ToUpperInvariant(); } if (string.IsNullOrEmpty(language)) { return(null); } PersonFieldElement authorsOrEditorsOrOrganizationsFieldElement = componentPart.Elements.OfType <PersonFieldElement>().Where(field => field.PropertyId == ReferencePropertyId.Editors || field.PropertyId == ReferencePropertyId.AuthorsOrEditorsOrOrganizations).FirstOrDefault() as PersonFieldElement; if (authorsOrEditorsOrOrganizationsFieldElement == null) { return(null); } if (componentPart.Scope == ComponentPartScope.Reference) { if ( citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Editor && citation.Reference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Organization ) { return(null); } } else if (componentPart.Scope == ComponentPartScope.ParentReference) { if ( citation.Reference.ParentReference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Editor && citation.Reference.ParentReference.AuthorsOrEditorsOrOrganizationsPersonRoleResolved != PersonRole.Organization ) { return(null); } } #region German if (language.Contains("DE")) { authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixSingular.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixPlural.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (Hrsg.)"; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (Hrsg.)"; return(null); } #endregion #region English if (language.Contains("EN")) { authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixSingular.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixPlural.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (ed.)"; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (eds.)"; return(null); } #endregion #region French if (language.Contains("FR")) { authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixSingular.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixPlural.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (éd.)"; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (éds.)"; return(null); } #endregion #region Italian if (language.Contains("IT")) { authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixSingular.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupPrefixPlural.Text = ""; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixSingular.Text = " (ed.)"; authorsOrEditorsOrOrganizationsFieldElement.GroupSuffixPlural.Text = " (eds.)"; return(null); } #endregion return(null); }
//CPS023 Format certain persons differently, by adding an "f" to the beginning of the person's notes field public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //When a first and/or middle name is added for disambiguation, should that be before or after the last name? PersonNameOrder nameOrder = PersonNameOrder.FirstNameLastName; NameFormat firstNameFormat = NameFormat.Abbreviated; FontStyle lastNameFontStyle = FontStyle.Neutral; FontStyle firstNameFontStyle = FontStyle.Italic; //NameFormat.Full John Mike //NameFormat.Abbreviated J. M. //NameFormat.AbbreviatedNoPeriod J M //NameFormat.AbbreviatedCompact J.M. //NameFormat.Compact JM handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } #region BeforeFormatPerson BeforeFormatPersonEventArgs bfp; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { bfp = (BeforeFormatPersonEventArgs)e; if (bfp.Person == null) { return; } if (string.IsNullOrWhiteSpace(bfp.Person.Notes)) { return; } //add ab "F" to the person's notes field to indicate: output with first name if (!bfp.Person.Notes.StartsWith("F", StringComparison.OrdinalIgnoreCase)) { return; } bfp.FirstNameFormat = firstNameFormat; bfp.NameOrder = nameOrder; bfp.FirstAndMiddleNameFontStyle = firstNameFontStyle; bfp.LastNameFontStyle = lastNameFontStyle; }; #endregion return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //if the following is set to true a placeholder citation's output will not show ders./dies. although this would normally be the case //as e.g. the second one of the following two: {Meier 2010 #2} and {Meier 2010 #2:17-19 /opt1} var deactivateFilterWithOption1Switch = true; //default: true //if the following is set to true, the citation collapsing can take place (if the style is set to omit author names) //true: (Mueller 2010, S. 10; 2011, S. 12f.; 2012, S. 17)o //false: (Mueller 2010, S. 10; ders. 2011, S. 12 f; ders. 2012, S. 17) var deactivateFilterInsideMultipleCitations = true; //default: true var deactivateFilterForFirstInsideMultipleCitations = true; //default: true; only applicable when deactivateFilterInsideMultipleCitations = false var deactivateFilterForFirstAfterMultipleCitations = true; //default: true var deactivateFilterInIbidemIdemSequence = false; //default: false var deactivateFilterAcrossFootnotes = false; //default: false var deactivateFilterAcrossFootnotesIfSeparatedByMoreThanOneIndexNo = true; //default: true; only applicable when deactivateFilterAcrossFootnotes = false var deactivateFilterAcrossFootnotesIfPreviousCitationNotSolitair = true; //default: true; ditto var outputInItalics = true; //default: true var outputInSmallCaps = false; //default: false var outputInBold = false; //default: false var outputUnderlined = false; //default: false var missingPersonsInfo = "o.A."; //can be set to e.g. "o.A."/"ohne Autor"; leave empty otherwise var outputMissingPersonsInfoInItalics = false; //default: false var outputMissingPersonsInfoInSmallCaps = false; //default: false var outputMissingPersonsInfoInBold = false; //default: false var outputMissingPersonsInfoUnderlined = false; //default: false var showGroupPrefixIfPresent = false; //default: false var showGroupSuffixIfPresent = true; //default: true var comparePersonsAgainstLastPersonField = true; handled = false; var thisCitationIsPartOfMultipleCitation = false; if (citation == null) { return(null); } if (citation.Reference == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } //determine current persons to compare IEnumerable <Person> thesePersons = GetPersonsOfPersonFieldElement(citation, personFieldElement); if (thesePersons == null || !thesePersons.Any()) { return(null); } bool usePlural = thesePersons.Count() > 1; PlaceholderCitation thisPlaceholderCitation = citation as PlaceholderCitation; #region deactivateFilterWithOption1Switch //SPECIAL: if this citation has the /opt1 switch set, this filter should be deactivated if (deactivateFilterWithOption1Switch && thisPlaceholderCitation != null && thisPlaceholderCitation.FormatOption1) { return(null); } #endregion deactivateFilterWithOption1Switch //handle missing persons #region MissingPersonsOutput var text = string.Empty; var output = new TextUnitCollection(); //SwissAcademic.Drawing.FontStyle fontStyle = outputInItalics ? SwissAcademic.Drawing.FontStyle.Italic : SwissAcademic.Drawing.FontStyle.Neutral; SwissAcademic.Drawing.FontStyle fontStyle; var personsMissing = (thesePersons == null || !thesePersons.Any()); var outputMissingPersonsInfo = personsMissing && !string.IsNullOrEmpty(missingPersonsInfo); if (personsMissing && outputMissingPersonsInfo) { text = missingPersonsInfo; fontStyle = SwissAcademic.Drawing.FontStyle.Neutral; if (outputMissingPersonsInfoInItalics) { fontStyle |= SwissAcademic.Drawing.FontStyle.Italic; } if (outputMissingPersonsInfoInSmallCaps) { fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps; } if (outputMissingPersonsInfoInBold) { fontStyle |= SwissAcademic.Drawing.FontStyle.Bold; } if (outputMissingPersonsInfoUnderlined) { fontStyle |= SwissAcademic.Drawing.FontStyle.Underline; } output.Add(new LiteralTextUnit(text, fontStyle)); handled = true; return(output); } else if (personsMissing) { return(null); } #endregion MissingPersonsOutput var previousVisibleCitation = GetPreviousVisibleCitation(citation); if (previousVisibleCitation == null) { return(null); } if (previousVisibleCitation.Reference == null) { return(null); } var secondPreviousVisibleCitation = GetPreviousVisibleCitation(previousVisibleCitation); #region MultipleCitation if (thisPlaceholderCitation != null) { var printingEntries = thisPlaceholderCitation.Entry.Placeholder.GetPrintingEntries(); if (printingEntries == null) { return(null); } if (printingEntries.Count() > 1) { thisCitationIsPartOfMultipleCitation = true; } if (thisCitationIsPartOfMultipleCitation) { if (deactivateFilterInsideMultipleCitations) { //We switch off "ders./dies." completely ... or ... return(null); } else { //... at least for the very first printing entry in a multiple citation var index = printingEntries.IndexOf(thisPlaceholderCitation.Entry); if (index == 0 && deactivateFilterForFirstInsideMultipleCitations) { return(null); } } } } #endregion MultipleCitation #region deactivateFilterInIbidemIdemSequence //avoiding a sequence such as e.g.: [2] Ebd. -> [3] Ders. if (deactivateFilterInIbidemIdemSequence) { if (secondPreviousVisibleCitation != null && secondPreviousVisibleCitation.Reference != null) { if (previousVisibleCitation.Reference == secondPreviousVisibleCitation.Reference) { return(null); } } } #endregion deactivateFilterInIbidemIdemSequence #region FootnoteCitation var thisFootnoteCitation = citation as FootnoteCitation; if (thisFootnoteCitation != null && !thisCitationIsPartOfMultipleCitation) { var previousVisibleFootnoteCitation = previousVisibleCitation as FootnoteCitation; if (previousVisibleFootnoteCitation == null) { return(null); } var printingEntries = previousVisibleFootnoteCitation.Entry.Placeholder.GetPrintingEntries(); if (printingEntries != null && printingEntries.Count() > 1 && deactivateFilterForFirstAfterMultipleCitations) { //previousVisibleFootnoteCitation IS part of a multiple citation return(null); } int thisFootnoteIndex = thisFootnoteCitation.FootnoteIndex; int previousFootnoteIndex = previousVisibleFootnoteCitation.FootnoteIndex; var secondPreviousVisibleFootnoteCitation = secondPreviousVisibleCitation as FootnoteCitation; int secondPreviousFootnoteIndex = secondPreviousVisibleFootnoteCitation == null ? 0 : secondPreviousVisibleFootnoteCitation.FootnoteIndex; #region deactivateFilterAcrossFootnotes //enforce distance rules as given by user settings above if ( ( deactivateFilterAcrossFootnotes && thisFootnoteIndex != previousFootnoteIndex ) || ( !deactivateFilterAcrossFootnotes && deactivateFilterAcrossFootnotesIfSeparatedByMoreThanOneIndexNo && thisFootnoteIndex - previousFootnoteIndex > 1 ) || ( !deactivateFilterAcrossFootnotes && deactivateFilterAcrossFootnotesIfPreviousCitationNotSolitair && thisFootnoteIndex - previousFootnoteIndex == 1 && secondPreviousFootnoteIndex == previousFootnoteIndex ) ) { return(null); } #endregion deactivateFilterAcrossFootnotes } #endregion FootnoteCitation #region InTextCitation var thisInTextCitation = citation as InTextCitation; //if this citations predecessor is part of a multiple citation, but THIS is NOT, switch off filter if (thisInTextCitation != null && !thisCitationIsPartOfMultipleCitation) { var previousVisibleInTextCitation = previousVisibleCitation as InTextCitation; if (previousVisibleInTextCitation == null) { return(null); } var printingEntries = previousVisibleInTextCitation.Entry.Placeholder.GetPrintingEntries(); if (printingEntries != null && printingEntries.Count() > 1 && deactivateFilterForFirstAfterMultipleCitations) { //previousVisibleInTextCitation IS part of a multiple citation return(null); } } #endregion InTextCitation //determine previous persons IEnumerable <Person> previousPersons = null; if (comparePersonsAgainstLastPersonField) { previousPersons = GetPersonsOfLastPersonFieldElement(previousVisibleCitation); } else { previousPersons = previousVisibleCitation.GetPersonsOfPersonFieldElement(0); } if (previousPersons == null || !previousPersons.Any()) { return(null); } var equality = CheckPersonEquality(thesePersons, previousPersons); if (equality == PersonEquality.None) { return(null); } #region Equality detected - generate output //we DO have some equality, so let's check what we need to output instead of the person's name(s) switch (equality) { case PersonEquality.M: text = "ders."; break; case PersonEquality.N: text = "dass."; break; default: //all others text = "dies."; break; } fontStyle = SwissAcademic.Drawing.FontStyle.Neutral; if (outputInItalics) { fontStyle |= SwissAcademic.Drawing.FontStyle.Italic; } if (outputInSmallCaps) { fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps; } if (outputInBold) { fontStyle |= SwissAcademic.Drawing.FontStyle.Bold; } if (outputUnderlined) { fontStyle |= SwissAcademic.Drawing.FontStyle.Underline; } #region GroupPrefix if (showGroupPrefixIfPresent && !string.IsNullOrEmpty(personFieldElement.GroupPrefixPlural.Text) && usePlural) { output.Add(new LiteralTextUnit(personFieldElement.GroupPrefixPlural.Text, personFieldElement.GroupPrefixPlural.FontStyle)); } else if (showGroupPrefixIfPresent && !string.IsNullOrEmpty(personFieldElement.GroupPrefixSingular.Text) && !usePlural) { output.Add(new LiteralTextUnit(personFieldElement.GroupPrefixSingular.Text, personFieldElement.GroupPrefixSingular.FontStyle)); } #endregion GroupPrefix output.Add(new LiteralTextUnit(text, fontStyle)); #region GroupSuffix if (showGroupSuffixIfPresent && !string.IsNullOrEmpty(personFieldElement.GroupSuffixPlural.Text) && usePlural) { output.Add(new LiteralTextUnit(personFieldElement.GroupSuffixPlural.Text, personFieldElement.GroupSuffixPlural.FontStyle)); } else if (showGroupSuffixIfPresent && !string.IsNullOrEmpty(personFieldElement.GroupSuffixSingular.Text) && !usePlural) { output.Add(new LiteralTextUnit(personFieldElement.GroupSuffixSingular.Text, personFieldElement.GroupSuffixSingular.FontStyle)); } #endregion GroupSuffix handled = true; return(output); #endregion Equality detected - generate output }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null) { return(null); } if (componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (!personFieldElement.AbbreviateNamePrefixes || string.IsNullOrEmpty(personFieldElement.NamePrefixAbbreviations)) { return(null); } Dictionary <string, string> namePrefixAbbreviationsDictionary = GetNamePrefixAbbreviationsDictionary(personFieldElement.NamePrefixAbbreviations); #region BeforeFormatPerson BeforeFormatPersonEventArgs b; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { b = (BeforeFormatPersonEventArgs)e; if (b.Person == null || string.IsNullOrEmpty(b.Person.LastName) || !string.IsNullOrEmpty(b.Person.Prefix)) { return; } bool found = false; string oldLastName = b.Person.LastName; string newLastName = null; foreach (KeyValuePair <string, string> kvp in namePrefixAbbreviationsDictionary) { if (oldLastName.StartsWith(kvp.Key + " ", System.StringComparison.OrdinalIgnoreCase)) { found = true; newLastName = kvp.Value + oldLastName.Substring(kvp.Key.Length); } } if (!found) { return; } var newPerson = new Person(b.Person.Project); newPerson.LastName = newLastName; newPerson.FirstName = b.Person.FirstName; newPerson.MiddleName = b.Person.MiddleName; newPerson.Prefix = b.Person.Prefix; newPerson.Suffix = b.Person.Suffix; newPerson.Abbreviation = b.Person.Abbreviation; b.Person = newPerson; }; #endregion return(null); }
//CPS012 Add first or middle names for ambiguous last names v5.0 //Version 5.0 Completely re-written for Citavi 6.4 (> Citavi 6.3.16) //Berücksichtigt die 3 neuen Werte: NameIdentity.LastNamePrefix, NameIdentity.LastNameFirstNameInitialMiddleNameInitial & NameIdentity.LastNameFirstNameInitialMiddleNameFull //Version 4.2 Added first name font style parameter //Version 4.1 Built-in option to insert non-breaking spaces and hyphens //Version 4.0 Completely re-written for Citavi 6 (6.2 or higher) //Disambiguation of identical person names by successively adding first name initials, full first names, middle name initals and full middle names (if available) public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //Should only the primary authors be considered in checking last names for ambiguity? bool checkAmbiguityForPrimaryAuthorsOnly = false; //When a first and/or middle name is added for disambiguation, should that be before or after the last name? PersonNameOrder nameOrderForAmbiguityResolution = PersonNameOrder.FirstNameLastName; //Formatting of the first name; combine several styles with a pipe character //FontStyle firstNameFontStyle = FontStyle.Bold | FontStyle.Italic; FontStyle firstNameFontStyle = FontStyle.Neutral; //In case of ambiguous last names, should the first attempt to disambigutate be the addition of full first names or just the initials? NameFormat firstNameFormatForAmbiguityResolution = NameFormat.Abbreviated; //NameFormat.Full John Mike //NameFormat.Abbreviated J. M. //NameFormat.AbbreviatedNoPeriod J M //NameFormat.AbbreviatedCompact J.M. //NameFormat.Compact JM //Insert non-breaking spaces and hyphens - geschütztes Leerzeichen und geschützten Bindestrich einfügen var useNonBreakingSpacesInAndBetweenFirstAndMiddleNames = true; //if true, then e.g. Meyers, J.°R. var useNonBreakingSpaceBetweenLastAndFirstName = true; //if true, then e.g. Meyers,°John Richard var useNonBreakingSpaceBetweenPrefixAndName = true; //if true, then e.g. von°Bülow, V. var useNonBreakingHyphenInFirstAndMiddleName = true; //if true, then e.g. Ewing, J.-R. handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } #region Insert non-breaking spaces and hyphens IEnumerable <PersonFieldElement> personFieldElements = componentPart.Elements.OfType <PersonFieldElement>(); if (personFieldElements == null || personFieldElements.Count() == 0) { return(null); } foreach (PersonFieldElement element in personFieldElements) { if (useNonBreakingSpacesInAndBetweenFirstAndMiddleNames) { element.FirstGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.LastPersonUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; } if (useNonBreakingSpaceBetweenLastAndFirstName) { element.FirstGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.SecondGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.LastPersonUseNonBreakingSpaceBetweenLastAndFirstName = true; } if (useNonBreakingSpaceBetweenPrefixAndName) { element.FirstGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.SecondGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.LastPersonUseNonBreakingSpaceBetweenPrefixAndName = true; } if (useNonBreakingHyphenInFirstAndMiddleName) { element.FirstGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.LastPersonUseNonBreakingHyphenInFirstAndMiddleNames = true; } } #endregion #region BeforeFormatPerson: Resolve last name ambiguity BeforeFormatPersonEventArgs bfp; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { bfp = (BeforeFormatPersonEventArgs)e; if (bfp.Person == null) { return; } if (checkAmbiguityForPrimaryAuthorsOnly && bfp.Index > 1) { return; } bool isLastNameAmbiguous = checkAmbiguityForPrimaryAuthorsOnly ? citationManager.IsFirstCitedPersonLastnameAmbiguous(bfp.Person.LastName) : citationManager.IsCitedPersonLastNameAmbiguous(bfp.Person.LastName); if (!isLastNameAmbiguous) { return; } NameIdentity nameIdentity = checkAmbiguityForPrimaryAuthorsOnly ? citationManager.GetFirstPersonNameIdentity(bfp.Person) : citationManager.GetPersonNameIdentity(bfp.Person); /* PERSON A PERSON B * NameIdentity.None Müller, Gerd Jakob Meier, Konrad Martin * NameIdentity.LastName Müller, Gerd Jakob Müller, Konrad Martin * NameIdentity.LastNamePrefix Müller, Gerd Jakob von Müller, Konrad Martin von * NameIdentity.LastNameFirstNameInitial Müller, Gerd Jakob Müller, Gustav Martin * NameIdentity.LastNameFirstNameFull Müller, Gerd Jakob Müller, Gerd Martin * NameIdentity.LastNameFirstNameFullMiddleNameInitial Müller, Gerd Jakob Müller, Gerd Johann * NameIdentity.LastNameFirstNameFullMiddleNameFull Müller, Gerd Jakob Müller, Gerd Jakob [der Ältere] */ switch (nameIdentity) { case NameIdentity.LastName: { if (!string.IsNullOrEmpty(bfp.Person.Prefix)) { bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameUsage = MiddleNameUsage.None; break; } else { bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } } case NameIdentity.LastNamePrefix: { bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameUsage = MiddleNameUsage.All; bfp.NamePrefixFontStyle = firstNameFontStyle; break; } case NameIdentity.LastNameFirstNameInitial: { if (!string.IsNullOrEmpty(bfp.Person.MiddleName)) { bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } else { bfp.FirstNameFormat = NameFormat.Full; bfp.MiddleNameFormat = NameFormat.Full; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } } case NameIdentity.LastNameFirstNameInitialMiddleNameInitial: { bfp.FirstNameFormat = NameFormat.Full; bfp.MiddleNameFormat = NameFormat.Full; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } case NameIdentity.LastNameFirstNameInitialMiddleNameFull: { bfp.FirstNameFormat = NameFormat.Full; bfp.MiddleNameFormat = NameFormat.Full; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } case NameIdentity.LastNameFirstNameFull: { bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameFormat = firstNameFormatForAmbiguityResolution; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } case NameIdentity.LastNameFirstNameFullMiddleNameInitial: { bfp.FirstNameFormat = NameFormat.Full; bfp.MiddleNameFormat = NameFormat.Full; bfp.MiddleNameUsage = MiddleNameUsage.All; break; } case NameIdentity.LastNameFirstNameFullMiddleNameFull: { //we can safely assume, that they have a different title or name addendum, like Jr. Sr. etc. bfp.SuppressNameSuffix = false; bfp.MiddleNameUsage = MiddleNameUsage.None; break; } case NameIdentity.None: default: { return; } } bfp.NameOrder = nameOrderForAmbiguityResolution; }; #endregion return(null); }
//Version 2.6 Fix bug that text before and after abbreviation is changed for all organisations in an authoring group //Version 2.5 If only the abbreviation of an organisation is to be shown, any text before and/or after is suppressed //Version 2.4 If Citavi demands that output is suppressed (e.g. when collapsing multiple citations of same author), this script will terminate //Version 2.3 Uses OnBeforeFormatOrganization to switch organization name output ot abbreviation only //Version 2.2 Uses PersonFormatter of PersonFieldElement //Version 2.1 Confine repetition detection to organizational names only, so that ambiguity of individual persons' names can be handled correctly again by Citavi // Therefore, name of helper method was changed from GetPreviouslyMentionedPersons to GetPreviouslyMentionedOrganizations public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } PlaceholderCitation placeholderCitation = citation as PlaceholderCitation; if (placeholderCitation == null) { return(null); } if (placeholderCitation.YearOnly) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements[0] as PersonFieldElement; if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } IEnumerable <Person> persons = personFieldElement.GetPersonsCited(citation); if (persons == null || !persons.Any()) { return(null); } if (!persons.Any(p => p.IsOrganization)) { return(null); } IEnumerable <Person> previouslyMentionedOrganizations = GetDistinctPreviouslyMentionedOrganizations(citation); if (previouslyMentionedOrganizations == null || !previouslyMentionedOrganizations.Any()) { return(null); } var textBeforeAbbreviation = personFieldElement.OrganizationTextBeforeAbbreviation.Text; var textAfterAbbreviation = personFieldElement.OrganizationTextAfterAbbreviation.Text; BeforeFormatOrganizationEventArgs b; personFieldElement.PersonFormatter.BeforeFormatOrganization += (sender, e) => { b = (BeforeFormatOrganizationEventArgs)e; if (b.Organization == null) { return; } if (previouslyMentionedOrganizations.Contains(b.Organization)) { b.NameOrder = OrganizationNameOrder.AbbreviationOnly; b.TextBeforeAbbreviation = null; b.TextAfterAbbreviation = null; } else { b.NameOrder = personFieldElement.OrganizationNameOrder; b.TextBeforeAbbreviation = textBeforeAbbreviation; b.TextAfterAbbreviation = textAfterAbbreviation; } }; return(null); }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //return handled = true if this macro generates the output (as an IEnumerable<ITextUnit>); the standard output will be suppressed //return handled = false if you want Citavi to produce the standard output; handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } #region ThisPersonFieldElement PersonFieldElement thisPersonFieldElement = GetFirstPersonFieldElement(componentPart); if (thisPersonFieldElement == null || thisPersonFieldElement.SuppressOutput) { return(null); } #endregion #region ThesePersons IEnumerable <Person> thesePersons = thisPersonFieldElement.GetPersons(citation); if (thesePersons == null || !thesePersons.Any()) { return(null); } #endregion #region PreviousPersonFieldElement PersonFieldElement previousPersonFieldElement = GetPreviousPersonFieldElement(thisPersonFieldElement, template, citation); if (previousPersonFieldElement == null) { return(null); } #endregion #region PreviousPersons IEnumerable <Person> previousPersons = previousPersonFieldElement.GetPersons(citation); if (previousPersons == null || !previousPersons.Any()) { return(null); } #endregion PersonTeamsCompareResult compareResult = GetPersonTeamsIdentityAndGenderStructure(thesePersons, previousPersons); if (compareResult.Identity == PersonTeamsIdentity.None) { return(null); } bool handleAlsoPartialIdentity = true; //if true, both of the following cases (1) and (2) will be treated. Otherwise, //if false, only case (1) will be treated //(1) Watson, Mary / Smith, Emma, »An interesting contribution«, in: iidem (Eds.), Edited book with 2 editors, London 2012. //(2) Watson, Mary / Smith, Emma, »A rather boring contribution«, in: iidem / Green, Peter (Eds.), Edited book with 3 editors, London 2012. if (compareResult.Identity == PersonTeamsIdentity.Partial && !handleAlsoPartialIdentity) { return(null); } //if you want "ders."/"dies." written in italics or other font styles, choose the desired option, for example FontStyle.Italic, FontStyle.Bold or FontStyle.SmallCaps LiteralTextUnit idemSingularMaleLiteral = new LiteralTextUnit("ders.", FontStyle.Neutral); LiteralTextUnit idemSingularFemaleLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); LiteralTextUnit idemSingularNeutralLiteral = new LiteralTextUnit("dass.", FontStyle.Neutral); LiteralTextUnit idemPluralLiteral = new LiteralTextUnit("dies.", FontStyle.Neutral); //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg.)", you can define them as group prefix and suffix on the field element inside the component part editor //CAUTION: This script will get more complex, if the separators between persons differ from group to group of for the last person LiteralTextUnit personSeparator = new LiteralTextUnit(thisPersonFieldElement.FirstGroupPersonSeparator.Text, thisPersonFieldElement.FirstGroupPersonSeparator.FontStyle); //we remove all separators, because some person names will have to be suppressed and we want to avoid excess separators such as the /'s in idem///John Smith thisPersonFieldElement.FirstGroupPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupLastPersonSeparator.Text = ""; thisPersonFieldElement.FirstGroupToSecondGroupSeparator.Text = ""; thisPersonFieldElement.SecondGroupPersonSeparator.Text = ""; thisPersonFieldElement.SecondGroupLastPersonSeparator.Text = ""; AfterFormatPersonEventArgs afp; thisPersonFieldElement.PersonFormatter.AfterFormatPerson += (sender, e) => { afp = (AfterFormatPersonEventArgs)e; #region Full Identity if (compareResult.Identity == PersonTeamsIdentity.Full) { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else { afp.TextUnits.Clear(); } } #endregion #region Partial Identity else { if (afp.Index == 0) { afp.TextUnits.Clear(); switch (compareResult.GenderStructure) { case PersonTeamGenderStructure.SingleMale: { afp.TextUnits.Add(idemSingularMaleLiteral); } break; case PersonTeamGenderStructure.SingleFemale: { afp.TextUnits.Add(idemSingularFemaleLiteral); } break; case PersonTeamGenderStructure.SingleNeuter: { afp.TextUnits.Add(idemSingularNeutralLiteral); } break; default: { afp.TextUnits.Add(idemPluralLiteral); } break; } } else if (afp.Index < compareResult.IdenticalPersonsCount) { afp.TextUnits.Clear(); } else { afp.TextUnits.Insert(0, personSeparator); } } #endregion }; return(null); }
//CPS012 Add first or middle names for ambiguous last names v3.5 //IMPORTANT: in Citavi 6.1 or below, it is only possible to identify persons with the same last name, not first or middle names. //Also disambiguation can only take place in a single stp, e.g. by adding first name initials only, or by adding full first names, or by adding both first and middle names. public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { //IMPORTANT: It is not possible Citavi 6.1 or below, to confine the name ambiguity check to the primary authors only. //If this is a requirement, pls. update to Citavi 6.2 or higher and make use of the latest component macr CPS012 version 4.0 or higher. //It is possible though to confine the disambiguation to the primary authors. bool disambiguatePrimaryAuthorsOnly = true; //When a first and/or middle name is added for disambiguation, should that be before or after the last name? PersonNameOrder nameOrderForAmbiguityResolution = PersonNameOrder.FirstNameLastName; //In case of ambiguous last names, should the disambiguation happen by adding full first names or just the initials? NameFormat firstNameFormatForAmbiguityResolution = NameFormat.Abbreviated; //NameFormat.Full John Mike //NameFormat.Abbreviated J. M. //NameFormat.AbbreviatedNoPeriod J M //NameFormat.AbbreviatedCompact J.M. //NameFormat.Compact JM //Should the middle name(s) be added for disambiguation? MiddleNameUsage middleNameUsageForAmbiguityResolution = MiddleNameUsage.All; //MiddleNameUsage.FirstOnly //MiddleNameUsage.All //In case of ambiguous last names, should disambiguation happen by adding full middle names or just the initials? NameFormat middleNameFormatForAmbiguityResolution = NameFormat.Full; handled = false; if (citation == null || citation.Reference == null) { return(null); } if (componentPart == null || componentPart.Elements == null || !componentPart.Elements.Any()) { return(null); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(null); } PersonFieldElement personFieldElement = componentPart.Elements.OfType <PersonFieldElement>().FirstOrDefault(); if (personFieldElement == null) { return(null); } if (personFieldElement.SuppressOutput) { return(null); } #region BeforeFormatPerson: Resolve last name ambiguity BeforeFormatPersonEventArgs bfp; personFieldElement.PersonFormatter.BeforeFormatPerson += (sender, e) => { bfp = (BeforeFormatPersonEventArgs)e; if (bfp.Person == null) { return; } if (disambiguatePrimaryAuthorsOnly && bfp.Index > 1) { return; } bool isLastNameAmbiguous = citationManager.IsCitedPersonLastNameAmbiguous(bfp.Person.LastName); if (!isLastNameAmbiguous) { return; } bfp.FirstNameFormat = firstNameFormatForAmbiguityResolution; bfp.NameOrder = nameOrderForAmbiguityResolution; bfp.MiddleNameUsage = middleNameUsageForAmbiguityResolution; bfp.MiddleNameFormat = middleNameFormatForAmbiguityResolution; }; #endregion return(null); }