summaryrefslogtreecommitdiff
path: root/scraper/client/paper/paper.verify.js
blob: 8794feb43d949448f6b518911cd2f3c05a258dc6 (plain)
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import * as actions from '../actions'
import { history } from '../store'
import { Loader, Autocomplete } from '../common'
import { USES_DATASET } from '../types'

const initialState = {
  citation: null,
  address: {},
  uses_dataset: USES_DATASET.UNKNOWN,
  images_in_paper: "FALSE",
  used_as_model: "FALSE",
  verified_by: localStorage.getItem('verify.username') || '',
  reference: '',
  notes: '',
  location: '',
  pdf_index: 0,
  isUnknown: false,
  institution_1: '',
  institution_2: '',
  institution_3: '',
  validate_1: false,
  validate_2: false,
  validate_3: false,
}

class PaperVerify extends Component {
  state = {
    ...initialState
  }

  componentDidMount() {
    const { sha256 } = this.props.match.params
    this.props.actions.getInstitutions()
    this.props.actions.getAddress(sha256)
    this.props.actions.getVerification(this.props.api.paperInfo.dataset.key, sha256)
    const citationState = this.getCitationState(sha256)
    // console.log('DID MOUNT')
    this.setState(citationState)
  }

  componentDidUpdate(oldProps) {
    const { sha256 } = this.props.match.params
    const { address, verify } = this.props.api
    const { sha256: oldSha256 } = oldProps.match.params
    const { verify: oldVerify, address: oldAddress } = oldProps.api
    const oldPaper = oldVerify ? oldVerify.paper : null
    const paper = verify ? verify.paper : null
    let newState = {}

    if (oldSha256 && sha256 !== oldSha256) {
      // console.log('update verification')
      this.props.actions.getAddress(sha256)
      this.props.actions.getVerification(this.props.api.paperInfo.dataset.key, sha256)
      const citationState = this.getCitationState(sha256)
      newState = {
        ...initialState,
        ...citationState,
        ...address.paper,
        pdfIndex: citationState.citation.pdf.findIndex(el => el.match(/^https:/)),
      }
      this.setState(newState)
    } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) {
      if (paper.error) {
        console.log('USING PAPER VERIFICATION')
        const citationState = this.getCitationState(sha256)
        newState = {
          ...initialState,
          ...citationState,
          ...address.paper,
          pdfIndex: citationState.citation.pdf.findIndex(el => el.match(/^https:/)),
        }
        this.setState(newState)
      } else {
        // console.log(paper)
        console.log('GOT CUSTOM CITATION STATE', paper)
        const citationState = this.getCitationState(sha256)
        newState = {
          ...citationState,
          ...address.paper,
          pdfIndex: citationState.citation.pdf.findIndex(el => el.match(/^https:/)),
          uses_dataset: paper.uses_dataset,
          images_in_paper: paper.images_in_paper,
          verified_by: paper.verified_by,
          reference: paper.reference,
          notes: paper.notes,
        }
        this.setState(newState)
      }
    } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) {
      console.log('loaded unknown citations')
      const citationState = this.getCitationState(sha256)
      newState = citationState
      this.setState(newState)
    }
  }

  getCitationState(sha256) {
    const { paperInfo, unknownCitations } = this.props.api
    let citation = (unknownCitations.citations || []).find(f => f.id === sha256)
    if (citation) {
      citation.isUnknown = true
    } else {
      citation = (paperInfo.citations || []).find(f => f.id === sha256)
      if (citation) {
        citation.isUnknown = false
      }
    }
    // console.log(sha256, citation)
    let state = { citation }
    return state
  }

  save() {
    console.log(this.state)
    let date = new Date()
    let mon = date.getMonth() + 1
    if (mon < 10) mon = "0" + mon
    let day = date.getDate()
    if (day < 10) day = "0" + day
    let time = date.toTimeString().split(" ")[0]
    let dateString = date.getFullYear() + '-' + mon + '-' + day + ' ' + time
    localStorage.setItem('verify.username', this.state.verified_by)
    this.props.actions.postVerification({
      paper_id: this.state.citation.id,
      title: this.state.citation.title,
      dataset: this.props.api.paperInfo.dataset.key,
      uses_dataset: this.state.uses_dataset,
      images_in_paper: this.state.images_in_paper,
      used_as_model: this.state.used_as_model,
      verified_by: this.state.verified_by,
      reference: this.state.reference,
      notes: this.state.notes,
      date: dateString,
      isUnknown: this.state.citation.isUnknown,
      institution_1: this.state.institution_1,
      validate_1: this.state.validate_1,
      institution_2: this.state.institution_2,
      validate_2: this.state.validate_2,
      institution_3: this.state.institution_3,
      validate_3: this.state.validate_3,
    })
    this.next()
  }

  prev() {
    const { key } = this.props.api.paperInfo.dataset
    const { paperInfo, sortedCitations } = this.props.api
    const citations = sortedCitations || paperInfo.citations || []
    let citationIndex = citations.findIndex(f => f.id === this.state.citation.id)

    if (citationIndex === -1) {
      history.push('/paper/' + key + '/info/')
    } else {
      citationIndex -= 1
      if (citationIndex < 0) {
        history.push('/paper/' + key + '/info/')
      } else {
        let nextId = sortedCitations[citationIndex].id
        history.push('/paper/' + key + '/verify/' + nextId)
      }
    }
  }

  next() {
    const { key } = this.props.api.paperInfo.dataset
    const { paperInfo, sortedCitations } = this.props.api
    const citations = sortedCitations || paperInfo.citations || []
    let citationIndex = citations.findIndex(f => f.id === this.state.citation.id)
    console.log(sortedCitations)
    console.log('going to next', key, citationIndex)
    if (citationIndex === -1) {
      history.push('/paper/' + key + '/info/')
    } else {
      citationIndex += 1
      if (citationIndex >= sortedCitations.length) {
        history.push('/paper/' + key + '/info/')
      } else {
        let nextId = sortedCitations[citationIndex].id
        history.push('/paper/' + key + '/verify/' + nextId)
      }
    }
  }

  render() {
    const { paperInfo, unknownCitations } = this.props.api
    if (paperInfo.loading) return <Loader />
    // console.log(this.state)
    const { citation } = this.state
    if (!citation) {
      return <div>Citation not found in this paper</div>
    }
    // console.log(citation)
    return (
      <div className='form'>
        <h3>{citation.title}</h3>
        <div className='gray'>
          {citation.id}
          {citation.pdf.length ? ' | PDF: ' : ''}
          {citation.pdf.map((pdf, i) => {
            const domain = pdf.replace('www.','').split('/').slice(2,3)[0] || 'unknown'
            return (
              <a
                key={i}
                href={pdf}
                rel={"noopener noreferrer"}
                onClick={() => this.setState({ pdf_index: i })}
                className={i === this.state.pdf_index ? 'selected pdfLink' : 'pdfLink'}
              >
                {'[' + domain + '] '}
              </a>
            )
          })}
          {(citation.doi && citation.doi.length) ? ' | DOI: ' : ''}
          {(citation.doi || []).map((doi, i) => {
            if (!doi) return null
            const domain = doi.replace('www.','').split('/').slice(2,3)[0] || 'unknown'
            return (
              <a
                key={i}
                href={doi}
                target={"_blank"}
                rel={"noopener noreferrer"}
                className={'pdfLink'}
              >
                {'[' + domain + ']'}
              </a>
            )
          })}
          {' | '}
          <a
            href={'https://www.semanticscholar.org/paper/' + citation.id}
            target="_blank"
            rel={"noopener noreferrer"}
            className={'pdfLink'}
          >
            {'Semantic Scholar'}
          </a>
          {' | '}
          <a
            href={'https://duckduckgo.com/?q=' + encodeURIComponent(citation.title)}
            target="_blank"
            rel={"noopener noreferrer"}
            className={'pdfLink'}
          >
            {'Search DuckDuckGo'}
          </a>
        </div>

        {this.renderLocationForm()}

        <div className='row vettingRow'>
          <div className='rowHeading'>
            {'Uses dataset'}
          </div>
          <label>
            <input
              className='vetting'
              type='radio'
              name='uses_dataset'
              checked={String(this.state.uses_dataset) === USES_DATASET.YES}
              onChange={e => this.setState({
                uses_dataset: USES_DATASET.YES,
              })}
            />
            <div>{"Yes"}</div>
          </label>

          <label>
            <input
              className='vetting'
              type='radio'
              name='uses_dataset'
              checked={String(this.state.uses_dataset) === USES_DATASET.NO}
              onChange={e => this.setState({
                uses_dataset: USES_DATASET.NO,
              })}
            />
            <div>{"No"}</div>
          </label>

          <label>
            <input
              className='vetting'
              type='radio'
              name='uses_dataset'
              checked={String(this.state.uses_dataset) !== USES_DATASET.YES && String(this.state.uses_dataset) !== USES_DATASET.NO}
              onChange={e => this.setState({
                uses_dataset: USES_DATASET.UNKNOWN,
              })}
            />
            <div>{"Not enough information"}</div>
          </label>
        </div>

        <div
          className={String(this.state.uses_dataset) === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'}
          disabled={String(this.state.uses_dataset) === USES_DATASET.YES ? false : true}
        >
          <div className='rowHeading'>
            {'Paper shows images'}
          </div>

          <label>
            <input
              className='vetting'
              type='radio'
              name='images_in_paper'
              checked={this.state.images_in_paper === "TRUE"}
              onChange={e => this.setState({
                images_in_paper: "TRUE",
              })}
            />
            <div>{"Yes"}</div>
          </label>

          <label>
            <input
              className='vetting'
              type='radio'
              name='images_in_paper'
              checked={this.state.images_in_paper === "FALSE"}
              onChange={e => this.setState({
                images_in_paper: "FALSE",
              })}
            />
            <div>{"No"}</div>
          </label>
        </div>

        <div className='row vettingRow'>
          <div className='rowHeading'>
            {'Used as model'}
          </div>

          <label>
            <input
              className='vetting'
              type='radio'
              name='used_as_model'
              checked={this.state.used_as_model === "TRUE"}
              onChange={e => this.setState({
                used_as_model: "TRUE",
              })}
            />
            <div>{"Yes"}</div>
          </label>

          <label>
            <input
              className='vetting'
              type='radio'
              name='used_as_model'
              checked={this.state.used_as_model === "FALSE"}
              onChange={e => this.setState({
                used_as_model: "FALSE",
              })}
            />
            <div>{"No"}</div>
          </label>
        </div>

        <div className='param'>
          <label>Verified by:</label>
          <input
            type='text'
            className='verified_by'
            value={this.state.verified_by}
            placeholder='Verified by'
            onChange={e => this.setState({ verified_by: e.target.value })}
          />
        </div>

        <div className='param'>
          <label>Reference</label>
          <textarea
            rows={3}
            cols={50}
            type='text'
            className='reference'
            value={this.state.reference}
            placeholder='Reference'
            onChange={e => this.setState({ reference: e.target.value })}
          />
        </div>

        <div className='param'>
          <label>Notes</label>
          <textarea
            rows={3}
            cols={50}
            type='text'
            className='notes'
            value={this.state.notes}
            placeholder='Notes'
            onChange={e => this.setState({ notes: e.target.value })}
          />
        </div>

        <div className='param'>
          <button
            className='btn btn-primary'
            onClick={this.save.bind(this)}
            ref={ref => this.button = ref}
          >Save Verification</button>

          <button
            className='btn'
            onClick={this.prev.bind(this)}
          >{'< Prev'}</button>

          <button
            className='btn'
            onClick={this.next.bind(this)}
          >{'Next >'}</button>
        </div>

        {citation.pdf.length
        ? <iframe className='pdfViewer' referrerPolicy='no-referrer' src={citation.pdf[this.state.pdf_index] || "about:blank"} />
        : ''
        }
      </div>
    )
  }
  renderLocationForm() {
    if (!this.state.citation.isUnknown) return
    return (
      <div>
        <div className='param'>
          <label>Institution #1</label>
          <Autocomplete
            placeholder='Institution #1'
            value={this.state.institution_1}
            onSelect={(institution_1, validate_1) => {
              this.setState({ institution_1, validate_1 })
            }}
            onCancel={value => {
              this.setState({ institution_1: '', validate_1: false })
            }}
          />
        </div>

        <div className='param'>
          <label>Institution #2</label>
          <Autocomplete
            placeholder='Institution #2'
            value={this.state.institution_2}
            onSelect={(institution_2, validate_2) => {
              this.setState({ institution_2, validate_2 })
            }}
            onCancel={value => {
              this.setState({ institution_2: '', validate_2: false })
            }}
          />
        </div>

        <div className='param'>
          <label>Institution #3</label>
          <Autocomplete
            placeholder='Institution #3'
            value={this.state.institution_3}
            onSelect={(institution_3, validate_3) => {
              this.setState({ institution_3, validate_3 })
            }}
            onCancel={value => {
              this.setState({ institution_3: '', validate_3: false })
            }}
          />
        </div>
      </div>
    )
  }
}

/*
        <div className='param'>
          <label>{"Verifiable"}</label>
          <input
            className='vetting'
            type='checkbox'
            name='verifiable'
            checked={!!this.state.verifiable}
            onChange={e => this.setState({
              verifiable: e.target.checked,
            })}
          />
        </div>
*/

const mapStateToProps = state => ({
  api: state.api,
})
const mapDispatchToProps = dispatch => ({
  actions: bindActionCreators({ ...actions }, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(PaperVerify)