<commit_before>class Entity < ActiveRecord::Base

# add custom pagination
extend SRNSW::Pages

  def date_range
    date_string self.Start_date_qualifier, self.Start_date, self.End_date_qualifier, self.End_date
  end
  
  # used in eac-cpf views
  def date_start
    parse_date(self.Start_date_qualifier, self.Start_date)
  end
  
  def date_end
    parse_date(self.End_date_qualifier, self.End_date)
  end
  
  def date_string start_qual, start_date, end_qual=nil, end_date=nil
    date_string = String.new
    start_date = parse_date(start_qual, start_date)
    if end_date
      end_date = parse_date(end_qual, end_date)
    end
    
    if start_date
      date_string += start_date
      if end_date
        date_string += " to "
        date_string += end_date
      else
        date_string += " +"
      end
    elsif end_date
      date_string += "- "
      date_string += end_date
    else
      date_string += "unknown"
    end
  end

  def parse_date qualifier, date
    if date
      if (qualifier.nil? or qualifier.strip.empty?)
        day_month_year(date)
      elsif qualifier == "year only" 
        date.year.to_s
      else
       string = ["?", "circa", "c", "c."].index(qualifier) ? "c. " : qualifier + " "
       string += day_month_year(date)
      end
    else
      nil
    end
  end
  
  def day_month_year date
    date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s
  end

  def self.simple_location location
   #for some weird text which has no dot at the end of sentence.
   location = location.sub(" however", ". however")
   #we do expect to have at least one dot to match the end of a sentence
   #but some of the data doesn't contain it
   location = location.concat(".")
   regexp = /^.*?[A-Z].*?([A-Z].*?)\./
   match = regexp.match(location)
   if match
  	  match = match[1]
  	else
  	  location
  	end
  end 
  
  def comments
	@comments = Comment.where(:entitytype => self.class.name).and(:entityid => self.id).order_by([:created_at, :asc])	
  end
  
  def tags
	@tags = Tag.where(:entitytype => self.class.name).and(:entityid => self.id).order_by([:created_at, :asc])
  end
  
  def dbg
   "#{self.class.name}-#{self.id}"
  end
end
<commit_msg>Added a default location name to a record which has no location defined<commit_after>class Entity < ActiveRecord::Base

# add custom pagination
extend SRNSW::Pages

  def date_range
    date_string self.Start_date_qualifier, self.Start_date, self.End_date_qualifier, self.End_date
  end
  
  # used in eac-cpf views
  def date_start
    parse_date(self.Start_date_qualifier, self.Start_date)
  end
  
  def date_end
    parse_date(self.End_date_qualifier, self.End_date)
  end
  
  def date_string start_qual, start_date, end_qual=nil, end_date=nil
    date_string = String.new
    start_date = parse_date(start_qual, start_date)
    if end_date
      end_date = parse_date(end_qual, end_date)
    end
    
    if start_date
      date_string += start_date
      if end_date
        date_string += " to "
        date_string += end_date
      else
        date_string += " +"
      end
    elsif end_date
      date_string += "- "
      date_string += end_date
    else
      date_string += "unknown"
    end
  end

  def parse_date qualifier, date
    if date
      if (qualifier.nil? or qualifier.strip.empty?)
        day_month_year(date)
      elsif qualifier == "year only" 
        date.year.to_s
      else
       string = ["?", "circa", "c", "c."].index(qualifier) ? "c. " : qualifier + " "
       string += day_month_year(date)
      end
    else
      nil
    end
  end
  
  def day_month_year date
    date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s
  end

  def self.simple_location location
   #for some weird text which has no dot at the end of sentence.
   location = location.sub(" however", ". however")
   #some records has no location defined
   location = location | "No location"
   #we do expect to have at least one dot to match the end of a sentence
   #but some of the data doesn't contain it
   location = location.concat(".")
   regexp = /^.*?[A-Z].*?([A-Z].*?)\./
   match = regexp.match(location)
   match ? match[1] : location
  end 
  
  def comments
	@comments = Comment.where(:entitytype => self.class.name).and(:entityid => self.id).order_by([:created_at, :asc])	
  end
  
  def tags
	@tags = Tag.where(:entitytype => self.class.name).and(:entityid => self.id).order_by([:created_at, :asc])
  end
  
  def dbg
   "#{self.class.name}-#{self.id}"
  end
end

{'fraction_non_alphanumeric': 0.10745233968804159, 'fraction_numerical': 0.0004332755632582322, 'mean_word_length': 2.4506726457399104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3668213', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1555, 'n_words': 390}