<commit_before>import NSIdentity from "./NSIdentity";
import IdResolver from "./IdResolver";
import Namespace from "./Namespace";
import {Name, Nullable, Undef} from "./Types";

type Dict<V> = { [key: string]: V };

export default class NSDictionary<V> {

  private _fqnObjectMap: Dict<V> = {};
  private _idResolver: IdResolver = new IdResolver();

  public set(key: NSIdentity, value: V): void {
    this._fqnObjectMap[key.fqn] = value;
    this._idResolver.add(key);
  }

  public delete(key: NSIdentity): boolean {
    if (this._fqnObjectMap[key.fqn] !== void 0) {
      delete this._fqnObjectMap[key.fqn];
      this._idResolver.remove(key);
      return true;
    }
    return false;
  }

  public get(name: Name): V;
  public get(element: Element): V;
  public get(attribute: Attr): V;
  public get(arg1: string | Element | NSIdentity | Attr): Nullable<V> {
    if (!arg1) {
      throw new Error("NSDictionary.get() can not recieve args null or undefined.");
    }
    if (typeof arg1 === "string") {
      const name = arg1.split(".");
      const res = this._idResolver.get(Namespace.defineByArray(name));
      // const namedMap = this._nameObjectMap[arg1];
      if (res.length === 0) {
        return null; // not exist.
      }
      if (res.length === 1) {
        return this._fqnObjectMap[res[0]];
      } else {
        throw new Error(`Specified tag name ${arg1} is ambiguous to identify.`);
      }

    } else {
      if (arg1 instanceof NSIdentity) {
        return this._fqnObjectMap[arg1.fqn];
      } else {
        if (arg1.namespaceURI) {<commit_msg>fix: bug on goml parsing for node<commit_after>import NSIdentity from "./NSIdentity";
import IdResolver from "./IdResolver";
import Namespace from "./Namespace";
import Ensure from "./Ensure";
import {Name, Nullable, Undef} from "./Types";

type Dict<V> = { [key: string]: V };

export default class NSDictionary<V> {

  private _fqnObjectMap: Dict<V> = {};
  private _idResolver: IdResolver = new IdResolver();

  public set(key: NSIdentity, value: V): void {
    this._fqnObjectMap[key.fqn] = value;
    this._idResolver.add(key);
  }

  public delete(key: NSIdentity): boolean {
    if (this._fqnObjectMap[key.fqn] !== void 0) {
      delete this._fqnObjectMap[key.fqn];
      this._idResolver.remove(key);
      return true;
    }
    return false;
  }

  public get(name: Name): V;
  public get(element: Element): V;
  public get(attribute: Attr): V;
  public get(arg1: string | Element | NSIdentity | Attr): Nullable<V> {
    if (!arg1) {
      throw new Error("NSDictionary.get() can not recieve args null or undefined.");
    }
    if (typeof arg1 === "string") {
      const fqn = Ensure.tobeFQN(arg1);
      if (fqn) {
        return this._fqnObjectMap[fqn];
      }
      const name = arg1.split(".");
      const res = this._idResolver.get(Namespace.defineByArray(name));
      // const namedMap = this._nameObjectMap[arg1];
      if (res.length === 0) {
        return null; // not exist.
      }
      if (res.length === 1) {
        return this._fqnObjectMap[res[0]];
      } else {
        throw new Error(`Specified tag name ${arg1} is ambiguous to identify.`);
      }

    } else {
      if (arg1 instanceof NSIdentity) {
        return this._fqnObjectMap[arg1.fqn];
      } else {
        if (arg1.namespaceURI) {
{'fraction_non_alphanumeric': 0.14108761329305136, 'fraction_numerical': 0.008157099697885197, 'mean_word_length': 2.872514619883041, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5685850', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1067, 'n_words': 289}