This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathfacethighlight.Rmd
208 lines (164 loc) · 4.77 KB
/
facethighlight.Rmd
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
---
title: Faceted and highlighted searches
author: Scott Chamberlain
date: "2021-02-23"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Faceted and highlighted searches}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
In addition to `searchplos()` and related searching functions, there are a
few slightly different ways to search: faceting and highlighted searches.
Faceting allows you to ask, e.g., how many articles are published in each of
the PLOS journals. Highlighting allows you to ask, e.g., highlight terms that
I search for in the text results given back, which can make downstream
processing easier, and help visualize search results (see `highbrow()` below).
### Load package from CRAN
```r
install.packages("rplos")
```
```r
library('rplos')
```
### Faceted search
Facet by journal
```r
facetplos(q='*:*', facet.field='journal')
```
```
#> $facet_queries
#> NULL
#>
#> $facet_fields
#> $facet_fields$journal
#> # A tibble: 9 x 2
#> term value
#> <chr> <chr>
#> 1 plos one 2073767
#> 2 plos genetics 77191
#> 3 plos neglected tropical diseases 72937
#> 4 plos pathogens 71789
#> 5 plos computational biology 66404
#> 6 plos biology 44593
#> 7 plos medicine 32612
#> 8 plos clinical trials 521
#> 9 plos medicin 9
#>
#>
#> $facet_pivot
#> NULL
#>
#> $facet_dates
#> NULL
#>
#> $facet_ranges
#> NULL
```
Using `facet.query` to get counts
```r
facetplos(q='*:*', facet.field='journal', facet.query='cell,bird')
```
```
#> $facet_queries
#> # A tibble: 1 x 2
#> term value
#> <chr> <int>
#> 1 cell,bird 12052
#>
#> $facet_fields
#> $facet_fields$journal
#> # A tibble: 9 x 2
#> term value
#> <chr> <chr>
#> 1 plos one 2073767
#> 2 plos genetics 77191
#> 3 plos neglected tropical diseases 72937
#> 4 plos pathogens 71789
#> 5 plos computational biology 66404
#> 6 plos biology 44593
#> 7 plos medicine 32612
#> 8 plos clinical trials 521
#> 9 plos medicin 9
#>
#>
#> $facet_pivot
#> NULL
#>
#> $facet_dates
#> NULL
#>
#> $facet_ranges
#> NULL
```
Date faceting
```r
facetplos(q='*:*', url=url, facet.date='publication_date',
facet.date.start='NOW/DAY-5DAYS', facet.date.end='NOW',
facet.date.gap='+1DAY')
```
```
#> list()
```
### Highlighted search
Search for the term _alcohol_ in the abstracts of articles, return only
10 results
```r
highplos(q='alcohol', hl.fl = 'abstract', rows=2)
```
```
#> $`10.1371/journal.pone.0218147`
#> $`10.1371/journal.pone.0218147`$abstract
#> [1] "Background: Binge drinking, an increasingly common form of <em>alcohol</em> use disorder, is associated"
#>
#>
#> $`10.1371/journal.pone.0138021`
#> $`10.1371/journal.pone.0138021`$abstract
#> [1] "Background and Aim: Harmful <em>alcohol</em> consumption has long been recognized as being the major"
```
Search for the term _alcohol_ in the abstracts of articles, and return
fragment size of 20 characters, return only 5 results
```r
highplos(q='alcohol', hl.fl='abstract', hl.fragsize=20, rows=2)
```
```
#> $`10.1371/journal.pone.0218147`
#> $`10.1371/journal.pone.0218147`$abstract
#> [1] " common form of <em>alcohol</em>"
#>
#>
#> $`10.1371/journal.pone.0138021`
#> $`10.1371/journal.pone.0138021`$abstract
#> [1] ": Harmful <em>alcohol</em>"
```
Search for the term _experiment_ across all sections of an article, return
id (DOI) and title fl only, search in full articles only
(via `fq='doc_type:full'`), and return only 10 results
```r
highplos(q='everything:"experiment"', fl='id,title', fq='doc_type:full',
rows=2)
```
```
#> $`10.1371/journal.pone.0154334`
#> $`10.1371/journal.pone.0154334`$everything
#> [1] " and designed the <em>experiments</em>: RJ CM AOC. Performed the <em>experiments</em>: RJ AOC. Analyzed the data: RJ. Contributed"
#>
#>
#> $`10.1371/journal.pone.0039681`
#> $`10.1371/journal.pone.0039681`$everything
#> [1] " Selection of Transcriptomics <em>Experiments</em> Improves Guilt-by-Association Analyses Transcriptomics <em>Experiment</em>"
```
### Visualize highligted searches
Browse highlighted fragments in your default browser
This first examle, we only looko at 10 results
```r
out <- highplos(q='alcohol', hl.fl = 'abstract', rows=10)
highbrow(out)
```
![highbrow1](../man/figures/highbrow.png)
But it works quickly with lots of results too
```r
out <- highplos(q='alcohol', hl.fl = 'abstract', rows=1200)
highbrow(out)
```
![highbrow2](../man/figures/highbrow_big.png)