<commit_before># encoding: UTF-8

# $HeadURL$
# $Id$
#
# Copyright (c) 2009-2014 by Public Library of Science, a non-profit corporation
# http://www.plos.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'cgi'
require 'addressable/uri'
require "builder"

class Article < ActiveRecord::Base
  strip_attributes

  # include HTTP request helpers
  include Networkable

  # include helper module for DOI resolution
  include Resolvable

  has_many :retrieval_statuses, :dependent => :destroy
  has_many :sources, :through => :retrieval_statuses
  has_many :alerts
  has_many :api_responses

  validates :uid, :title, :year, :presence => true
  validates :doi, :uniqueness => true , :format => { :with => DOI_FORMAT }, :allow_nil => true
  validates :year, :numericality => { :only_integer => true }, :inclusion => { :in => 1650..(Time.zone.now.year), :message => "should be between 1650 and #{Time.zone.now.year}" }
  validate :validate_published_on

  before_validation :sanitize_title
  after_create :create_retrievals

  scope :query, lambda { |query|
    if self.has_many?
      where("doi like ?", "#{query}%")
    else
      where("doi like ? OR title like ?", "%#{query}%", "%#{query}%")
    end
  }

  scope :last_x_days, lambda { |duration| where(published_on: (Date.today - duration.days)..Date.today) }
  scope :is_cited, lambda { includes(:retrieval_statuses).where("retrieval_statuses.event_count > ?", 0) }

  # simplify admin dashboard when we have more than 150,000 articles
  def self.has_many?
    Article.count > 150000<commit_msg>ALM-213 added signposts scope<commit_after># encoding: UTF-8

# $HeadURL$
# $Id$
#
# Copyright (c) 2009-2014 by Public Library of Science, a non-profit corporation
# http://www.plos.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'cgi'
require 'addressable/uri'
require "builder"

class Article < ActiveRecord::Base
  strip_attributes

  # include HTTP request helpers
  include Networkable

  # include helper module for DOI resolution
  include Resolvable

  has_many :retrieval_statuses, :dependent => :destroy
  has_many :sources, :through => :retrieval_statuses
  has_many :alerts
  has_many :api_responses

  validates :uid, :title, :year, :presence => true
  validates :doi, :uniqueness => true , :format => { :with => DOI_FORMAT }, :allow_nil => true
  validates :year, :numericality => { :only_integer => true }, :inclusion => { :in => 1650..(Time.zone.now.year), :message => "should be between 1650 and #{Time.zone.now.year}" }
  validate :validate_published_on

  before_validation :sanitize_title
  after_create :create_retrievals

  scope :query, lambda { |query|
    if self.has_many?
      where("doi like ?", "#{query}%")
    else
      where("doi like ? OR title like ?", "%#{query}%", "%#{query}%")
    end
  }

  scope :last_x_days, lambda { |duration| where(published_on: (Date.today - duration.days)..Date.today) }
  scope :is_cited, lambda { includes(:retrieval_statuses).where("retrieval_statuses.event_count > ?", 0) }
  scope :signposts, joins(:sources).pluck_all(:name, :event_count)

  # simplify admin dashboard when we have more than 150,000 articles
  def self.has_many?
    Article.count > 150000
{'fraction_non_alphanumeric': 0.11585220500595947, 'fraction_numerical': 0.01692491060786651, 'mean_word_length': 4.324873096446701, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '880061', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1264, 'n_words': 428}