public static string NewShortTitle(Reference reference) { try { if (reference == null) { return(null); } string newShortTitle = string.Empty; Project project = Program.ActiveProjectShell.Project; string styleName = "ShortTitleGenerator.ccs"; string folder = project.Addresses.GetFolderPath(CitaviFolder.UserData).ToString(); string fullPath = folder + @"\Custom Citation Styles\" + styleName; if (!System.IO.File.Exists(fullPath)) { System.Windows.Forms.MessageBox.Show(ShortTitleGeneratorLocalization.CitationStyleNotFound); return(null); } Uri uri = new Uri(fullPath); CitationStyle citationStyle = CitationStyle.Load(uri.AbsoluteUri); List <Reference> references = new List <Reference>(); references.Add(reference); CitationManager citationManager = new CitationManager(Program.ActiveProjectShell.Project.Engine, citationStyle, references); if (citationManager == null) { return(null); } BibliographyCitation bibliographyCitation = citationManager.BibliographyCitations.FirstOrDefault(); if (bibliographyCitation == null) { return(null); } List <ITextUnit> textUnits = bibliographyCitation.GetTextUnits(); if (textUnits == null) { return(null); } var output = new TextUnitCollection(); foreach (ITextUnit textUnit in textUnits) { output.Add(textUnit); } newShortTitle = output.ToString(); return(newShortTitle); } catch { 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) { return(null); } Reference reference = citation.Reference; if (reference == null) { return(null); } if (citation.CitationManager == null) { return(null); } CitationManager citationManager = citation.CitationManager; BibliographyCitation bibliographyCitation = citation as BibliographyCitation; if (bibliographyCitation == null) { return(null); } int counter = 0; foreach (PlaceholderCitation placeholderCitation in citationManager.PlaceholderCitations) { if (placeholderCitation == null || placeholderCitation.Reference == null) { continue; } if (placeholderCitation.Reference.Equals(reference)) { counter++; } } if (counter == 1) { handled = true; return(null); } 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); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } Reference thisReference = citation.Reference; if (thisReference == null) { return(false); } Reference thisParentReference = thisReference.ParentReference; if (thisParentReference == null) { return(false); } List <Person> thisAuthors = thisReference.AuthorsOrEditorsOrOrganizations.ToList(); if (thisAuthors == null || !thisAuthors.Any()) { return(false); } CitationManager cm = citation.CitationManager; if (cm == null) { return(false); } foreach (Citation otherCitation in cm.BibliographyCitations) { if (otherCitation == null) { continue; } Reference otherReference = otherCitation.Reference; if (otherReference == null) { continue; } if (otherReference == thisReference) { continue; } Reference otherParentReference = otherReference.ParentReference; if (otherParentReference == null) { continue; } if (otherParentReference != thisParentReference) { continue; } List <Person> otherAuthors = otherReference.AuthorsOrEditorsOrOrganizations.ToList(); if (otherAuthors == null || !otherAuthors.Any()) { continue; } if (thisAuthors.SequenceEqual(otherAuthors)) { return(true); } } //still here? so other contribution by same other from same reference found return(false); }
/// <summary> /// Initializes the controller. /// </summary> /// <param name="settings"> /// Environment-specific settings. /// </param> /// <param name="nodeServices"> /// Node.JS services. /// </param> /// <returns> /// An initialized controller. /// </returns> public CitationController(IOptions <Settings> settings, INodeServices nodeServices) : base(settings) { _citationManager = new CitationManager(nodeServices); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } IReference currentReference = citation.Reference; if (currentReference == null) { return(false); } IReference currentParentReference = currentReference.ParentReference; if (currentParentReference == null) { return(false); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(false); } #region Bibliography BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation; if (currentBibliographyCitation != null) { if (!citationManager.BibliographyCitations.IsSorted) { return(false); } foreach (BibliographyCitation otherBibliographyCitation in citationManager.BibliographyCitations) { if (otherBibliographyCitation == null) { continue; } if (otherBibliographyCitation == currentBibliographyCitation) { break; } IReference otherReference = otherBibliographyCitation.Reference; if (otherReference == null) { continue; } if (otherReference == currentReference) { return(true); } if (otherReference == currentParentReference) { return(true); } IReference otherParentReference = otherReference.ParentReference; if (otherParentReference == null) { continue; } if (otherParentReference == currentParentReference) { return(true); } if (otherParentReference == currentReference) { return(true); } } return(false); } #endregion Bibliography #region Footnotes FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation != null) { foreach (FootnoteCitation otherFootnoteCitation in citationManager.FootnoteCitations) { if (otherFootnoteCitation == null) { continue; } if (otherFootnoteCitation == currentFootnoteCitation) { break; } IReference otherReference = otherFootnoteCitation.Reference; if (otherReference == null) { continue; } if (otherReference == currentReference) { return(true); } if (otherReference == currentParentReference) { return(true); } IReference otherParentReference = otherReference.ParentReference; if (otherParentReference == null) { continue; } if (otherParentReference == currentParentReference) { return(true); } if (otherParentReference == currentReference) { return(true); } } return(false); } #endregion Footnotes //not implmented for InTextCitations return(false); }
//Other reference of same author(s)/editor(s)/organization(s) cited BEFORE public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { var testEqualityBy = PersonIdentityTest.ByInternalID; //adjust here to your needs //e.g. PersonIdentityTest.ByLastNameFirstName //e.g. PersonIdentityText.ByFullName //e.g. PersonIdentityTest.ByInternalID <- recommended for most cases bool considerNoBibInBibliographyCitations = false; bool considerNoBibInInTextCitations = false; bool considerNoBibInFootnoteCitations = false; if (citation == null) { return(false); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(false); } Reference currentReference = citation.Reference; if (currentReference == null) { return(false); } IEnumerable <Person> currentPersons = currentReference.AuthorsOrEditorsOrOrganizations; if (currentPersons == null || currentPersons.Count() == 0) { return(false); } IEnumerable <PublicationCitation> allCitations = null; PublicationCitation currentPublicationCitation = citation as PublicationCitation; if (currentPublicationCitation == null) { return(false); } #region InTextCitations InTextCitation currentInTextCitation = citation as InTextCitation; if (currentInTextCitation != null) { if (currentInTextCitation.BibOnly) { return(false); } allCitations = considerNoBibInInTextCitations ? citationManager.InTextCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() : citationManager.InTextCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false)); } #endregion #region FootnoteCitations if (allCitations == null) { FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation != null) { if (currentFootnoteCitation.BibOnly) { return(false); } allCitations = considerNoBibInFootnoteCitations ? citationManager.FootnoteCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() : citationManager.FootnoteCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false)); } } #endregion #region BibliographyCitations if (allCitations == null) { BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation; if (currentBibliographyCitation.NoBib.GetValueOrDefault(false)) { return(false); } if (currentBibliographyCitation != null) { allCitations = citationManager.BibliographyCitations.Where(item => !item.NoBib.GetValueOrDefault(false)).Cast <PublicationCitation>(); } } #endregion IEnumerable <string> currentIdentifiers = GetPersonIdentifiers(currentPersons, testEqualityBy); foreach (PublicationCitation otherPublicationCitation in allCitations) { if (otherPublicationCitation == null) { continue; } if (otherPublicationCitation == currentPublicationCitation) { break; } var otherReference = otherPublicationCitation.Reference; if (otherReference == null) { continue; } if (otherReference == currentReference) { continue; } var otherPersons = otherReference.AuthorsOrEditorsOrOrganizations; if (otherPersons == null || otherPersons.Count() == 0) { continue; } var otherIdentifiers = GetPersonIdentifiers(otherPersons, testEqualityBy); if (testEqualityBy == PersonIdentityTest.ByInternalID) { //object identity if (otherPersons.SequenceEqual(currentPersons)) { return(true); } } else { if (otherIdentifiers.SequenceEqual(currentIdentifiers)) { return(true); } } } return(false); }
public int Compare(Citation x, Citation y) { #region Preliminary Tests //First we make sure we are comparing BibliographyCitations only var xBibliographyCitation = x as BibliographyCitation; var yBibliographyCitation = y as BibliographyCitation; if (xBibliographyCitation == null || yBibliographyCitation == null) { return(0); } var xReference = xBibliographyCitation.Reference; var yReference = yBibliographyCitation.Reference; if (xReference == null || yReference == null) { return(0); } #endregion #region Define the default citation comparer for sorting var defaultCitationComparer = CitationComparer.AuthorYearTitleOrNoAuthorThenTitleYearAscending; #endregion #region Exclude certain reference types from bibliography //Set the NoBib flag to true for ContributionInLegalCommentary ("Beitrag im Gesetzeskommentar") if (xReference.ReferenceType == ReferenceType.ContributionInLegalCommentary) { xBibliographyCitation.NoBib = true; } if (yReference.ReferenceType == ReferenceType.ContributionInLegalCommentary) { yBibliographyCitation.NoBib = true; } //Set the NoBib flag to true for StatuteOrRegulation ("Gesetz / Verordnung") if (xReference.ReferenceType == ReferenceType.StatuteOrRegulation) { xBibliographyCitation.NoBib = true; } if (yReference.ReferenceType == ReferenceType.StatuteOrRegulation) { yBibliographyCitation.NoBib = true; } //Set the NoBib flag to true for CourtDecision ("Gerichtsentscheid") if (xReference.ReferenceType == ReferenceType.CourtDecision) { xBibliographyCitation.NoBib = true; } if (yReference.ReferenceType == ReferenceType.CourtDecision) { yBibliographyCitation.NoBib = true; } #endregion #region Exclude references that have only been cited once inside footnotes (in text citations are NOT counted) CitationManager citationManager = x.CitationManager; if (citationManager == null) { return(0); } int xCounter = 0; int yCounter = 0; foreach (FootnoteCitation fnCit in citationManager.FootnoteCitations) { if (fnCit.Reference == null) { continue; } if (fnCit.Reference == xReference) { xCounter++; } if (fnCit.Reference == yReference) { yCounter++; } } if (xCounter < 2) { xBibliographyCitation.NoBib = true; } if (yCounter < 2) { yBibliographyCitation.NoBib = true; } #endregion #region Apply default sorting return(defaultCitationComparer.Compare(x, y)); #endregion }
//Reference has been cited at least 2 times before in footnotes public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.Reference == null) { return(false); } FootnoteCitation thisFootnoteCitation = citation as FootnoteCitation; if (thisFootnoteCitation == null) { return(false); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(false); } if (citationManager.FootnoteCitations == null || citationManager.FootnoteCitations.Count <= 2) { return(false); //no 3rd mention possible } if (thisFootnoteCitation.IsUniqueFootnote) { return(false); //there is just one } if (!thisFootnoteCitation.IsRepeatingCitation) { return(false); //is has not mentioned before, therefore in cannot be the 3rd (or higher) mention } //still here? we iterate over all footnote citations int previousMentions = 0; foreach (FootnoteCitation otherFootnoteCitation in citationManager.FootnoteCitations) { if (otherFootnoteCitation == null) { continue; } if (otherFootnoteCitation.Reference == null) { continue; } if (otherFootnoteCitation.Equals(thisFootnoteCitation)) { break; //we reached the current footnote citation } if (otherFootnoteCitation.Reference.Equals(thisFootnoteCitation.Reference)) { previousMentions++; //found another previous mention } if (previousMentions >= 2) { return(true); } } return(previousMentions >= 2); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { //Other work in the same series was cited before if (citation == null) { return(false); } var currentPlaceholderCitation = citation as PlaceholderCitation; if (currentPlaceholderCitation == null) { return(false); } Reference currentReference = currentPlaceholderCitation.Reference; SeriesTitle currentSeries = currentReference.SeriesTitle; if (currentSeries == null && currentReference.ParentReference != null) { currentSeries = currentReference.ParentReference.SeriesTitle; } if (currentSeries == null) { return(false); } // regarding placeholderCitation.PersonOnly: see comment for RepeatingInTextCitation if (currentPlaceholderCitation.RuleSetOverride != RuleSetOverride.None) { return(false); } if (currentPlaceholderCitation.YearOnly) { return(false); } CitationManager citationManager = currentPlaceholderCitation.CitationManager; if (citationManager == null) { return(false); } // we iterate over placeholder citations inside the same ruleset ONLY, i.e. in-text citations OR footnote citations IEnumerable <PlaceholderCitation> otherPlaceholderCitations = null; if (currentPlaceholderCitation.CitationType == CitationType.Footnote) { otherPlaceholderCitations = citationManager.FootnoteCitations.Select(item => item as PlaceholderCitation); } else if (currentPlaceholderCitation.CitationType == CitationType.InText) { otherPlaceholderCitations = citationManager.InTextCitations.Select(item => item as PlaceholderCitation); } foreach (PlaceholderCitation otherPlaceholderCitation in otherPlaceholderCitations) { if (otherPlaceholderCitation == currentPlaceholderCitation) { break; //we just look in the direction of the beginning of the document } Reference otherReference = otherPlaceholderCitation.Reference; if (otherReference == null) { continue; } SeriesTitle otherSeries = otherReference.SeriesTitle; if (otherSeries == null && otherReference.ParentReference != null) { otherSeries = otherReference.ParentReference.SeriesTitle; } if (otherSeries == null) { continue; } if (otherSeries == currentSeries && otherReference != currentReference) { return(true); } } //still here? nothing found, return false return(false); }
//Reference has been cited exactly once before public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.Reference == null) { return(false); } PlaceholderCitation currentPlaceholderCitation = citation as PlaceholderCitation; if (currentPlaceholderCitation == null) { return(false); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(false); } if (citationManager.PlaceholderCitations == null || citationManager.PlaceholderCitations.Count <= 1) { return(false); //no 2nd mention possible } if (currentPlaceholderCitation.IsUniquePlaceholderCitation) { return(false); //there is just one } if (!currentPlaceholderCitation.IsRepeatingCitation) { return(false); //it has not been mentioned before, therefore in cannot be the 2nd (or higher) mention } //still here? we iterate over all footnote citations int previousMentions = 0; foreach (PlaceholderCitation otherPlaceholderCitation in citationManager.PlaceholderCitations) { if (otherPlaceholderCitation == null) { continue; } if (otherPlaceholderCitation.Reference == null) { continue; } if (otherPlaceholderCitation.Equals(currentPlaceholderCitation)) { break; //we reached the current footnote citation } if (otherPlaceholderCitation.Reference.Equals(currentPlaceholderCitation.Reference)) { previousMentions++; //found another previous mention } } return(previousMentions == 1); }
//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); }