This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtext.go
67 lines (51 loc) · 1.64 KB
/
text.go
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
package goscholar
import (
"regexp"
"strings"
)
func parseYearText(s string) (year string) {
re, _ := regexp.Compile("\\s\\d{4}\\s")
year = strings.TrimSpace(string(re.Find([]byte(s))))
if year == "" {
re, _ = regexp.Compile("\\s\\d{4}")
year = strings.TrimSpace(string(re.Find([]byte(s))))
}
return year
}
func parseClusterIdText(url string) (clusterId string) {
clusterId = strings.TrimPrefix(url, "/scholar?cites=")
clusterId = clusterId[:strings.Index(clusterId, "&")]
return strings.TrimSpace(clusterId)
}
func parseNumCiteText(s string) (numCite string) {
s = strings.TrimPrefix(s, "Cited by")
return strings.TrimSpace(s)
}
func parseNumVerText(s string) (numVer string) {
s = strings.TrimPrefix(s, "All")
s = strings.TrimSuffix(s, "versions")
return strings.TrimSpace(s)
}
func parseInfoIdText(url string) (infoId string) {
infoId = strings.TrimPrefix(url, "/scholar?q=related:")
infoId = infoId[:strings.Index(infoId, ":scholar.google.com")]
return strings.TrimSpace(infoId)
}
func parseLinkText(s string) (name, format string) {
ix := strings.Index(s, " ")
name = strings.TrimSpace(s[:ix])
format = strings.TrimSpace(s[ix:])
return name, format[1 : len(format)-1]
}
// checkDoubleQuotation return true if s starts and ends with double quotation
// E.g. checkDoubleQuotation("\"y bengio\"") => true
func enclosedInDoubleQuotation(s string) bool {
if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") {
return true
} else {
return false
}
}
func generateBibTeXLink(infoId string) (bibtexLink string) {
return scholar_url + "scholar.bib?q=info:" + infoId + ":scholar.google.com/&output=citation&hl=en&ct=citation"
}