/*
* Publication Harvester
* Copyright (c) 2003-2006 Stellman & Greene Consulting
* Developed for Joshua Zivin and Pierre Azoulay, Columbia University
* http://www.stellman-greene.com/PublicationHarvester
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program (GPL.txt); if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.Odbc;
namespace Com.StellmanGreene.PubMed
{
///
/// The Publication struct contains information about a publication. That
/// information is populated by calling the ProcessMedlineTag() function
/// repeatedly. ProcessMedlineTag() reads a single tag from the output
/// of a Medline query and updates the properties accordingly. The calling
/// object is responsible for sending all of the tags for the publication
/// through that function.
///
public struct Publication
{
///
/// PubMed ID for the publication (Medline PMID)
///
public int PMID;
///
/// Journal name (medline TA)
///
public string Journal;
///
/// Publication year (medline DP, year portion of "2005 May 17")
///
public int Year;
///
/// Month of publication (or null, if no month is specified)
/// (medline DP, optional month portion of "2005 May 17")
///
public string Month;
///
/// Day of publication (or null, if no day is specified)
/// (medline DP, optional day portion of "2005 May 17")
///
public string Day;
///
/// Title of publication (or null, if no title is specified) (medline TI)
///
public string Title;
///
/// List of authors (medline AU)
///
public string[] Authors;
///
/// Volume of publication (or null, if no volume is specified) (medline VI)
///
public string Volume;
///
/// Issue of publication (or null, if no issue is specified) (medline IP)
///
public string Issue;
///
/// Page numbers of publication (or null, if no pages are specified) (medline PG)
///
public string Pages;
///
/// Language of publication (or null, if no language is specified) (medline LA)
///
public string Language;
///
/// Listof grant IDs associated with the publication (or null, if no grant ID is specified)
/// (Medline GR, first occurrence)
///
public ArrayList Grants;
///
/// First publication type listed for the publication (or null, if no
/// publication type is specified) (medline PT, first occurrence)
///
public string PubType;
///
/// List of MeSH headings for the publication (medline MH)
///
public ArrayList MeSHHeadings;
public override string ToString()
{
return PMID + " " + (Title ?? "[no title]");
}
}
///
/// Comparer class to compare two publications.
///
public class PublicationComparer : IComparer
{
// Classes to get bin and author position
public PublicationTypes publicationTypes;
public Person person;
public Database DB;
///
/// Sort publications in order of year, publication type "bin", author position and PMID
///
///
///
///
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;
}
}
}
///
/// IComparer for finding a specific year in an array of publications
///
public class PublicationYearFinder : IComparer
{
public Int32 Compare(Object pFirstObject, Object pObjectToCompare)
{
if ((pFirstObject is Publication) && (pObjectToCompare is int))
return Comparer.DefaultInvariant.Compare(((Publication)pFirstObject).Year, (int)pObjectToCompare);
else
return 0;
}
}
}