text: 
  
  <!DOCTYPE html>
  <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>claf.config.namespace &mdash; CLaF 0.2.0 documentation</title>
    
  
    
    
      <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
    
    
    
  
    
    <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
    
      
        <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
          <script type="text/javascript" src="../../../_static/jquery.js"></script>
          <script type="text/javascript" src="../../../_static/underscore.js"></script>
          <script type="text/javascript" src="../../../_static/doctools.js"></script>
          <script type="text/javascript" src="../../../_static/language_data.js"></script>
      
      <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  
      
  
    
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/theme_overrides.css" type="text/css" />
      <link rel="index" title="Index" href="../../../genindex.html" />
      <link rel="search" title="Search" href="../../../search.html" /> 
  </head>
  
  <body class="wy-body-for-nav">
  
     
    <div class="wy-grid-for-nav">
  
      
      <nav data-toggle="wy-nav-shift" class="wy-nav-side">
        <div class="wy-side-scroll">
          <div class="wy-side-nav-search">
            
  
            
              <a href="../../../index.html">
            
  
            
              
              <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
            
            </a>
  
            
              
              
                <div class="version">
                  0.2.0
                </div>
              
            
  
            
  <div role="search">
    <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
  </div>
  
            
          </div>
  
          <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
            
              
              
                
              
              
                <p class="caption"><span class="caption-text">Contents</span></p>
  <ul>
  <li class="toctree-l1"><a class="reference internal" href="../../../contents/dataset_and_model.html">Dataset and Model</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../contents/pretrained_vector.html">Pretrained Vector</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../contents/tokens.html">Tokens</a></li>
  </ul>
  <p class="caption"><span class="caption-text">Package Reference</span></p>
  <ul>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.config.html">config</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.data.html">data</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.learn.html">learn</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.metric.html">metric</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.model.html">model</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.modules.html">modules</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../claf.tokens.html">tokens</a></li>
  </ul>
  <p class="caption"><span class="caption-text">Reports</span></p>
  <ul>
  <li class="toctree-l1"><a class="reference internal" href="../../../reports/glue.html">GLUE</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../reports/historyqa.html">HistoryQA</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../reports/korquad.html">KorQuAD</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../reports/squad.html">SQuAD</a></li>
  <li class="toctree-l1"><a class="reference internal" href="../../../reports/wikisql.html">WikiSQL</a></li>
  </ul>
  <p class="caption"><span class="caption-text">Summary</span></p>
  <ul>
  <li class="toctree-l1"><a class="reference internal" href="../../../summary/reading_comprehension.html">Reading Comprehension</a></li>
  </ul>
  <p class="caption"><span class="caption-text">Appendix</span></p>
  <ul>
  <li class="toctree-l1"><a class="reference internal" href="../../../references.html">References</a></li>
  </ul>
  
              
            
          </div>
        </div>
      </nav>
  
      <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  
        
        <nav class="wy-nav-top" aria-label="top navigation">
          
            <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
            <a href="../../../index.html">CLaF</a>
          
        </nav>
  
  
        <div class="wy-nav-content">
          
          <div class="rst-content">
          
            
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  <div role="navigation" aria-label="breadcrumbs navigation">
  
    <ul class="wy-breadcrumbs">
      
        <li><a href="../../../index.html">Docs</a> &raquo;</li>
          
            <li><a href="../../index.html">Module code</a> &raquo;</li>
          
        <li>claf.config.namespace</li>
      
      
        <li class="wy-breadcrumbs-aside">
          
        </li>
      
    </ul>
  
    
    <hr/>
  </div>
            <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
             <div itemprop="articleBody">
              
    <h1>Source code for claf.config.namespace</h1><div class="highlight"><pre>
  <span></span>
  <span class="kn">import</span> <span class="nn">argparse</span>
  
  
  <div class="viewcode-block" id="NestedNamespace"><a class="viewcode-back" href="../../../claf.config.html#claf.config.namespace.NestedNamespace">[docs]</a><span class="k">class</span> <span class="nc">NestedNamespace</span><span class="p">(</span><span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">):</span>
      <span class="sd">&quot;&quot;&quot;</span>
  <span class="sd">    Nested Namespace</span>
  <span class="sd">    (Simple class used by default by parse_args() to create</span>
  <span class="sd">     an object holding attributes and return it.)</span>
  <span class="sd">    &quot;&quot;&quot;</span>
  
      <span class="k">def</span> <span class="nf">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
          <span class="k">if</span> <span class="s2">&quot;.&quot;</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
              <span class="n">group</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
              <span class="n">namespace</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">NestedNamespace</span><span class="p">())</span>
              <span class="nb">setattr</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
              <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">group</span><span class="p">]</span> <span class="o">=</span> <span class="n">namespace</span>
          <span class="k">else</span><span class="p">:</span>
              <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
  
  <div class="viewcode-block" id="NestedNamespace.delete_unselected"><a class="viewcode-back" href="../../../claf.config.html#claf.config.namespace.NestedNamespace.delete_unselected">[docs]</a>    <span class="k">def</span> <span class="nf">delete_unselected</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">namespace</span><span class="p">,</span> <span class="n">excepts</span><span class="o">=</span><span class="p">[]):</span>
          <span class="n">delete_keys</span> <span class="o">=</span> <span class="p">[]</span>
          <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">namespace</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
              <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">excepts</span><span class="p">:</span>
                  <span class="n">delete_keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
  
          <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">delete_keys</span><span class="p">:</span>
              <span class="nb">delattr</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span></div>
  
  <div class="viewcode-block" id="NestedNamespace.overwrite"><a class="viewcode-back" href="../../../claf.config.html#claf.config.namespace.NestedNamespace.overwrite">[docs]</a>    <span class="k">def</span> <span class="nf">overwrite</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
          <span class="k">def</span> <span class="nf">_overwrite</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
              <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                  <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">==</span> <span class="nb">dict</span><span class="p">:</span>
                      <span class="n">nested_namespace</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
                      <span class="k">if</span> <span class="n">nested_namespace</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                          <span class="n">nested_namespace</span> <span class="o">=</span> <span class="n">NestedNamespace</span><span class="p">()</span>
                          <span class="n">nested_namespace</span><span class="o">.</span><span class="n">load_from_json</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
  
                          <span class="nb">setattr</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">nested_namespace</span><span class="p">)</span>
                      <span class="k">else</span><span class="p">:</span>
                          <span class="n">_overwrite</span><span class="p">(</span><span class="n">nested_namespace</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
                  <span class="k">else</span><span class="p">:</span>
                      <span class="nb">setattr</span><span class="p">(</span><span class="n">namespace</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
              <span class="k">return</span> <span class="n">namespace</span>
  
          <span class="k">return</span> <span class="n">_overwrite</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">)</span></div>
  
  <div class="viewcode-block" id="NestedNamespace.load_from_json"><a class="viewcode-back" href="../../../claf.config.html#claf.config.namespace.NestedNamespace.load_from_json">[docs]</a>    <span class="k">def</span> <span class="nf">load_from_json</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dict_data</span><span class="p">):</span>
  
          <span class="n">name_value_pairs</span> <span class="o">=</span> <span class="p">[]</span>
  
          <span class="k">def</span> <span class="nf">make_key_value_pairs</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
              <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                  <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">==</span> <span class="nb">dict</span><span class="p">:</span>
                      <span class="n">next_prefix</span> <span class="o">=</span> <span class="n">k</span>
                      <span class="k">if</span> <span class="n">prefix</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                          <span class="n">next_prefix</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{prefix}</span><span class="s2">.</span><span class="si">{k}</span><span class="s2">&quot;</span>
                      <span class="n">make_key_value_pairs</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="n">next_prefix</span><span class="p">)</span>
                  <span class="k">else</span><span class="p">:</span>
                      <span class="n">key_with_prefix</span> <span class="o">=</span> <span class="n">k</span>
                      <span class="k">if</span> <span class="n">prefix</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                          <span class="n">key_with_prefix</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{prefix}</span><span class="s2">.</span><span class="si">{k}</span><span class="s2">&quot;</span>
                      <span class="n">name_value_pairs</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">key_with_prefix</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
  
          <span class="n">make_key_value_pairs</span><span class="p">(</span><span class="n">dict_data</span><span class="p">)</span>
          <span class="k">for</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="ow">in</span> <span class="n">name_value_pairs</span><span class="p">:</span>
              <span class="bp">self</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div></div>
  </pre></div>
  
             </div>
             
            </div>
            <footer>
    
  
    <hr/>
  
    <div role="contentinfo">
      <p>
          &copy; Copyright 2019, Dongjun Lee
  
      </p>
    </div>
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 
  
  </footer>
  
          </div>
        </div>
  
      </section>
  
    </div>
    
  
  
    <script type="text/javascript">
        jQuery(function () {
            SphinxRtdTheme.Navigation.enable(true);
        });
    </script>
  
    
    
      
     
  
  </body>
  </html>