Revision: 27532
http://sourceforge.net/p/bibdesk/svn/27532
Author: hofman
Date: 2022-06-03 14:14:07 +0000 (Fri, 03 Jun 2022)
Log Message:
-----------
Parse URL strings for project Euclid and numdam parsers before passing it to
the download object. Let the proper parser class add the URL so it can be added
first.
Modified Paths:
--------------
trunk/bibdesk/BDSKMathSciNetParser.m
trunk/bibdesk/BDSKNumdamParser.m
trunk/bibdesk/BDSKProjectEuclidParser.m
trunk/bibdesk/BDSKZentralblattParser.m
Modified: trunk/bibdesk/BDSKMathSciNetParser.m
===================================================================
--- trunk/bibdesk/BDSKMathSciNetParser.m 2022-06-03 09:46:44 UTC (rev
27531)
+++ trunk/bibdesk/BDSKMathSciNetParser.m 2022-06-03 14:14:07 UTC (rev
27532)
@@ -72,7 +72,7 @@
NSMutableArray * IDArray = [NSMutableArray
arrayWithCapacity:[regexpResults count]];
for (AGRegexMatch * match in regexpResults) {
- NSString * matchedString = [[match string]
substringWithRange:[match rangeAtIndex:1]];
+ NSString * matchedString = [match groupAtIndex:1];
if (![IDArray containsObject:matchedString]) {
[IDArray addObject:matchedString];
}
@@ -163,11 +163,17 @@
[results addObjectsFromArray:[parser
itemsFromBibTeXString:cleanedRecord error:NULL]];
}
+ // The extra URL can be passed by the BDSKProjectEuclidParser or
BDSKNumdamParser
+ NSString * URLString = [[download contextInfo] objectForKey:@"URLString"];
+
// Add a URL reference pointing to the review's web page to each record.
for (BibItem * item in results) {
NSString * MRNumber = [[item citeKey] stringByRemovingPrefix:@"MR"];
NSString * MRItemURL = [[NSURL
URLWithString:[@"/mathscinet-getitem?mr=" stringByAppendingString:MRNumber]
relativeToURL:[download URL]] absoluteString];
+ if ( URLString )
+ [item addURLString:URLString];
[item addURLString:MRItemURL];
+ URLString = nil;
}
return results;
Modified: trunk/bibdesk/BDSKNumdamParser.m
===================================================================
--- trunk/bibdesk/BDSKNumdamParser.m 2022-06-03 09:46:44 UTC (rev 27531)
+++ trunk/bibdesk/BDSKNumdamParser.m 2022-06-03 14:14:07 UTC (rev 27532)
@@ -88,7 +88,7 @@
NSObject * MRID = nil;
if (match) {
NSUInteger count;
- MRID = [[[match string] substringWithRange:[match rangeAtIndex:1]]
stringByReplacingOccurrencesOfString:@" #" withString:@":"
options:NSLiteralSearch replacements:&count];
+ MRID = [[match groupAtIndex:1]
stringByReplacingOccurrencesOfString:@" #" withString:@":"
options:NSLiteralSearch replacements:&count];
}
*/
@@ -95,7 +95,7 @@
match = [ZMathRegexp findInString:item];
NSObject * ZMathID = nil;
if (match) {
- ZMathID = [[match string] substringWithRange:[match
rangeAtIndex:1]];
+ ZMathID = [match groupAtIndex:1];
}
/*
@@ -116,11 +116,17 @@
}
}
+ NSString * URLString = nil;
+ AGRegex * URLRegexp = [AGRegex regexWithPattern:@"stable URL:
([a-zA-Z0-9:=./?_]*)" options:0];
+ match = [URLRegexp findInString:content];
+ if ([match count] >= 2)
+ URLString = [match groupAtIndex:1];
+
/*
NSArray * MRRequests = [BDSKMathSciNetParser
bibTeXRequestsForZMathIDs:ZMathReferences referrer:[self URL] error:outError];
for (NSURLRequest *request in MRRequests) {
- NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass",
firstMRIDIsOwnId ? content : nil, @"content", nil];
+ NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass",
firstMRIDIsOwnId ? URLString : nil, @"URLString", nil];
[self addDownloadWithRequest:request contextInfo:contextInfo];
firstMRIDIsOwnId = NO;
}
@@ -129,7 +135,7 @@
NSArray * ZMathRequests = [BDSKZentralblattParser
bibTeXRequestsForZMathIDs:ZMathReferences referrer:[self URL] error:outError];
for (NSURLRequest *request in ZMathRequests) {
- NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass",
firstZMathIDIsOwnId ? content : nil, @"content", nil];
+ NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass",
firstZMathIDIsOwnId ? URLString : nil, @"URLString", nil];
[self addDownloadWithRequest:request contextInfo:contextInfo];
firstZMathIDIsOwnId = NO;
}
@@ -138,36 +144,9 @@
}
- (NSArray *)itemsFromDownload:(BDSKCitationDownload *)download error:(NSError
**)outError {
- NSArray *results = nil;
- NSDictionary *contextInfo = [download contextInfo];
- Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
- NSString *content = [contextInfo objectForKey:@"content"];
+ Class parserClass = (Class)[[download contextInfo]
objectForKey:@"parserClass"];
- results = [parserClass itemsFromDownload:download parser:self
error:outError];
-
- if ([results count] > 0 && content != nil) {
- // add Numdam URL to item's own record
- BibItem *item = [results objectAtIndex:0];
- AGRegex * URLRegexp = [AGRegex regexWithPattern:@"stable URL:
([a-zA-Z0-9:=./?_]*)" options:0];
- AGRegexMatch * match = [URLRegexp findInString:content];
-
- if ([match count] >= 2) {
- NSString * myURLString = [[match string] substringWithRange:[match
rangeAtIndex:1]];
-
- if ( myURLString ) {
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud
boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
-
- if ( addUrlField )
- [item setField:BDSKUrlString toValue:myURLString];
- if ( addLinkedFiles )
- [item insertObject:[BDSKLinkedFile
linkedFileWithURLString:myURLString] inFilesAtIndex:0];
- }
- }
- }
-
- return results;
+ return [parserClass itemsFromDownload:download parser:self error:outError];
}
+ (NSString *)name { return @"NUMDAM"; }
Modified: trunk/bibdesk/BDSKProjectEuclidParser.m
===================================================================
--- trunk/bibdesk/BDSKProjectEuclidParser.m 2022-06-03 09:46:44 UTC (rev
27531)
+++ trunk/bibdesk/BDSKProjectEuclidParser.m 2022-06-03 14:14:07 UTC (rev
27532)
@@ -79,10 +79,10 @@
// find IDs for the item itself
match = [MRRegexp findInString:identifierString];
- myMRID = [[match string] substringWithRange:[match rangeAtIndex:1]];
+ myMRID = [match groupAtIndex:1];
if (myMRID == nil) {
match = [ZMathRegexp findInString:identifierString];
- myZMathID = [[match string] substringWithRange:[match
rangeAtIndex:1]];
+ myZMathID = [match groupAtIndex:1];
}
// Set up arrays for the lists of MathSciNet and Zentralblatt IDs.
These will have the ID for the current element at position 0 and contain NSNull
when no ID is found for the respective service.
@@ -105,22 +105,26 @@
}
}
+ AGRegex * ProjectEuclidRegexp = [AGRegex
regexWithPattern:@"(https://projecteuclid.org/[^\\s]*)" options:0];
+ match = [ProjectEuclidRegexp findInString:identifierString];
+ NSString * projectEuclidURLString = [match groupAtIndex:1];
+
MRRequests = [BDSKMathSciNetParser bibTeXRequestsForMRIDs:MRIDs
referrer:[self URL] error:outError];
- NSString *myIdentifier = myMRID ? identifierString : nil;
+ NSString *URLString = myMRID ? projectEuclidURLString : nil;
for (NSURLRequest *request in MRRequests) {
- NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass",
myIdentifier, @"myIdentifier", nil];
+ NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass",
URLString, @"URLString", nil];
[self addDownloadWithRequest:request contextInfo:contextInfo];
- myIdentifier = nil;
+ URLString = nil;
}
ZMathRequests = [BDSKZentralblattParser
bibTeXRequestsForZMathIDs:ZMathIDs referrer:[self URL] error:outError];
- myIdentifier = myZMathID ? identifierString : nil;
+ URLString = myZMathID ? projectEuclidURLString : nil;
for (NSURLRequest *request in ZMathRequests) {
- NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass",
myIdentifier, @"myIdentifier", nil];
+ NSDictionary *contextInfo = [NSDictionary
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass",
URLString, @"URLString", nil];
[self addDownloadWithRequest:request contextInfo:contextInfo];
- myIdentifier = nil;
+ URLString = nil;
}
}
@@ -129,32 +133,9 @@
}
- (NSArray *)itemsFromDownload:(BDSKCitationDownload *)download error:(NSError
**)outError {
- NSArray *results = nil;
- NSDictionary *contextInfo = [download contextInfo];
- Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
- NSString *myIdentifier = [contextInfo objectForKey:@"myIdentifier"];
+ Class parserClass = (Class)[[download contextInfo]
objectForKey:@"parserClass"];
- results = [parserClass itemsFromDownload:download parser:self
error:outError];
-
- if ([results count] > 0 && myIdentifier != nil) {
- // add Project Euclid URL to item's own record
- BibItem * item = [results objectAtIndex:0];
- AGRegex * ProjectEuclidRegexp = [AGRegex
regexWithPattern:@"(https://projecteuclid.org/[^\\s]*)" options:0];
- AGRegexMatch * match = [ProjectEuclidRegexp findInString:myIdentifier];
- NSString * projectEuclidURLString = [[match string]
substringWithRange:[match rangeAtIndex:1]];
-
- if ( projectEuclidURLString ) {
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud
boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
- if ( addUrlField )
- [item setField:BDSKUrlString toValue:projectEuclidURLString];
- if ( addLinkedFiles )
- [item insertObject:[BDSKLinkedFile
linkedFileWithURLString:projectEuclidURLString] inFilesAtIndex:0];
- }
- }
-
- return results;
+ return [parserClass itemsFromDownload:download parser:self error:outError];
}
+ (NSString *)name {return @"Project Euclid"; }
Modified: trunk/bibdesk/BDSKZentralblattParser.m
===================================================================
--- trunk/bibdesk/BDSKZentralblattParser.m 2022-06-03 09:46:44 UTC (rev
27531)
+++ trunk/bibdesk/BDSKZentralblattParser.m 2022-06-03 14:14:07 UTC (rev
27532)
@@ -72,7 +72,7 @@
NSMutableArray * IDArray = [NSMutableArray
arrayWithCapacity:[regexpResults count]];
for (AGRegexMatch *match in regexpResults) {
- NSString * matchedString = [[match string]
substringWithRange:[match rangeAtIndex:3]];
+ NSString * matchedString = [match groupAtIndex:3];
if (![IDArray containsObject:matchedString]) {
[IDArray addObject:matchedString];
}
@@ -142,12 +142,17 @@
bibTeXString = [umlautFixer replaceWithString:@"{$1}"
inString:bibTeXString];
NSArray * results = [parser itemsFromBibTeXString:bibTeXString
error:outError];
+ // The extra URL can be passed by the BDSKProjectEuclidParser or
BDSKNumdamParser
+ NSString * URLString = [[download contextInfo] objectForKey:@"URLString"];
// Add a URL reference to the review's web page to each record.
for (BibItem * item in results) {
NSString * ZMathID = [item citeKey];
NSString * ZMathItemURLString = [NSString
stringWithFormat:@"https://zbmath.org/search/?format=complete&q=an:%@",
ZMathID];
+ if ( URLString )
+ [item addURLString:URLString];
[item addURLString:ZMathItemURLString];
+ URLString = nil;
}
return results;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit