private static FootnoteCitation GetPreviousVisibleFootnoteCitation(FootnoteCitation thisFootnoteCitation, bool sameFootnote) { if (thisFootnoteCitation == null) { return(null); } FootnoteCitation previousFootnoteCitation = thisFootnoteCitation; //consider bibonly do { previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation; if (previousFootnoteCitation == null) { return(null); } } while (previousFootnoteCitation.BibOnly == true); //still here? found one! if (sameFootnote && previousFootnoteCitation.FootnoteIndex != thisFootnoteCitation.FootnoteIndex) { return(null); } return(previousFootnoteCitation); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.Reference == null) { return(false); } FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation == null) { return(false); } FootnoteCitation previousFootnoteCitation = currentFootnoteCitation.PreviousFootnoteCitation; if (previousFootnoteCitation == null) { //there is no previous citation in a footnote, so this is the first one (disregarding reference-less footnotes) return(true); } while (previousFootnoteCitation != null) { if (previousFootnoteCitation.FootnoteIndex != currentFootnoteCitation.FootnoteIndex) { if (previousFootnoteCitation.PageInPublication == currentFootnoteCitation.PageInPublication) { //a different previous footnote on the same page > this citation cannot be in the first footnote on the page return(false); } else { //a different previous footnote on other page > this citation is in first footnote on page (disregarding reference-less footnotes) return(true); } } else { if (previousFootnoteCitation.PageInPublication == currentFootnoteCitation.PageInPublication) { //the previous citation is in the same footnote on the same page; we cannot say anything yet } else { //the previous citation is in the same footnote, but on a different page: can we really detect page breaks INSIDE footnotes? return(true); } } previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation; } //still here? false! return(false); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { //Titel ist nur einmal in der FN zitiert if (citation == null) { return(false); } if (citation.Reference == null) { return(false); } FootnoteCitation footnoteCitation = citation as FootnoteCitation; if (footnoteCitation == null) { return(false); } return(footnoteCitation.IsUniqueFootnote); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.Reference == null) { return(false); } FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation == null) { return(false); } FootnoteCitation previousFootnoteCitation = currentFootnoteCitation.PreviousFootnoteCitation; while (previousFootnoteCitation != null) { if (previousFootnoteCitation.PageInPublication != currentFootnoteCitation.PageInPublication) { return(false); } if (previousFootnoteCitation.Reference != null && previousFootnoteCitation.Reference.Equals(currentFootnoteCitation.Reference)) { return(true); } previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation; } //still here, then we had no luck iterating on same page & looking for same reference return(false); }
private static Citation GetPreviousVisibleCitation(Citation citation) { if (citation == null) { return(null); } #region Bibliography if (citation.CitationType == CitationType.Bibliography) { BibliographyCitation previousBibliographyCitation = citation as BibliographyCitation; if (previousBibliographyCitation == null) { return(null); } //consider nobib do { previousBibliographyCitation = previousBibliographyCitation.PreviousBibliographyCitation; if (previousBibliographyCitation == null) { return(null); } } while (previousBibliographyCitation.NoBib == true); //still here? found one! return(previousBibliographyCitation); } #endregion Bibliography #region InText if (citation.CitationType == CitationType.InText) { InTextCitation previousInTextCitation = citation as InTextCitation; if (previousInTextCitation == null) { return(null); } //consider bibonly do { previousInTextCitation = previousInTextCitation.PreviousInTextCitation; if (previousInTextCitation == null) { return(null); } } while (previousInTextCitation.BibOnly == true); //still here? found one! return(previousInTextCitation); } #endregion InText #region Footnote if (citation.CitationType == CitationType.Footnote) { FootnoteCitation previousFootnoteCitation = citation as FootnoteCitation; if (previousFootnoteCitation == null) { return(null); } //consider bibonly do { previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation; if (previousFootnoteCitation == null) { return(null); } } while (previousFootnoteCitation.BibOnly == true); //still here? found one! return(previousFootnoteCitation); } #endregion Footnote //still here? no visible previous citation found! return(null); }
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); }
//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 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); } FootnoteCitation thisFootnoteCitation = citation as FootnoteCitation; if (thisFootnoteCitation == null) { return(null); } if (componentPart == null) { return(null); } Reference referenceToLookFor = null; if (componentPart.Scope == ComponentPartScope.ParentReference) { referenceToLookFor = citation.Reference.ParentReference; } else { referenceToLookFor = citation.Reference; } if (referenceToLookFor == null) { return(null); } //iterate through all previous footnote citations to find first occurance of referenceToLookFor var citationManager = thisFootnoteCitation.CitationManager; if (citationManager == null) { return(null); } FootnoteCitation firstFootnoteCitationToLookFor = null; foreach (FootnoteCitation previousFootnoteCitation in citationManager.FootnoteCitations) { if (previousFootnoteCitation == null) { continue; } if (previousFootnoteCitation == thisFootnoteCitation) { break; } if (previousFootnoteCitation.Reference == null) { continue; } if (previousFootnoteCitation.Reference == referenceToLookFor) { firstFootnoteCitationToLookFor = previousFootnoteCitation; break; } } if (firstFootnoteCitationToLookFor == null) { handled = true; return(null); //no first footnote index, NO output } //Still here? First footnote index was found. //caution: this does not work: firstFootnoteCitationToLookFor.FootnoteIndex == thisFootnoteCitation.FootnoteIndex if (firstFootnoteCitationToLookFor.FootnoteIndex.Equals(thisFootnoteCitation.FootnoteIndex)) { handled = true; return(null); //same footnote, so NO output } else { handled = false; return(null); } }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.CitationManager == null) { return(false); } if (citation.Reference == null) { return(false); } if (citation.Reference.Periodical == null) { return(false); } FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation != null) { if (currentFootnoteCitation.RuleSetOverride != RuleSetOverride.None) { return(false); } if (currentFootnoteCitation.YearOnly || currentFootnoteCitation.PersonOnly) { return(false); } foreach (FootnoteCitation otherFootnoteCitation in citation.CitationManager.FootnoteCitations) { if (otherFootnoteCitation == currentFootnoteCitation) { break; } if (otherFootnoteCitation.Reference == null) { continue; } if (otherFootnoteCitation.Reference.Periodical == null) { continue; } if (otherFootnoteCitation.Reference.Periodical.Equals(currentFootnoteCitation.Reference.Periodical)) { return(true); } } //still here? return(false); } InTextCitation currentInTextCitation = citation as InTextCitation; if (currentInTextCitation != null) { if (currentInTextCitation.RuleSetOverride != RuleSetOverride.None) { return(false); } if (currentInTextCitation.YearOnly || currentInTextCitation.PersonOnly) { return(false); } foreach (InTextCitation otherInTextCitation in citation.CitationManager.InTextCitations) { if (otherInTextCitation == currentInTextCitation) { break; } if (otherInTextCitation.Reference == null) { continue; } if (otherInTextCitation.Reference.Periodical == null) { continue; } if (otherInTextCitation.Reference.Periodical.Equals(currentInTextCitation.Reference.Periodical)) { return(true); } } //still here? return(false); } BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation; if (currentBibliographyCitation != null) { foreach (BibliographyCitation otherBibliographyCitation in citation.CitationManager.BibliographyCitations) { if (otherBibliographyCitation == currentBibliographyCitation) { break; } if (otherBibliographyCitation.Reference == null) { continue; } if (otherBibliographyCitation.Reference.Periodical == null) { continue; } if (otherBibliographyCitation.Reference.Periodical.Equals(currentBibliographyCitation.Reference.Periodical)) { return(true); } } //still here return(false); } return(false); }