<commit_before>var css = require('dom-css')
var inherits = require('inherits')
var _ = require('lodash')
var EventEmitter = require('events').EventEmitter
var reader = require('./reader.js')

inherits(Paper, EventEmitter)

function Paper (container, opts) {
  if (!(this instanceof Paper)) return new Paper(container, opts)
  var self = this
  this.opts = opts

  var box = container.appendChild(document.createElement('div'))
  box.className = 'paper'
  var title = box.appendChild(document.createElement('div'))
  var author = box.appendChild(document.createElement('div'))
  var year = box.appendChild(document.createElement('div'))
  var overlay = box.appendChild(document.createElement('div'))
  var lens = overlay.appendChild(document.createElement('img'))
  lens.src = './images/lens.png'

  var lensReader = null

  var base = {
    position: 'absolute',
    fontFamily: 'Aleo-Regular',
    textAlign: 'left',
    color: 'rgb(178,180,184)'
  }

  css(box, {
    position: 'relative',
    background: 'rgb(43,43,51)',
    display: 'inline-block',
    marginRight: '20px',
    marginBottom: '20px',
    cursor: 'pointer'
  })

  css(overlay, {
    position: 'absolute',
    left: 0,
    top: 0,
    width: '100%',
    height: '100%',
    display: 'none',
    background: 'rgba(255, 255, 255, 0.4)',
    alignItems: 'center',
    justifyContent: 'center'
  })

  css(lens, {
    width: '20%'
  })

  self.layout = function () {

    var width = '160'

    css(box, {
      width: width + 'px',
      height: width * 1.31,
      padding: width * 0.09
    })

    css(title, _.extend(_.clone(base), {
      fontSize: '14px',
      left: '10px',
      right: '10px',
      top: '10px',
      bottom: '40px',
      overflowY: 'scroll',
      overflowX: 'hidden'
    }))

    css(author, _.extend(_.clone(base), {
      fontSize: '10px',
      left: '10px',
      right: '40px',
      bottom: '10px'
    }))

    css(year, _.extend(_.clone(base), {
      position: 'absolute',
      fontSize: '14px',
      left: '120px',
      right: '10px',
      bottom: '10px'
    }))

  }

  self.update = function (value) {
    Object.assign(this, value)

    var pmcid = _.find(self.document.identifier, { type: 'pmcid' }).id
    this.pmcid = `PMC${pmcid}`

    title.innerHTML = value.document.title
    author.innerHTML = self.etalia(value.document.author)
    year.innerHTML = value.document.year

    self.loadFile()
  }

  self.etalia = function (authors) {
    var authorStrs = authors.map((a) => `${a.given_names} ${a.surname}`)
    if (authors.length > 3) {
      return authors[0] + ' et al.'
    } else {
      return authorStrs.join(', ')
    }
  }

  self.truncate = function (str, limit) {
    var  bits = str.split('')
    if (bits.length > limit) {
      for (var i = bits.length - 1; i > -1; --i) {
        if (i > limit) {
          bits.length = i
        }
        else if (' ' === bits[i]) {
          bits.length = i
          break
        }
      }
      bits.push('...')
    }
    return bits.join('')
  };

  self.downloadFailed = function (err) {
    css(box, {
      borderBottom: 'solid 7px rgb(202,77,107)'
    })
  }

  self.downloaded = function (file) {
    self.file = file.path
    css(box, {
      borderBottom: 'solid 7px rgb(202, 172, 77)'
    })
  }

  self.loadFile = function () {
    var self = this
    var filepath = this.filepath()
    fs.stat(filepath, function(err, stat) {
      if (err == null) {
        // file exists - show lens viewer button
        self.downloaded({ path: filepath })
        console.log('paper should be located at', filepath)
      } else if(err.code == 'ENOENT') {
        // file doesn't exist - do nothing
      } else {
        console.log('Error looking for file: ', filepath, err);
      }
    });
  }

  self.filepath = function() {
    var dir = opts.fulltextSource.dir
    var pmcid = self.pmcid
    var filepath = path.join(opts.datadir, dir, pmcid, 'fulltext.xml')
    return filepath
  }

  self.url = function() {
    var port = opts.contentServer.port
    var dir = opts.fulltextSource.dir
    var pmcid = self.pmcid
    var url = `http://localhost:${port}/${dir}/${pmcid}/fulltext.xml`
    console.log('paper should be served at', url)
    return url
  }

  self.layout()

  box.onclick  = function () {
    self.emit('click')
  }

  box.addEventListener("mouseenter", function(event) {
    if (self.file && contentServer.port) css(overlay, { display: 'flex' })
  })

  box.addEventListener("mouseleave", function(event) {
    css(overlay, { display: 'none' })
  })

  lens.onclick = function () {
    self.emit('lens-click')
    lensReader = reader(self, self.opts)
    lensReader.show()
    // TODO: destroy on close
  }
}

module.exports = Paper
<commit_msg>Fix author string rendering<commit_after>var css = require('dom-css')
var inherits = require('inherits')
var _ = require('lodash')
var EventEmitter = require('events').EventEmitter
var reader = require('./reader.js')

