/// <summary> /// Write one row of the publications report /// </summary> /// <param name="pub">Publication to write</param> /// <returns></returns> public string PubsReportRow(Person person, Publication pub) { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); // setnb -- unique identifier writer.Write(person.Setnb); // pmid -- Unique article identifier WriteCSV(pub.PMID.ToString(), writer); // journal_name -- Name of journal WriteCSV(pub.Journal, writer); // year -- Year of publication WriteCSV(pub.Year.ToString(), writer); // Month -- Month of publication WriteCSV(pub.Month, writer); // day -- Day of publication WriteCSV(pub.Day, writer); // title -- Article title WriteCSV(pub.Title, writer); // Volume -- volume number of the journal in which the article was published WriteCSV(pub.Volume, writer); // issue -- Issue in which the article was published WriteCSV(pub.Issue, writer); // position -- Position in authorship list Harvester.AuthorPositions positionType; int authorPosition = person.GetAuthorPosition(DB, pub, out positionType); WriteCSV(authorPosition.ToString(), writer); // nbauthors -- Number of coauthors (including person) WriteCSV(pub.Authors.Length.ToString(), writer); // Bin -- From I to IV, based on the PubTypeCategoryID value int bin = PubTypes.GetCategoryNumber(pub.PubType); WriteCSV(bin.ToString(), writer); // Pages -- Page numbers WriteCSV(pub.Pages, writer); // Publication_type -- Publication Type from Medline WriteCSV(pub.PubType, writer); return(sb.ToString()); }
/// <summary> /// Sort publications in order of year, publication type "bin", author position and PMID /// </summary> /// <param name="pFirstObject"></param> /// <param name="pObjectToCompare"></param> /// <returns></returns> public Int32 Compare(Object pFirstObject, Object pObjectToCompare) { if ((pFirstObject is Publication) && (pObjectToCompare is Publication)) { Publication First = (Publication)pFirstObject; Publication Compare = (Publication)pObjectToCompare; if (First.Year != Compare.Year) { return(Comparer.DefaultInvariant.Compare(First.Year, Compare.Year)); } else { int FirstPubType = publicationTypes.GetCategoryNumber(First.PubType); int ComparePubType = publicationTypes.GetCategoryNumber(Compare.PubType); if (FirstPubType != ComparePubType) { return(Comparer.DefaultInvariant.Compare(FirstPubType, ComparePubType)); } else { Harvester.AuthorPositions FirstAuthorPosition; person.GetAuthorPosition(DB, First, out FirstAuthorPosition); Harvester.AuthorPositions CompareAuthorPosition; person.GetAuthorPosition(DB, Compare, out CompareAuthorPosition); if (FirstAuthorPosition != CompareAuthorPosition) { return(Comparer.DefaultInvariant.Compare(FirstAuthorPosition, CompareAuthorPosition)); } else { return(Comparer.DefaultInvariant.Compare(First.PMID, Compare.PMID)); } } } } else { return(0); } }
/// <summary> /// Add the current publication to the database /// </summary> /// <param name="publication">Publication to write</param> /// <param name="DB">Database to add to</param> /// <param name="PubTypes">PublicationTypes object</param> /// <param name="Languages">The publication must match one of these languages or it will be rejected</param> /// <returns>True if the publication was written or is in the database already, false otherwise</returns> public static bool WriteToDB(Publication publication, Database DB, PublicationTypes PubTypes, string[] Languages) { ArrayList Parameters; // If the object already exists in the database, do nothing Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); int Count = DB.GetIntValue( @"SELECT Count(*) FROM Publications p WHERE p.PMID = ?", Parameters ); if (Count > 0) { return(true); // Return true because the publication is in the database } // Only write a publication if the language matches one of the languages // passed in the Languages parameter -- if Languages is null, accept // all values if (Languages != null) { bool Found = false; foreach (string Language in Languages) { if (publication.Language == Language) { Found = true; } } if (!Found) { return(false); // Return false because the publication wasn't written } } // Add the authors // First delete any authors that are there, in case the add was // interrupted partway through for (int Position = 0; (publication.Authors != null) && (Position <= publication.Authors.GetUpperBound(0)); Position++) { int First = (Position == 0) ? 1 : 0; int Last = (Position == publication.Authors.GetUpperBound(0)) ? 1 : 0; Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); Parameters.Add(Database.Parameter(Position + 1)); // The first author position is 1, not 0 Parameters.Add(Database.Parameter(Database.Left(publication.Authors[Position], 70))); Parameters.Add(Database.Parameter(First)); Parameters.Add(Database.Parameter(Last)); DB.ExecuteNonQuery( @"INSERT INTO PublicationAuthors (PMID, Position, Author, First, Last) VALUES (? , ? , ? , ? , ?)" , Parameters); } // Add the MeSH headings for (int Heading = 0; (publication.MeSHHeadings != null) && (Heading < publication.MeSHHeadings.Count); Heading++) { // If the MeSH heading already exists in the MeSHHeadings table, reuse it, // otherwise add it int ID; string MeSHHeading = Database.Left((string)publication.MeSHHeadings[Heading], 255); Parameters = new ArrayList(); Parameters.Add(Database.Parameter(MeSHHeading)); DataTable Results = DB.ExecuteQuery("SELECT ID FROM MeSHHeadings WHERE Heading = ?", Parameters); if (Results.Rows.Count > 0) { ID = Convert.ToInt32(Results.Rows[0][0]); } else { Parameters = new ArrayList(); Parameters.Add(Database.Parameter(MeSHHeading)); DB.ExecuteNonQuery("INSERT INTO MeSHHeadings (Heading) VALUES (?)", Parameters); ID = DB.GetIntValue("SELECT LAST_INSERT_ID()"); } Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); Parameters.Add(Database.Parameter(ID)); DB.ExecuteNonQuery( @"INSERT INTO PublicationMeSHHeadings (PMID, MeSHHeadingID) VALUES ( ? , ? )", Parameters); } // Add the grants for (int Grant = 0; (publication.Grants != null) && (Grant < publication.Grants.Count); Grant++) { // Some publications may have duplicate grants, so only add non-duplicates to avoid // primary key problems string GrantID = Database.Left((string)publication.Grants[Grant], 50); Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); Parameters.Add(Database.Parameter(GrantID)); if (DB.GetIntValue( @"SELECT Count(*) FROM PublicationGrants WHERE PMID = ? AND GrantID = ?", Parameters) == 0) { Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); Parameters.Add(Database.Parameter(GrantID)); DB.ExecuteNonQuery( @"INSERT INTO PublicationGrants (PMID, GrantID) VALUES ( ? , ? )", Parameters); } } // Strip the single and double quotes from the title before writing it string title; if (String.IsNullOrEmpty(publication.Title)) { title = ""; } else { title = publication.Title.Replace("\"", "").Replace("'", ""); } Parameters = new ArrayList(); Parameters.Add(Database.Parameter(publication.PMID)); Parameters.Add(Database.Parameter(Database.Left(publication.Journal, 128))); Parameters.Add(Database.Parameter(publication.Year)); Parameters.Add(Database.Parameter(publication.Authors == null ? 0 : publication.Authors.Length)); Parameters.Add(Database.Parameter(Database.Left(publication.Month, 32))); Parameters.Add(Database.Parameter(Database.Left(publication.Day, 32))); Parameters.Add(Database.Parameter(Database.Left(title, 244))); Parameters.Add(Database.Parameter(Database.Left(publication.Volume, 32))); Parameters.Add(Database.Parameter(Database.Left(publication.Issue, 32))); Parameters.Add(Database.Parameter(Database.Left(publication.Pages, 50))); // Finally, add the publication. This is part of the publication fault // tolerance system -- the headings and authors are not "final" until // the publication is written, and can be cleared from the database using // Harvester.ClearDataAfterInterruption(). // Publication type processing -- read the publication type file, // create the publication type table, add the types, file types into bins Parameters.Add(Database.Parameter(publication.PubType)); Parameters.Add(Database.Parameter(PubTypes.GetCategoryNumber(publication.PubType))); DB.ExecuteNonQuery( @"INSERT INTO Publications (PMID, Journal, Year, Authors, Month, Day, Title, Volume, Issue, Pages, PubType, PubTypeCategoryID) VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )", Parameters); return(true); }
/// <summary> /// Retrieve counts from a publication list /// </summary> /// <param name="PublicationList">Publication list to retrieve counts from, /// sorted by year, publication type and author position</param> /// <param name="Index">Offset in the publication list of the first publication /// matching the year and publication type</param> /// <param name="Year">Year to match for</param> /// <param name="PublicationType">Publication type to match for</param> public Counts(Publication[] PublicationList, ref int Index, int Year, int PublicationType, PublicationTypes PubTypes, Database DB, Person person, Hashtable Weights, string PeoplePublicationsTable) { // Return zero counts if the publication list is empty if (PublicationList.Length == 0) { return; } // Return zero counts if the index is out of bounds if ((Index < 0) || (Index >= PublicationList.Length)) { return; } // Return zero counts if the index doesn't point to a match -- that means // there are no matches Publication pub = PublicationList[Index]; int PubType = PubTypes.GetCategoryNumber(pub.PubType); if ((pub.Year != Year) || (PubType != PublicationType)) { return; } // If we get this far, we have a match. Move forward through the publication // list, adding to the counts, until we find a non-matching publication or // the list runs out. do { // Get the weight for the journal float Weight = 0; if (pub.Journal != null && Weights.ContainsKey(pub.Journal)) { Weight += (float)Weights[pub.Journal]; } // Get the position type, and increment the correct counter Harvester.AuthorPositions PositionType; Publications.GetAuthorPosition(DB, pub.PMID, person, out PositionType, PeoplePublicationsTable); switch (PositionType) { case Harvester.AuthorPositions.First: First++; FirstWeighted += Weight; break; case Harvester.AuthorPositions.Last: Last++; LastWeighted += Weight; break; case Harvester.AuthorPositions.Second: Second++; SecondWeighted += Weight; break; case Harvester.AuthorPositions.NextToLast: NextToLast++; NextToLastWeighted += Weight; break; case Harvester.AuthorPositions.Middle: case Harvester.AuthorPositions.None: Middle++; MiddleWeighted += Weight; break; } Index++; if (Index < PublicationList.Length) { pub = PublicationList[Index]; PubType = PubTypes.GetCategoryNumber(pub.PubType); } } while ((Index < PublicationList.Length) && (PublicationList[Index].Year == Year) && (PubType == PublicationType)); }