<commit_before>const { URL } = require('url');
const StringQuery = require('./string');

/**
 * A class respresenting an query that resolves to a link.
 */
class LinkQuery extends StringQuery {
  /**
   * Constructs a LinkQuery given a document path to the link
   * and an object of additional configuration options.
   * 
   * @param  {string}  path    The path to the link in a document.
   * @param  {object}             options An object of additional configuration options.
   */
  constructor(path, base, options={}) {
    options.base = base;
    super(path, options);
  }

  /**
   * Finds the link in the document.
   * 
   * @param  {Document} document  The document to find the link in.
   * @return {*} The link found in the document.
   */
  find(document) {
    return document.link(this.options.path);
  }

  /**
   * Given the query's retrieved value, this method creates a url object
   * from the retrieved link and a fallback base uri. It returns this
   * url coerced to a string.
   * 
   * @param  {*}        string    The link retrieved from the document.
   * @param  {Document} document  The document the link was retrieved from.
   * @return {string} The resulting, uri coerced to a string.
   */
  build(string, document) {
    return (new URL(string, this.options.base)).toString();
  }
}

module.exports = LinkQuery;<commit_msg>changed link query to use legacy url API<commit_after>const url = require('url');
const StringQuery = require('./string');

/**
 * A class respresenting an query that resolves to a link.
 */
class LinkQuery extends StringQuery {
  /**
   * Constructs a LinkQuery given a document path to the link
   * and an object of additional configuration options.
   * 
   * @param  {string}  path    The path to the link in a document.
   * @param  {object}             options An object of additional configuration options.
   */
  constructor(path, base, options={}) {
    options.base = base;
    super(path, options);
  }

  /**
   * Finds the link in the document.
   * 
   * @param  {Document} document  The document to find the link in.
   * @return {*} The link found in the document.
   */
  find(document) {
    return document.link(this.options.path);
  }

  /**
   * Given the query's retrieved value, this method creates a url object
   * from the retrieved link and a fallback base uri. It returns this
   * url coerced to a string.
   * 
   * @param  {*}        string    The link retrieved from the document.
   * @param  {Document} document  The document the link was retrieved from.
   * @return {string} The resulting, uri coerced to a string.
   */
  build(string, document) {
    return url.resolve(this.options.base || '', string);
  }
}

module.exports = LinkQuery;
{'fraction_non_alphanumeric': 0.1023391812865497, 'fraction_numerical': 0.0, 'mean_word_length': 2.8066759388038944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7505843', 'n_tokens_mistral': 795, 'n_tokens_neox': 773, 'n_words': 311}