inherits(Paper, EventEmitter)

function Paper (container, opts) {
  if (!(this instanceof Paper)) return new Paper(container, opts)
  var self = this
  this.opts = opts

  var box = container.appendChild(document.createElement('div'))
  box.className = 'paper'
  var title = box.appendChild(document.createElement('div'))
  var author = box.appendChild(document.createElement('div'))
  var year = box.appendChild(document.createElement('div'))
  var overlay = box.appendChild(document.createElement('div'))
  var lens = overlay.appendChild(document.createElement('img'))
  lens.src = './images/lens.png'

  var lensReader = null

  var base = {
    position: 'absolute',
    fontFamily: 'Aleo-Regular',
    textAlign: 'left',
    color: 'rgb(178,180,184)'
  }

  css(box, {
    position: 'relative',
    background: 'rgb(43,43,51)',
    display: 'inline-block',
    marginRight: '20px',
    marginBottom: '20px',
    cursor: 'pointer'
  })

  css(overlay, {
    position: 'absolute',
    left: 0,
    top: 0,
    width: '100%',
    height: '100%',
    display: 'none',
    background: 'rgba(255, 255, 255, 0.4)',
    alignItems: 'center',
    justifyContent: 'center'
  })

  css(lens, {
    width: '20%'
  })

  self.layout = function () {

    var width = '160'

    css(box, {
      width: width + 'px',
      height: width * 1.31,
      padding: width * 0.09
    })

    css(title, _.extend(_.clone(base), {
      fontSize: '14px',
      left: '10px',
      right: '10px',
      top: '10px',
      bottom: '40px',
      overflowY: 'scroll',
      overflowX: 'hidden'
    }))

    css(author, _.extend(_.clone(base), {
      fontSize: '10px',
      left: '10px',
      right: '40px',
      bottom: '10px'
    }))

    css(year, _.extend(_.clone(base), {
      position: 'absolute',
      fontSize: '14px',
      left: '120px',
      right: '10px',
      bottom: '10px'
    }))

  }

  self.update = function (value) {
    Object.assign(this, value)

    var pmcid = _.find(self.document.identifier, { type: 'pmcid' }).id
    this.pmcid = `PMC${pmcid}`

    title.innerHTML = value.document.title
    author.innerHTML = self.etalia(value.document.author)
    year.innerHTML = value.document.year

    self.loadFile()
  }

  self.stringForAuthor = function(a) {
    return `${a.given_names} ${a.surname}`
  }

  self.etalia = function (authors) {
    var authorStrs = authors.map(self.stringForAuthor)
    if (authors.length > 3) {
      return self.stringForAuthor(authors[0]) + ' et al.'
    } else {
      return authorStrs.join(', ')
    }
  }

  self.truncate = function (str, limit) {
    var  bits = str.split('')
    if (bits.length > limit) {
      for (var i = bits.length - 1; i > -1; --i) {
        if (i > limit) {
          bits.length = i
        }
        else if (' ' === bits[i]) {
          bits.length = i
          break
        }
      }
      bits.push('...')
    }
    return bits.join('')
  };

  self.downloadFailed = function (err) {
    css(box, {
      borderBottom: 'solid 7px rgb(202,77,107)'
    })
  }

  self.downloaded = function (file) {
    self.file = file.path
    css(box, {
      borderBottom: 'solid 7px rgb(202, 172, 77)'
    })
  }

  self.loadFile = function () {
    var self = this
    var filepath = this.filepath()
    fs.stat(filepath, function(err, stat) {
      if (err == null) {
        // file exists - show lens viewer button
        self.downloaded({ path: filepath })
        console.log('paper should be located at', filepath)
      } else if(err.code == 'ENOENT') {
        // file doesn't exist - do nothing
      } else {
        console.log('Error looking for file: ', filepath, err);
      }
    });
  }

  self.filepath = function() {
    var dir = opts.fulltextSource.dir
    var pmcid = self.pmcid
    var filepath = path.join(opts.datadir, dir, pmcid, 'fulltext.xml')
    return filepath
  }

  self.url = function() {
    var port = opts.contentServer.port
    var dir = opts.fulltextSource.dir
    var pmcid = self.pmcid
    var url = `http://localhost:${port}/${dir}/${pmcid}/fulltext.xml`
    console.log('paper should be served at', url)
    return url
  }

  self.layout()

  box.onclick  = function () {
    self.emit('click')
  }

  box.addEventListener("mouseenter", function(event) {
    if (self.file && contentServer.port) css(overlay, { display: 'flex' })
  })

  box.addEventListener("mouseleave", function(event) {
    css(overlay, { display: 'none' })
  })

  lens.onclick = function () {
    self.emit('lens-click')
    lensReader = reader(self, self.opts)
    lensReader.show()
    // TODO: destroy on close
  }
}

module.exports = Paper

{'fraction_non_alphanumeric': 0.1586473228264273, 'fraction_numerical': 0.020457154785512993, 'mean_word_length': 2.566058801637514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2190219', 'n_tokens_mistral': 3371, 'n_tokens_neox': 3175, 'n_words': 728}