-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCCitation.h
254 lines (184 loc) · 8.04 KB
/
BCCitation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//
// BCCitation.h
// Xynk
//
// Created by Tom Houpt on 15/2/25.
//
//
#import "BCCiteKey.h"
@class BCAuthor;
@class BCCitationAuthor;
@class BCXMLElement;
#define kBCCitationEditedNotification @"BCCitationEditedNotification"
typedef NS_ENUM(NSInteger, BCCitationType) {
kArticle = 0,
kBook = 1,
kBooklet = 2,
kConference = 3,
kInBook = 4,
kInCollection=5,
kInProceedings=6,
kManual,
kMastersThesis=7,
kMisc=8,
kPhdThesis=9,
kProceedings=10,
kTechReport=11,
kUnpublished =12
};
#define kArticleString @"@article"
#define kBookString @"@book"
#define kBookletString @"@booklet"
#define kConferenceString @"@conference"
#define kInBookString @"@inbook"
#define kInCollectionString @"@incollection"
#define kInProceedingsString @"@inproceedings"
#define kManualString @"@manual"
#define kMastersThesisString @"@mastersthesis"
#define kMiscString @"@misc"
#define kPhdThesisString @"@phdthesis"
#define kProceedingsString @"@proceedings"
#define kTechReportString @"@techreport"
#define kUnpublished @"@unpublished"
/*
NSArray bibTexTypeStrings = [
kArticleString ,
kBookString ,
kBookletString ,
kConferenceString ,
kInbookString ,
kIncollectionString ,
kInproceedingsString ,
kManualString ,
kMastersthesisString ,
kMiscString ,
kPhdthesisString ,
kProceedingsString ,
kTechreportString ,
kUnpublished
];
*/
// should each type have an associated list of key/value pairs?
@class BCPubmedParser;
@interface BCCitation : BCCiteKey {
BCPubmedParser *citationParser;
}
/** stubs for full citation info
we use NSStrings because even values expected to be numeric, like volume,
might contain non-numeric values (e.g. "supplemental volume 5 b" = "S5b"
*/
// maybe put this all in a dictionary of properties
@property BCAuthor *correspondingAuthor;
@property NSMutableArray<BCCitationAuthor *> *authors; /// array of BCCitationAuthors...
@property BCCitationType citationType; /// map to bibtex type
// journal article fields
@property NSInteger pmidToParse;
@property (copy) NSString *bibtexKey;
@property (copy) NSString *journal;
@property (copy) NSString *journalAbbreviation;
@property (copy) NSString *volume;
@property (copy) NSString *number;
@property (copy) NSString *pages;
@property (copy) NSString *abstract;
@property (copy) NSString *url; // bibtex url
@property (copy) NSString *urldate; // bibtex accessed
@property (copy) NSString *issn;
@property NSMutableArray *keywords; /// array of NSString keywords
@property (copy) NSString *booktitle;
@property (copy) NSString *bookLength;
@property NSMutableArray<BCCitationAuthor *> *editors; // array of BCCitationAuthors
@property (copy) NSString *publisher;
@property (copy) NSString *publicationPlace;
@property (copy) NSDate *publicationDate;
@property (copy) NSDate *ePubDate;
@property (copy) NSString *address;
@property (copy) NSString *chapter;
@property (copy) NSString *edition;
@property (copy) NSString *howpublished;
@property (copy) NSString *institution;
@property (copy) NSString *month;
@property (copy) NSString *note;
@property (copy) NSString *organization;
@property (copy) NSString *school;
@property (copy) NSString *series;
@property (copy) NSString *isbn;
@property (copy) NSString *language;
@property (copy) NSString *file;
@property NSMutableDictionary *databaseIDs; /// pairs of databaseID as key and ascension number, e.g. databaseIDs["PMID"] = 314156 ; citation can have 0 or more than one databaseID if represented in multiple databases...
//NOTE: are all ascension numbers numeric -- no, so store as strings
// e.g., DOI could be considered an ascension number but it has non-numeric characters
/** firstAuthor, title , and doi can be nil or empty (white space only),
although to generate a citekey the citation should have either a title or a doi
@return newly initialized BCCitation object
*/
-(id)initWithAuthor:(NSString *)a title:(NSString *)t year:(NSInteger)y doi:(NSString *)d;
/** look up pmid and populate citation fields
*/
-(id)initWithPMID:(NSInteger)pmid;
-(id)initWithBibtex:(NSString *)bibtexString;
-(void)pmidParsed:(NSNotification*) note;
-(void)setFieldsFromPubMedXMLDictionary:(BCXMLElement *)rootDictionary;
/** citation represented as a string
*/
-(NSString *) citation;
/** given a database ID string (e.g. @"PMID") return the stored ascension number/string;
if no ascension number available, then return -1
// NOTE: should we enable the database to construct well-formed urls, e.g. http://www.ncbi.nlm.nih.gov/pubmed/25711536 for a pubmed id? perhaps maintain an application wide database of database accessors constructors...
@param database a key to identify database, e.g. PMID, PMCID, JSTOR, PSYCHLIT, etc.
@return ascension number (or link) for this citation in given database key
*/
-(NSString *)ascensionForDatabase:(NSString *)database;
/** store an ascension number/string for the given database ID
No Op. if either ascension or database are nil
@param database n NSString key to identify database, e.g. PMID, PMCID, JSTOR, PSYCHLIT, doi, url, etc.
@param ascension an NSString containing the ascension number (or link) within the given database
*/
-(void)setAscension:(NSString *)ascension forDatabase:(NSString *)database;
-(NSDictionary *)packIntoDictionary;
-(void)unpackFromDictionary:(NSDictionary *)theDictionary;
/** open dialog to allow editing of citation
*/
-(void)edit;
/** dialog was closed
returnFlag = YES if OK pressed
returnFlag = NO if Cancel pressed
*/
-(void)finishedEditing:(BOOL)returnFlag;
/**
#Papers.app CiteKey Reverse Lookup
When a Papers.app universal citekey is pasted into a Caravan text file, or a reference is dragged from the Papers.app library window, the citation is inserted with the given citekey. (A Papers.app citekey is identified as the form "{<author>:YYYYaa}, where YYYY is a 4-digit year and aa is a 2-character hash code.) Caravan then performs a reverse lookup of the citekey in the Papers.app database.
The Papers.app "Database.papersdb" is an SQLite library, usually located within the Papers.app library folder, e.g., at '/Users/your_name/Documents/Papers2/Library.papers2/Database.papersdb'. Caravan uses the [FMDB Wrapper](https://github.com/ccgus/fmdb) for sqlite access.
The "Database.papersdb" does not store the universal citekey of each paper explicitly, so the corresponding paper must be found by calculating the citekey for likely papers and selecting the paper which matches. Given a citekey such as "{Houpt:2003ud}", all entries in the database with first author "Houpt" published in the year "2003" are retrived, and their citekeys calculated from their titles and doi entries to find the paper with the hash "ud". The citation information for the matched paper is then retrieved from the sqlite database and used to populate the Caravan citation fields.
##sqlite notes
Caravan constructs a query string from the known citekey author and year, to retrieve all entries by that first author in that ear:
```
queryString = [NSString stringWithFormat:@"SELECT title, doi, uuid FROM Publication WHERE citekey_base = '%@' AND publication_date LIKE '%@%%'", citekeyAuthor,citekeyYearField];
```
One a matching entry is found, Caravan populates its citation fields using information from the following columns in the database file:
@"citekey_base" (first author),
@"title",
@"publication_date",
@"doi",
@"full_author_string",
@"attributed_title" (journal title),
@"abbreviation" (journal abbreviation),
@"volume",
@"number",
@"startpage",
@"endpage",
// NOTE: need to update with fields for other item types such as book chapter, books, etc.
*/
-(BOOL)citekeyReverseLookup:(NSString *)theCitekey fromLibraryFolder:(NSString *)libraryPath;
/** return the citations pmid, or @"--" if not found
*/
-(NSString *)pmid;
/** return an image containging citekey as a rounded blue token
*/
-(NSImage *)citeKeyTokenImage:(CGFloat)fontHeight;
/** return the citation formated as a chucnk of bibtex yaml for use in pandoc document
*/
-(NSString *)bibtex_yaml;
/** get year of publication date as NSString yyyy
*/
-(NSString *)publicationYearString;
@end