|
@@ -0,0 +1,69 @@
|
|
|
+# Author: Esty Thomas
|
|
|
+# License: GPL v3.0
|
|
|
+
|
|
|
+# If the list of authors will return a search term
|
|
|
+# under 2048 characters, indep() will use this
|
|
|
+# which simply returns a string of the format
|
|
|
+# author:'name 1' OR author:'name 2' etc
|
|
|
+def indep_short(authl)
|
|
|
+ authors=authl.join("' OR author:'")
|
|
|
+ authors="author:'"+authors+"'"
|
|
|
+ return authors
|
|
|
+end
|
|
|
+
|
|
|
+# If the list of authors will return a search term
|
|
|
+# over 2048 characters, indep() will use this
|
|
|
+# which recursively splits the list until each
|
|
|
+# separate output term will be under 2048 characters
|
|
|
+# and returns them in an array.
|
|
|
+# It's not the prettiest hack but it will do until
|
|
|
+# I start figuring out how to make this into a browser
|
|
|
+# extension or something.
|
|
|
+def indep_long(authl)
|
|
|
+ half = (authl.length/2).floor
|
|
|
+ authl1 = authl.take(half)
|
|
|
+ authl2 = authl.drop(half)
|
|
|
+ authors1 = "author:'"+authl1.join("' OR author:'")+"'"
|
|
|
+ authors2 = "author:'"+authl2.join("' OR author:'")+"'"
|
|
|
+ if (authors1.length>2048) && (authors2.length<2048)
|
|
|
+ return [indep_long(authl1), authors2] #split authl1
|
|
|
+ elsif (authors1.length<2048) && (authors2.length>2048)
|
|
|
+ return [authors1, indep_long(authl2)] #split authl2
|
|
|
+ elsif (authors1.length>2048) && (authors2.length>2048)
|
|
|
+ return [indep_long(authl1), indep_long(authl2)] #split both
|
|
|
+ else
|
|
|
+ return [authors1, authors2]
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+# only use 'sort' when you have an author list like this:
|
|
|
+# "Last, First, First Last, First Last, and First Last"
|
|
|
+# it will give you the author list back like this:
|
|
|
+# "First Last, First Last, First Last, First Last"
|
|
|
+# so you can put it into 'indep'
|
|
|
+def sort(auth)
|
|
|
+ authl = auth.split(", ")
|
|
|
+ authl[1] = authl[1] + " " + authl[0]
|
|
|
+ authl = authl.drop(1)
|
|
|
+ last = authl[-1]
|
|
|
+ lastl = last.split(" ")
|
|
|
+ lastnew = lastl.drop(1).join(" ")
|
|
|
+ authl[-1] = lastnew
|
|
|
+ return authl.join(", ")
|
|
|
+end
|
|
|
+
|
|
|
+# this will give you search terms you can use in Google Scholar
|
|
|
+# use this for author lists like this:
|
|
|
+# "First Last, First Last, First Last, First Last"
|
|
|
+# If the list starts "Last, First" and ends "and First Last"
|
|
|
+# put it into 'sort' and use the result
|
|
|
+def indep(auth)
|
|
|
+ authl = auth.split(", ")
|
|
|
+ if (auth.length+9+(authl.length-1)) < 2048
|
|
|
+ return indep_short(authl)
|
|
|
+ else
|
|
|
+ return indep_long(authl)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|