<commit_before>/**
 * Appends the objects necessary for a new class to extend a base class.
 */
Function.prototype.extends = function(base){
  if(base.constructor == Function){
    // normal inheritance
    this.prototype = Object.create(base.prototype);
    this.prototype.constructor = this;
    this.prototype.base = base.prototype;
  }
  else {
    // virtual inheritance
    this.prototype = Object.create(base.prototype);
    this.prototype.constructor = this;
    this.prototype.base = base;
  }
  return this;
}

var svg = {
  ns: "http://www.w3.org/2000/svg",
}

/*******************************************************************************
 * A node is the root base class for all classes in the svg namespace. It
 * provides methods for working with attributes and children.
 */
svg.node = function(){
  this.root = null;
  this.element = null;
}

/**
 * This function sets the value of an attribute on an element.
 *
 * @param key   - the name of the attribute
 * @param value - the value the attribute should be set to
 *
 * @return a reference to this object
 */
svg.node.prototype.attr = function(key, value){
  this.element.setAttributeNS(null, key, value);
  return this;
}

/**
 * This function sets the values of one or more attributes on an element.
 *
 * @param attrs - an object literal containg the attributes to modify
 *
 * @return a reference to this object
 */
svg.node.prototype.attrs = function(attrs){
  for(var key in attrs){
    this.element.setAttributeNS(null, key, attrs[key]);
  }
  return this;
}

/**
 * Returns the value of the specified attribute.
 *
 * @param key - the name of the attribute to return.
 *
 * @return the value of the attribute
 */
svg.node.prototype.get = function(key){
  return this.element.getAttributeNS(null, key);
}

/**
 * Adds an SVG as a child of this element.
 *
 * @param child - the element to add.
 *
 * @return a reference to this object
 */
svg.node.prototype.add = function(child){
  this.element.appendChild(child.element);
  return this;
}

/**
 * Returns a list of the children contained in this SVG element.
 *
 * @return a NodeList of children.
 */
svg.node.prototype.children = function(){
  return this.element.childNodes;
}

/*******************************************************************************
 * The definition class represents a <defs> element in the SVG.
 *
 * If the provided <svg> element does not contain any <defs> elements, a new one
 * is created. Otherwise, the first <defs> element is associated with this
 * object.
 *
 * @param root - an <svg> element.
 */
svg.definition = function(root){
  this.root = root;

  var defs = root.element.getElementsByTagName("defs");
  if(defs.length > 0){
    this.element = defs[0];
  } else {
    this.element = document.createElementNS(svg.ns, "defs");
    this.root.element.appendChild(this.element);
  }
}

svg.definition.extends(svg.node);

/**
 * Returns a new instance of the definition.
 *
 * @param x - the x attribute of the new element.
 * @param y - the y attribute of the new element.
 *<commit_msg>svg: fixed definition constructor<commit_after>/**
 * Appends the objects necessary for a new class to extend a base class.
 */
Function.prototype.extends = function(base){
  if(base.constructor == Function){
    // normal inheritance
    this.prototype = Object.create(base.prototype);
    this.prototype.constructor = this;
    this.prototype.base = base.prototype;
  }
  else {
    // virtual inheritance
    this.prototype = Object.create(base.prototype);
    this.prototype.constructor = this;
    this.prototype.base = base;
  }
  return this;
}

var svg = {
  ns: "http://www.w3.org/2000/svg",
}

/*******************************************************************************
 * A node is the root base class for all classes in the svg namespace. It
 * provides methods for working with attributes and children.
 */
svg.node = function(){
  this.root = null;
  this.element = null;
}

/**
 * This function sets the value of an attribute on an element.
 *
 * @param key   - the name of the attribute
 * @param value - the value the attribute should be set to
 *
 * @return a reference to this object
 */
svg.node.prototype.attr = function(key, value){
  this.element.setAttributeNS(null, key, value);
  return this;
}

/**
 * This function sets the values of one or more attributes on an element.
 *
 * @param attrs - an object literal containg the attributes to modify
 *
 * @return a reference to this object
 */
svg.node.prototype.attrs = function(attrs){
  for(var key in attrs){
    this.element.setAttributeNS(null, key, attrs[key]);
  }
  return this;
}

/**
 * Returns the value of the specified attribute.
 *
 * @param key - the name of the attribute to return.
 *
 * @return the value of the attribute
 */
svg.node.prototype.get = function(key){
  return this.element.getAttributeNS(null, key);
}

/**
 * Adds an SVG as a child of this element.
 *
 * @param child - the element to add.
 *
 * @return a reference to this object
 */
svg.node.prototype.add = function(child){
  this.element.appendChild(child.element);
  return this;
}

/**
 * Returns a list of the children contained in this SVG element.
 *
 * @return a NodeList of children.
 */
svg.node.prototype.children = function(){
  return this.element.childNodes;
}

/*******************************************************************************
 * The definition class represents a <defs> element in the SVG.
 *
 * If the provided <svg> element does not contain any <defs> elements, a new one
 * is created. Otherwise, the first <defs> element is associated with this
 * object.
 *
 * @param root - an <svg> element.
 */
svg.definition = function(root){
  svg.node.call(this);

  this.root = root;

  var defs = root.element.getElementsByTagName("defs");
  if(defs.length > 0){
    this.element = defs[0];
  } else {
    this.element = document.createElementNS(svg.ns, "defs");
    this.root.element.appendChild(this.element);
  }
}

svg.definition.extends(svg.node);

/**
 * Returns a new instance of the definition.
 *
 * @param x - the x attribute of the new element.
 * @param y - the y attribute of the new element.
 *
{'fraction_non_alphanumeric': 0.16336472880805455, 'fraction_numerical': 0.0022734654108476776, 'mean_word_length': 3.4956204379562044, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '701062', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1774, 'n_words': 620}