<commit_before>(function() {
  "use strict"

  function splitComponents(path) {
    return path
      .replace(/^\//, "")
      .replace(/\/$/, "")
      .split("/")
  }

  class PathPattern {
    constructor(path) {
      this.path = path
      this.components = splitComponents(path)
    }

    // returns captured strings array(or empty array) if matched or returns null
    match(path) {
      const capture = {}
      const target = splitComponents(path).reverse()
      for (const c of this.components) {
        const t = target.pop()
        if (c == "*") {
          continue
        } else if (c.startsWith(":")) {
          capture[c.substr(1)] = t
        } else if (c != t) {
          return null
        }
      }
      return capture
    }
  }

  function callMatched(listeners, type, path, value) {
    let res = undefined
    listeners
      .filter(l => l.type == "*" || l.type == type)
      .forEach(l => {
        const match = l.pattern.match(path)
        if (match) {
          res = l.callback({
            type: type,
            path: path,
            value: value,
            params: match
          })
        }
      })
    return res
  }

  class Observer {
    constructor() {
      this.listeners = []
    }

    on(type, pattern, callback) {
      this.listeners.push({
        type: type,
        pattern: new PathPattern(pattern),
        callback: callback
      })
    }

    off(type, pattern, callback) {
      this.listeners = this.listeners.filter(o => 
        o.type == type &&
        o.pattern == pattern &&
        o.callback == callback
      )
    }

    trigger(type, path, value) {
      callMatched(this.listeners, type, path, value)
    }
  }

  class Shinjuku {
    constructor() {
      this.resources = []
      this.upObserver = new Observer
      this.downObserver = new Observer
      this.on = this.onDown
    }

    resource(pattern, callback) {
      this.resources.push({
        pattern: new PathPattern(pattern),
        callback: callback
      })
    }

    get(path) {
      for (const r of this.resources) {
        const match = r.pattern.match(path)
        if (match) {
         return r.callback.apply(null, match)
        }
      }
    }

    onUp(type, pattern, callback) {
      this.upObserver.on(type, pattern, callback)
    }

    offUp(type, pattern, callback) {
      this.upObserver.off(type, pattern, callback)
    }

    up(type, path, value) {<commit_msg>use Observer to implement get-resource<commit_after>(function() {
  "use strict"

  function splitComponents(path) {
    return path
      .replace(/^\//, "")
      .replace(/\/$/, "")
      .split("/")
  }

  class PathPattern {
    constructor(path) {
      this.path = path
      this.components = splitComponents(path)
    }

    // returns captured strings array(or empty array) if matched or returns null
    match(path) {
      const capture = {}
      const target = splitComponents(path).reverse()
      for (const c of this.components) {
        const t = target.pop()
        if (c == "*") {
          continue
        } else if (c.startsWith(":")) {
          capture[c.substr(1)] = t
        } else if (c != t) {
          return null
        }
      }
      return capture
    }
  }

  function callMatched(listeners, type, path, value) {
    let res = undefined
    listeners
      .filter(l => l.type == "*" || l.type == type)
      .forEach(l => {
        const match = l.pattern.match(path)
        if (match) {
          res = l.callback({
            type: type,
            path: path,
            value: value,
            params: match
          })
        }
      })
    return res
  }

  class Observer {
    constructor() {
      this.listeners = []
    }

    on(type, pattern, callback) {
      this.listeners.push({
        type: type,
        pattern: new PathPattern(pattern),
        callback: callback
      })
    }

    off(type, pattern, callback) {
      this.listeners = this.listeners.filter(o => 
        o.type == type &&
        o.pattern == pattern &&
        o.callback == callback
      )
    }

    trigger(type, path, value) {
      return callMatched(this.listeners, type, path, value)
    }
  }

  class Shinjuku {
    constructor() {
      this.resources = []
      this.upObserver = new Observer
      this.downObserver = new Observer
      this.resourceObserver = new Observer
      this.on = this.onDown
    }

    resource(pattern, callback) {
      this.resourceObserver.on("res", pattern, callback)
    }

    get(path) {
      return this.resourceObserver.trigger("res", path)
    }

    onUp(type, pattern, callback) {
      this.upObserver.on(type, pattern, callback)
    }

    offUp(type, pattern, callback) {
      this.upObserver.off(type, pattern, callback)
    }

    up(type, path, value) {
{'fraction_non_alphanumeric': 0.12875, 'fraction_numerical': 0.0004166666666666667, 'mean_word_length': 1.7864190365641324, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, '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': '6044214', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1416, 'n_words': 337}