text:
package com.esri.gpt.server.assertion.index;
import com.esri.gpt.framework.context.ConfigurationException;
import com.esri.gpt.framework.util.Val;
import com.esri.gpt.server.assertion.components.AsnContext;

/**
 * Represents a configuration reference to a Lucene based assertion index.
 */
public class AsnIndexReference {

  /** instance variables ====================================================== */
  private boolean enabled = true;
  private String  indexAdapterClass;
  private String  indexLocation;
  private String  name;
  private boolean useNativeFSLockFactory = true;
  private int     writeLockTimeout = 0;

  /** constructors ============================================================ */

  /** Default constructor. */
  public AsnIndexReference() {}

  /**
   * Construct by duplicating an existing object.
   * @param objectToDuplicate the object to duplicate
   */
  public AsnIndexReference(AsnIndexReference objectToDuplicate) {
    if (objectToDuplicate != null) {
      this.setEnabled(objectToDuplicate.getEnabled());
      this.setIndexAdatperClass(objectToDuplicate.getIndexAdapterClass());
      this.setIndexLocation(objectToDuplicate.getIndexLocation());
      this.setName(objectToDuplicate.getName());
      this.setUseNativeFSLockFactory(objectToDuplicate.getUseNativeFSLockFactory());
      this.setWriteLockTimeout(objectToDuplicate.getWriteLockTimeout());
    }
  }

  /** properties ============================================================== */

  /**
   * Gets the status indicating whether or not the index is enabled.
   * @return true if enabled
   */
  public boolean getEnabled() {
    return this.enabled;
  }
  /**
   * Sets the status indicating whether or not the index is enabled.
   * @param enabled true if enabled
   */
  public void setEnabled(boolean enabled) {
    this.enabled = enabled;
  }

  /**
   * Gets the fully qualified class name of the index adapter.
   *
(must extend AsnIndexAdapter)
   * @return the index adapter class
   */
  public String getIndexAdapterClass() {
    return this.indexAdapterClass;
  }
  /**
   * Sets the fully qualified class name of the index adapter.
   *
(must extend AsnIndexAdapter)
   * @param indexAdapterClass the index adapter class
   */
  public void setIndexAdatperClass(String indexAdapterClass) {
    this.indexAdapterClass = indexAdapterClass;
  }

  /**
   * Gets the location of the index folder (system path).
   * @return the location
   */
  public String getIndexLocation() {
    return this.indexLocation;
  }
  /**
   * Sets the location of the index folder (system path).
   * @param location the location
   */
  public void setIndexLocation(String location) {
    this.indexLocation = location;
  }
  /**
   * Sets the location of the index folder (system path).
   * @param rootIndexRef the index reference associated with the assertion root
   * @param name the index folder name
   * @param location the location
   */
  public void setIndexLocation(AsnIndexReference rootIndexRef, String name, String location) {
    location = Val.chkStr(location);
    this.setName(name);
    if (location.length() > 0) {
      this.setIndexLocation(location);
    } else {
      this.setIndexLocation(rootIndexRef.getIndexLocation()+"/"+name);
    }
  }

  /**
   * Gets the name associated with the index.
   * @return the name
   */
  public String getName() {
    return this.name;
  }
  /**
   * Sets the name associated with the index.
   * @param name the name
   */
  public void setName(String name) {
    this.name = name;
  }

  /**
   * Gets the flag indicating if a NativeFSLockFactory should be used.
   * @return true if a NativeFSLockFactory should be used, otherwise use a SimpleFSLockFactory
   */
  public boolean getUseNativeFSLockFactory() {
    return this.useNativeFSLockFactory;
  }
  /**
   * Sets the flag indicating if a NativeFSLockFactory should be used.
   * @param useNative true if a NativeFSLockFactory should be used, otherwise use a SimpleFSLockFactory
   */
  public void setUseNativeFSLockFactory(boolean useNative) {
    this.useNativeFSLockFactory = useNative;
  }

  /**
   * Gets the write lock timeout in milli-seconds.
   * @return the write lock timeout
   */
  public int getWriteLockTimeout() {
    return this.writeLockTimeout;
  }
  /**
   * Sets the write lock timeout in milli-seconds.
   *
If the timeout is less than zero, the timeout will be set to 60000.
   * @param millis the write lock timeout  the write lock timeout
   */
  public void setWriteLockTimeout(int millis) {
    this.writeLockTimeout = millis;
    if (this.writeLockTimeout < 0) this.writeLockTimeout = 60000;
  }

  /** methods ================================================================= */

  /**
   * Produces a deep clone of the object.
   *
The duplication constructor is invoked.
   *
return new AsnIndexRef(this);
   * @return the duplicated object
   */
  public AsnIndexReference duplicate() {
    return new AsnIndexReference(this);
  }

  /**
   * Makes an index adapter based upon the associated indexAdapterClass.
   * @param context the assertion operation context
   * @return the index adapter
   * @throws ClassNotFoundException if the class was not found
   * @throws InstantiationException if the class could not be instantiated
   * @throws IllegalAccessException if the class could not be accessed
   */
  public AsnIndexAdapter makeIndexAdapter(AsnContext context)
    throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    if (!this.getEnabled()) {
      String msg = "The index is not enabled: "+this.getName();
      throw new ConfigurationException(msg);
    }
    String className = Val.chkStr(this.getIndexAdapterClass());
    if ((className.length() == 0) || className.equals(AsnIndexAdapter.class.getName())) {
      AsnIndexAdapter broker = new AsnIndexAdapter();
      broker.configure(this);
      return broker;
    } else {
      Class<?> cls = Class.forName(className);
      Object obj = cls.newInstance();
      if (obj instanceof AsnIndexAdapter) {
        AsnIndexAdapter broker = (AsnIndexAdapter)obj;
        broker.configure(this);
        return broker;
      } else {
        String msg = "The configured indexAdapterClass is invalid: "+ className;
        throw new ConfigurationException(msg);
      }
    }
  }

}


text:
cd resource-glacius
npm install

redpajama_set_name: RedPajamaGithub


text:
---
layout: post
title: Solr 入门系列
category: java
tags: [java,solr]
---

## 简介 ##

Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http G  Solret操作提出查找请求,并得到XML格式的返回结果;
 使用相当简单,到http://lucene.apache.org/solr/ 就是Solr的官方,它是基于Lucene开发的一个应用服务器,嵌入了Jetty。使得应用更加方便开发。
 Solr 提供了多种语言的接口,包括php,asp,java,ruby,python等。
Solr入门比较简答,下载压缩包打开后,里面有个readme.txt就指导了怎么启动服务器。
http://localhost:8983/solr/admin/  管理页面
http://localhost:8983/solr/browse 体验页面
http://localhost:8983/solr/admin/analysis.jsp 分词页面

## 基于SolrJ的开发 ##

介绍几个方法,这些都是比较基础的方法,方便新手熟悉API

``` java
/**
 * 创建 SolrServer
 * @param url
 * @return
 * @throws MalformedURLException
 */
public static SolrServer getSolrServer(String url) throws MalformedURLException{
    //the instance can be reused
    return new CommonsHttpSolrServer(url);
}
```
``` java
/**
 * 插入doc
 * @param server
 * @throws SolrServerException
 * @throws IOException
 */
public static void addDocIndex(SolrServer server) throws SolrServerException, IOException{
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField( "id", "id1", 1.0f );
    doc1.addField( "name", "森之魔人", 1.0f );
    doc1.addField( "price", 10 );

    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField( "id", "id2", 1.0f );
    doc2.addField( "name", "小嘻嘻男", 1.0f );
    doc2.addField( "price", 20 );

    Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
    docs.add( doc1 );
    docs.add( doc2 );

    server.add( docs );
    server.commit();
}

```
``` java
/**
 * 批量插入
 * @param server
 * @throws SolrServerException
 * @throws IOException
 */
public static void addBatchDocIndex(SolrServer server) throws SolrServerException, IOException{
    Item item = new Item();
    item.id = "one";
    item.categories =  new String[] { "aaa", "bbb", "ccc" };
    server.addBean(item);

    /* 以下代码可以做批量插入
    List<Item> beans = new ArrayList<Item>();
    beans.add(item);
    server.addBeans(beans);
    */
}
```
``` java
/**
 * 更新doc
 * @param server
 * @throws SolrServerException
 * @throws IOException
 */
public static void updateDocIndex(SolrServer server) throws SolrServerException, IOException{
    UpdateRequest req = new UpdateRequest();
    req.setAction( AbstractUpdateRequest.ACTION.COMMIT, false, false );

    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField( "id", "id1", 1.0f );
    doc1.addField( "name", "魔人", 1.0f );
    doc1.addField( "price", 10 );

    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField( "id", "id2", 1.0f );
    doc2.addField( "name", "嘻嘻男", 1.0f );
    doc2.addField( "price", 20 );

    Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
    docs.add( doc1 );
    docs.add( doc2 );

    req.add( docs );
    UpdateResponse rsp = req.process( server );
}
```
``` java
/**
     * 全部搜索出来,排序
     * @throws MalformedURLException
     * @throws SolrServerException
     */
    public static void search01() throws MalformedURLException, SolrServerException{
        SolrQuery query = new SolrQuery();
        query.setQuery( "*:*" );
        query.addSortField( "price", SolrQuery.ORDER.asc );

        String url = "http://localhost:8983/solr";
        SolrServer server = getSolrServer(url);
        QueryResponse rsp = server.query( query );

        List<Item> beans = rsp.getBeans(Item.class);

        for(Item item : beans){
            System.out.println(item.getId()+" : " + item.getCategories() + " : "+item.getFeatures());
        }
    }
```
``` java
/**
 * 查询某个字段
 * @throws MalformedURLException
 * @throws SolrServerException
 */
public static void search02() throws MalformedURLException, SolrServerException{
    SolrQuery query = new SolrQuery();
    query.setQuery( "name:魔人" );

    String url = "http://localhost:8983/solr";
    SolrServer server = getSolrServer(url);
    QueryResponse rsp = server.query( query );

    SolrDocumentList sdl = rsp.getResults();
    for(int i = 0 ; i < sdl.size() ; i++){
        System.out.println(rsp.getResults().get(i).getFieldValue("id"));
        System.out.println(rsp.getResults().get(i).getFieldValue("name"));
        System.out.println(rsp.getResults().get(i).getFieldValue("price"));
    }

}
```
```java
/**
     * 删除指定索引或者全部索引
     * @param server
     * @throws SolrServerException
     * @throws IOException
     */
    public static void deleteDocIndex(SolrServer server) throws SolrServerException, IOException{
        //server.deleteByQuery("*:*");
        server.deleteByQuery("name:小嘻嘻男");
        server.commit();
    }
```

## schema.xml配置 ##

使用Solr,我们必须学会怎么配置schema.xml。

	-  schema.xml这个配置文件分 几块
	-  <type></type> 模块
	-  <fields></fields>模块
	-  <uniqueKey>id</uniqueKey>      唯一字段
	-  <defaultSearchField>text</defaultSearchField>  搜索字段默认是text
	-  <solrQueryParser defaultOperator="OR" />
	-  <copyField >模块        应该不是必须的

type 模块,我们可以修改使用的分词器
```xml
<fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="true">
      <analyzer type="index" class="org.apache.lucene.analysis.standard.StandardAnalyzer">

<tokenizer class="org.apache.lucene.analysis.standard.StandardAnalyzer"  isMaxWordLength="false"/>

<!--tokenizer class="solr.WhitespaceTokenizerFactory"/-->
        <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!-- Case insensitive stop word removal.
          add enablePositionIncrements=true in both the index and query
          analyzers to leave a 'gap' for more accurate phrase queries.
        -->
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="stopwords.txt"
                enablePositionIncrements="true"
                />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query" class="org.apache.lucene.analysis.standard.StandardAnalyzer">
        <!--tokenizer class="solr.WhitespaceTokenizerFactory"/-->

<tokenizer class="org.apache.lucene.analysis.standard.StandardAnalyzer" isMaxWordLength="true"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="stopwords.txt"
                enablePositionIncrements="true"
                />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>
```
fields 模块,我们可以配置我们需要的字段
``` xml
<field name="cusid" type="string" indexed="true" stored="true" required="true" />
<field name="cusname" type="text" indexed="true" stored="true" omitNorms="true"/>
<field name="cuskeyname" type="textTight" indexed="true" stored="true"/>
```

## Solr的检索运算符 ##

    1. ":" 指定字段查指定值,如返回所有值*:*
    2. "?" 表示单个任意字符的通配
    3. "*" 表示多个任意字符的通配(不能在检索的项开始使用*或者?符号)
    4. "~" 表示模糊检索,如检索拼写类似于"roam"的项这样写:roam~将找到形如foam和roams的单词;roam~0.8,检索返回相似度在0.8以上的记录。
    5. 邻近检索,如检索相隔10个单词的"apache"和"jakarta","jakarta apache"~10
    6. "^" 控制相关度检索,如检索jakarta apache,同时希望去让"jakarta"的相关度更加好,那么在其后加上"^"符号和增量值,即jakarta^4 apache
    7. 布尔操作符AND、||
    8. 布尔操作符OR、&&
    9. 布尔操作符NOT、!、- (排除操作符不能单独与项使用构成查询)
    10. "+" 存在操作符,要求符号"+"后的项必须在文档相应的域中存在
    11. ( ) 用于构成子查询
    12. [] 包含范围检索,如检索某时间段记录,包含头尾,date:[200707 TO 200710]
    13. {} 不包含范围检索,如检索某时间段记录,不包含头尾
    date:{200707 TO 200710}
    14. \ 转义操作符,特殊字符包括+ - && || ! ( ) { } [ ] ^ " ~ * ? : \

## 感受 ##

今天对半年前用lucene做的索引重新做了一遍,发现居然用solr做索引非常快。有意想不到的速度体现。
慢慢写,未完!


text:
package org.revenj.patterns;

import java.io.Serializable;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public interface Query<T extends DataSource> {

	Query<T> filter(Specification<T> predicate);

	Query<T> skip(long n);

	Query<T> limit(long n);

	@FunctionalInterface
	interface Compare<U, V extends Comparable<V>> extends Serializable {
		V compare(U item);
	}

	<V extends Comparable<V>> Query<T> sortedBy(Compare<T, V> order);

	<V extends Comparable<V>> Query<T> sortedDescendingBy(Compare<T, V> order);

	long count() throws IOException;

	boolean anyMatch(Specification<? super T> predicate) throws IOException;

	default boolean any() throws IOException {
		return anyMatch(null);
	}

	boolean allMatch(Specification<? super T> predicate) throws IOException;

	boolean noneMatch(Specification<? super T> predicate) throws IOException;

	Optional<T> findFirst() throws IOException;

	Optional<T> findAny() throws IOException;

	List<T> list() throws IOException;

	default Stream<T> stream() throws IOException {
		return list().stream();
	}
}


text:
package com.wesabe.servlet.normalizers;

import com.wesabe.servlet.normalizers.util.CharacterSet;

/**
 * Normalizes servlet parameter names.
 *
 * @author coda
 */
public class ParameterNameNormalizer implements Normalizer<String> {
	private static final CharacterSet VALID_CHARACTERS = CharacterSet.of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
	@Override
	public String normalize(String input) throws ValidationException {
		if (VALID_CHARACTERS.composes(input)) {
			return input;
		}

		throw new ValidationException(input, "not a valid parameter name");
	}

}


text:
import Guble from '../src/main.js';
import assert from 'assert';
import * as mock from 'mock-socket';
//global.WebSocket = global.MockWebSocket;
global.WebSocket = mock.WebSocket;

describe('test sending messages', function() {
    it('send raw data to the server', done => {
      const mockServer = new mock.Server("ws://127.0.0.1:8080/stream/user");
      var messages = [];
      mockServer.on('message', data => messages.push(data));

      var g = new Guble("ws://127.0.0.1:8080/");
      g.connect("user");
      g.sendRaw("Hello World");
      g.sendRaw("foo");
      g.sendRaw("bar");

      setTimeout(() => {
        assert.deepEqual(['Hello World', 'foo', 'bar'], messages);
        done();
      }, 0);

    });
});


text:
<!DOCTYPE html>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>AdminLTE 2 | Simple Tables</title>

        <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

        <link rel="stylesheet" href="<?php echo admin_template_url();?>bootstrap/css/bootstrap.min.css">

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">

        <link rel="stylesheet" href="<?php echo admin_template_url();?>dist/css/AdminLTE.min.css">

        <link rel="stylesheet" href="<?php echo admin_template_url();?>dist/css/skins/_all-skins.min.css">
        <link rel="stylesheet" href="<?php echo admin_public_url();?>css/global-style.css">

			<?php
			    $this->load->view('admincp/layout/header');
			    //
			    $this->load->view('admincp/layout/aside');
			?>

					<?php
			    		$this->load->view($view);
			    	?>

		    	<?php
			    $this->load->view('admincp/layout/footer');
			?>

Recent Activity

Langdon's Birthday

Will be 23 on April 24th

Frodo Updated His Profile

New phone +1(800)555-1234

Nora Joined Mailing List

nora@example.com

Cron Job 254 Executed

Execution time 5 seconds

Tasks Progress

                                        Custom Template Design
                                        70%

                                        Update Resume
                                        95%

                                        Laravel Integration
                                        50%

                                        Back End Framework
                                        68%

Stats Tab Content

                        <form method="post">

General Settings

                                Report panel usage
                                <input type="checkbox" class="pull-right" checked>

                                    Some information about this general settings option

                                Allow mail redirect
                                <input type="checkbox" class="pull-right" checked>

                                    Other sets of options are available

                                Expose author name in posts
                                <input type="checkbox" class="pull-right" checked>

                                    Allow the user to show his name in blog posts

Chat Settings

                                Show me as online
                                <input type="checkbox" class="pull-right" checked>

                                Turn off notifications
                                <input type="checkbox" class="pull-right">

                                Delete chat history

                        </form>


text:
package sage;

public abstract class MetaFont
{
  /**
   * The plain style constant.
   */
  public static final int PLAIN	= 0;

  /**
   * The bold style constant.  This can be combined with the other style
   * constants (except PLAIN) for mixed styles.
   */
  public static final int BOLD	= 1;

  /**
   * The italicized style constant.  This can be combined with the other
   * style constants (except PLAIN) for mixed styles.
   */
  public static final int ITALIC	= 2;

  private static final boolean USE_JAVA_FONTS = Sage.getBoolean("ui/disable_freetype_fonts", false);
  public static MetaFont getFont(String fontName, int fontStyle, int fontSize)
  {
    if (USE_JAVA_FONTS)
      return new JavaFont(fontName, fontStyle, fontSize);
    else
    {
      try
      {
        return new FreetypeFont(fontName, fontStyle, fontSize);
      }
      catch (Throwable e)
      {
        if (Sage.DBG && !(e instanceof java.io.FileNotFoundException)) System.out.println("Error loading Freetype Font; trying to load Java font instead; error=" + e);
        return new JavaFont(fontName, fontStyle, fontSize);
      }
    }
  }
  public MetaFont(String fontName, int fontStyle, int fontSize)
  {
    size = fontSize;
    name = fontName;
    style = fontStyle;
  }
  public abstract MetaFont deriveFontSize(int newSize, UIManager uiLoader);
  public abstract MetaFont deriveFont(int newStyle, UIManager uiLoader);
  public abstract /*EMBEDDED_SWITCH*/float/*/int/**/ getHeight();
  public abstract int stringWidth(String s);
  public /*EMBEDDED_SWITCH*/float/*/int/**/ charWidth(char c)
  {
    return stringWidth("" + c);
  }
  public abstract /*EMBEDDED_SWITCH*/float/*/int/**/ getAscent();
  public abstract /*EMBEDDED_SWITCH*/float/*/int/**/ getDescent();

  public abstract GlyphVector createGlyphVector(String s);
  public abstract GlyphVector[] createGlyphVectors(String s, int wrapWidth);

  public abstract /*EMBEDDED_SWITCH*/float/*/int/**/ getLeading();
  public String getName() { return name; }
  public int getSize() { return size; }
  public int getStyle() { return style; }
  public abstract void releaseNativeFont();
  public abstract long getNativeFontHandle();
  public abstract int getNumGlyphs();
  // Creates the rect maps for the glyphs for the accelerated font. This does not actually do the rendering.
  public abstract SageRenderer.CachedFontGlyphs loadAcceleratedFont(int maxRequiredGlyphCode, int width, int height);
  // These methods will create the actual image to be used in the caching system
  public abstract java.awt.image.BufferedImage loadJavaFontImage(SageRenderer.CachedFontGlyphs cacheData, int imageIndex);
  public abstract sage.media.image.RawImage loadRawFontImage(SageRenderer.CachedFontGlyphs cacheData, int imageIndex);
  public String toString()
  {
    return "MetaFont[" + name + ", size=" + size + ", style=" + style + ", height=" + height +
        ", ascent=" + ascent + ", descent=" + descent + ", leading=" + leading + ", class=" + getClass() + "]";
  }

  public boolean equals(Object o)
  {
    return (o instanceof MetaFont) && ((MetaFont) o).name.equals(name) && (((MetaFont) o).size == size) && (((MetaFont) o).style == style);
  }

  public int hashCode()
  {
    return name.hashCode() ^ 7*size ^ 273*style;
  }

  public static java.awt.Font getJavaFont(MetaFont font)
  {
    return UIManager.getCachedJavaFont(font.name, font.style, font.size);
  }

  protected String name;
  protected int size;
  protected int style;
  protected long nativeHandle;
  protected float height;
  protected float ascent;
  protected float descent;
  protected float leading;

  public static class JavaFont extends MetaFont
  {
    public JavaFont(String fontName, int fontStyle, int fontSize)
    {
      super(fontName, fontStyle, fontSize);
      myFont = UIManager.getCachedJavaFont(fontName, fontStyle, fontSize);
      frc = new java.awt.font.FontRenderContext(null, true, false);
      java.awt.font.LineMetrics metrics = myFont.getLineMetrics("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz0123456789", frc);
      height = metrics.getHeight();
      ascent = metrics.getAscent();
      leading = metrics.getLeading();
      descent = metrics.getDescent();
    }
    public MetaFont deriveFontSize(int newSize, UIManager uiLoader)
    {
      return new JavaFont(name, style, newSize);
    }
    public MetaFont deriveFont(int newStyle, UIManager uiLoader)
    {
      return new JavaFont(name, newStyle, size);
    }

    public float getHeight()
    {
      return height;
    }

    public int stringWidth(String s)
    {
      return (int)myFont.getStringBounds(s, frc).getWidth();
    }

    public float getAscent()
    {
      return ascent;
    }

    public float getDescent()
    {
      return descent;
    }

    public float getLeading()
    {
      return leading;
    }

    public void releaseNativeFont()
    {
    }

    public long getNativeFontHandle()
    {
      return 0;
    }

    public MetaFont.GlyphVector createGlyphVector(String s)
    {
      return new JavaGlyphVector(this, s, new java.awt.font.TextLayout(s, myFont, frc), frc);
    }

    public MetaFont.GlyphVector[] createGlyphVectors(String s, int wrapWidth)
    {
      java.util.ArrayList rv = new java.util.ArrayList();
      java.text.AttributedString attStr = new java.text.AttributedString(s);
      attStr.addAttribute(java.awt.font.TextAttribute.FONT, myFont);
      java.awt.font.LineBreakMeasurer lbm =
          new java.awt.font.LineBreakMeasurer(attStr.getIterator(), frc);
      int idx0 = 0;
      java.awt.font.TextLayout currLay = lbm.nextLayout(wrapWidth);
      while (currLay != null)
      {
        rv.add(new JavaGlyphVector(this, s.substring(idx0, lbm.getPosition()), currLay, frc));
        idx0 = lbm.getPosition();
        currLay = lbm.nextLayout(wrapWidth);
      }
      return (MetaFont.GlyphVector[]) rv.toArray(new MetaFont.GlyphVector[0]);
    }

    public int getNumGlyphs()
    {
      return myFont.getNumGlyphs();
    }

    public SageRenderer.CachedFontGlyphs loadAcceleratedFont(int maxRequiredGlyphCode, int width, int height)
    {
      int x = 0;
      int y = 0;
      int maxHeightForRow = 0;
      int maxWidthForGlyph = 0;
      boolean fixedGlyphCacheWidth = !Sage.getBoolean("ui/load_complete_glyph_maps", false);
      if (fixedGlyphCacheWidth)
      {
        maxWidthForGlyph = stringWidth("W") + 4;
        maxWidthForGlyph = Math.max(maxWidthForGlyph, stringWidth("" + '\u5355') + 4);
      }
      int orgMaxRequiredGlyphCode = maxRequiredGlyphCode;
      maxRequiredGlyphCode = Integer.MAX_VALUE;
      SageRenderer.CachedFontGlyphs rv = new SageRenderer.CachedFontGlyphs();
      rv.font = this;
      rv.width = width;
      rv.height = height;
      int imageCount = 0;
      int numCachedGlyphs = 0;
      int numGlyphs = getNumGlyphs();
      rv.numGlyphs = numGlyphs;
      rv.imageIndexByGlyphCode = new int[numGlyphs];
      java.util.Arrays.fill(rv.imageIndexByGlyphCode, -1);
      rv.pixelRectByGlyphCode = new java.awt.geom.Rectangle2D.Float[numGlyphs];
      rv.logicalRectByGlyphCode = new java.awt.geom.Rectangle2D.Float[numGlyphs];
      int[] tmpGlyphCounts = new int[1024]; // way more then we'd ever have
      int i = 0;
      for (; i < numGlyphs; i++)
      {
        java.awt.geom.Rectangle2D glyphBounds;
        java.awt.Rectangle pixelBounds;
        if (fixedGlyphCacheWidth && i > orgMaxRequiredGlyphCode)
        {
          glyphBounds = new java.awt.geom.Rectangle2D.Float(0, 0, maxWidthForGlyph, getHeight());
          pixelBounds = new java.awt.Rectangle(-2, (int)Math.floor(-getAscent()), maxWidthForGlyph, (int)Math.ceil(getHeight()));
        }
        else
        {
          java.awt.font.GlyphVector currGlyph = myFont.createGlyphVector(frc, new int[] { i });
          glyphBounds = currGlyph.getLogicalBounds();
          pixelBounds = currGlyph.getGlyphPixelBounds(0, frc, 0, 0);
        }
        if (x + pixelBounds.width >= width)
        {
          // Move us on to the next line
          x = 0;
          y += maxHeightForRow + 1;
          maxHeightForRow = 0;
        }
        if (y + glyphBounds.getHeight() >= height)
        {
          // Move on to the next image
          if (i > maxRequiredGlyphCode)
            break;
          tmpGlyphCounts[imageCount] = i;
          imageCount++;
          if (tmpGlyphCounts.length <= imageCount)
          {
            int[] newTemp = new int[tmpGlyphCounts.length * 2];
            System.arraycopy(tmpGlyphCounts, 0, newTemp, 0, tmpGlyphCounts.length);
            tmpGlyphCounts = newTemp;
          }
          x = 0;
          y = 0;
          maxHeightForRow = 0;
        }
        // pixelBounds tells us what pixels the glyph will cover in the image
        // If we've got a negative x; then we need to shift over more in x so we don't overlap prior glyphs
        // If we've got a positive y; then we've got extra wasted space on the left side and we can decrease x
        x -= pixelBounds.x;
        numCachedGlyphs = i;
        rv.imageIndexByGlyphCode[i] = imageCount;
        rv.pixelRectByGlyphCode[i] = new java.awt.geom.Rectangle2D.Float(x + pixelBounds.x, y,
            pixelBounds.width, pixelBounds.height);
        rv.logicalRectByGlyphCode[i] = new java.awt.geom.Rectangle2D.Float(x, y - pixelBounds.y,
            (float)glyphBounds.getWidth(), (float)glyphBounds.getHeight());
        maxHeightForRow = Math.max(maxHeightForRow, pixelBounds.height);
        x += pixelBounds.width + pixelBounds.x + 1;
      }
      tmpGlyphCounts[imageCount] = i;
      rv.glyphCounts = new int[imageCount + 1];
      System.arraycopy(tmpGlyphCounts, 0, rv.glyphCounts, 0, imageCount + 1);
      if (Sage.DBG) System.out.println("Loaded font cache info for " + this + " numGlyphs=" + numGlyphs + " maxGlyph=" + maxRequiredGlyphCode);
      return rv;
    }

    public java.awt.image.BufferedImage loadJavaFontImage(SageRenderer.CachedFontGlyphs cacheData, int imageIndex)
    {
      int x = 1; // to avoid overlap on the leftmost pixel
      int y = 0;
      int maxHeightForRow = 0;
      java.awt.image.BufferedImage currImage = new java.awt.image.BufferedImage(cacheData.width, cacheData.height,
          java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);
      java.awt.Graphics2D g2 = currImage.createGraphics();
      g2.setRenderingHint(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      g2.setColor(java.awt.Color.white);
      int numGlyphs = getNumGlyphs();
      int startGlyph = (imageIndex == 0) ? 0 : cacheData.glyphCounts[imageIndex - 1];
      int endGlyph = Math.min(numGlyphs, cacheData.glyphCounts[imageIndex] - 1);
      for (int i = startGlyph; i <= endGlyph; i++)
      {
        java.awt.font.GlyphVector currGlyph = myFont.createGlyphVector(frc, new int[] { i });
        g2.setClip(cacheData.pixelRectByGlyphCode[i]);// make sure the glyph doesn't overwrite other glyphs
        g2.drawGlyphVector(currGlyph, cacheData.logicalRectByGlyphCode[i].x, cacheData.logicalRectByGlyphCode[i].y);
      }
      g2.dispose();

      // Fix the alpha for the image
      if (UIManager.shouldAntialiasFont(getSize()) && !Sage.getBoolean("ui/dont_premultiply_alpha_for_3dfontmaps", false))
      {
        int[] texturedata = ((java.awt.image.DataBufferInt) currImage.getRaster().getDataBuffer()).getData();
        for (int j = 0; j < texturedata.length; j++)
        {
          int tmp = (texturedata[j] >> 24) & 0xFF;
          if (tmp != 0)
          {
            tmp = tmp | (tmp << 8);
            texturedata[j] = tmp | (tmp << 16);
          }
        }
      }

      if (Sage.DBG) System.out.println("Rendered new font to cache index=" + imageIndex + " font=" + myFont);
      if (Sage.getBoolean("ui/dump_font_cache", false))
      {
        try
        {
          java.io.FileOutputStream os = new java.io.FileOutputStream(getName() + getSize() + "_" + imageIndex + ".png");
          javax.imageio.ImageIO.write(currImage, "png", os);
          os.close();
        }catch(Exception e){}
      }
      return currImage;
    }

    public sage.media.image.RawImage loadRawFontImage(SageRenderer.CachedFontGlyphs cacheData, int imageIndex)
    {
      return new sage.media.image.RawImage(loadJavaFontImage(cacheData, imageIndex));
    }

    private java.awt.Font myFont;
    private java.awt.font.FontRenderContext frc;
  }

  public static abstract class GlyphVector
  {
    public /*EMBEDDED_SWITCH*/float/*/int/**/ getAdvance()
    {
      return advance;
    }
    public /*EMBEDDED_SWITCH*/float/*/int/**/ getVisibleAdvance()
    {
      return visAdvance;
    }
    public String getText()
    {
      return text;
    }
    public int getNumGlyphs()
    {
      return glyphCodes.length;
    }
    public int getGlyphCode(int i)
    {
      return glyphCodes[i];
    }
    public float getGlyphPosition(int i)
    {
      return glyphPos[i];
    }
    public java.awt.geom.Rectangle2D getLogicalBounds()
    {
      return boundingBox;
    }
    public /*EMBEDDED_SWITCH*/float/*/int/**/ getHeight()
    {
      // With Freetype, sometimes the ascent + descent is greater than the height, and this would then cause the bottom
      // of glyphs to get cutoff since we would use this height as the source bounding box for the rendering operation
      return Math.max(font.getHeight(), font.getAscent() + font.getDescent());
    }
    protected /*EMBEDDED_SWITCH*/float/*/int/**/ advance;
    protected /*EMBEDDED_SWITCH*/float/*/int/**/ visAdvance;
    protected String text;
    protected int[] glyphCodes;
    protected float[] glyphPos;
    protected MetaFont font;
    protected java.awt.geom.Rectangle2D.Float boundingBox; // relative to a baseline at the origin
  }
  public static final boolean ENABLE_BIDI_ANALYSIS = Sage.getBoolean("ui/load_complete_glyph_maps", false);

  public static class JavaGlyphVector extends GlyphVector
  {
    public JavaGlyphVector(MetaFont inFont, String inText, java.awt.font.TextLayout inLayer, java.awt.font.FontRenderContext frc)
    {
      font = inFont;
      if (ENABLE_BIDI_ANALYSIS)
      {
        // Perform Bidi analysis to reverse the proper portions of the text
        java.text.Bidi booty = new java.text.Bidi(inText, java.text.Bidi.DIRECTION_LEFT_TO_RIGHT);
        if (booty.isLeftToRight())
        {
          javaGV = MetaFont.getJavaFont(font).createGlyphVector(frc, inText);
        }
        else
        {
          if (booty.isRightToLeft())
          {
            javaGV = MetaFont.getJavaFont(font).createGlyphVector(frc, new StringBuffer(inText).reverse().toString().trim());
          }
          else
          {
            int runCounts = booty.getRunCount();
            byte[] levelInfo = new byte[runCounts];
            Object[] textObjs = new Object[runCounts];
            for (int i = 0; i < runCounts; i++)
            {
              levelInfo[i] = (byte)booty.getRunLevel(i);
              textObjs[i] = inText.substring(booty.getRunStart(i), booty.getRunLimit(i));
              textObjs[i] = (levelInfo[i] % 2) == booty.getBaseLevel() ? textObjs[i].toString() :
                new StringBuffer(textObjs[i].toString()).reverse().toString();
            }
            java.text.Bidi.reorderVisually(levelInfo, 0, textObjs, 0, runCounts);
            StringBuffer newText = new StringBuffer(inText.length() + 1);
            for (int i = 0; i < textObjs.length; i++)
              newText.append(textObjs[i].toString());
            javaGV = MetaFont.getJavaFont(font).createGlyphVector(frc, newText.toString());
          }
        }
      }
      else
        javaGV = MetaFont.getJavaFont(font).createGlyphVector(frc, inText);
      advance = inLayer.getAdvance();
      visAdvance = inLayer.getVisibleAdvance();
      text = inText;
    }

    public int getNumGlyphs()
    {
      return javaGV.getNumGlyphs();
    }

    public int getGlyphCode(int i)
    {
      return javaGV.getGlyphCode(i);
    }

    public float getGlyphPosition(int i)
    {
      return (float)javaGV.getGlyphPosition(i).getX();
    }

    public java.awt.font.GlyphVector getJavaGV()
    {
      return javaGV;
    }
    public java.awt.geom.Rectangle2D getLogicalBounds()
    {
      return javaGV.getLogicalBounds();
    }
    private java.awt.font.GlyphVector javaGV;
  }
}


text:
package com.github.rvesse.airline.io.decorations;

/**
 * Interface for classes that provide ANSI decorations
 *
 */
public interface AnsiDecorationProvider {

    /**
     * Gets the ANSI control code for enabling a decoration
     *
     * @return Control code
     */
    public abstract String getAnsiDecorationEnabledControlCode();

    /**
     * Gets the ANSI control code for disabling a decoration
     *
     * @return Control Code
     */
    public abstract String getAnsiDecorationDisabledControlCode();

}


text:
package fasthttp

import (
	"bufio"
	"errors"
	"io"
	"net"
	"net/http"
	"strings"

	"github.com/admpub/fasthttp"
	"github.com/admpub/log"
	"github.com/webx-top/echo/engine"
	"github.com/webx-top/echo/logger"
)

var ErrAlreadyCommitted = errors.New(`response already committed`)

type (
	Response struct {
		context           *fasthttp.RequestCtx
		header            engine.Header
		status            int
		size              int64
		committed         bool
		writer            io.Writer
		logger            logger.Logger
		stdResponseWriter http.ResponseWriter
	}
)

func NewResponse(c *fasthttp.RequestCtx) *Response {
	return &Response{
		context: c,
		header:  &ResponseHeader{header: &c.Response.Header, stdhdr: nil},
		writer:  c,
		logger:  log.New("echo"),
	}
}

func (r *Response) Object() interface{} {
	return r.context
}

func (r *Response) Header() engine.Header {
	return r.header
}

func (r *Response) WriteHeader(code int) {
	if r.committed {
		r.logger.Warn(ErrAlreadyCommitted.Error())
		return
	}
	r.status = code
	r.context.SetStatusCode(code)
	r.committed = true
}

func (r *Response) KeepBody(_ bool) {
}

func (r *Response) Write(b []byte) (n int, err error) {
	n, err = r.writer.Write(b)
	r.size += int64(n)
	return
}

func (r *Response) Status() int {
	return r.status
}

func (r *Response) Size() int64 {
	return r.size
}

func (r *Response) Committed() bool {
	return r.committed
}

func (r *Response) SetWriter(w io.Writer) {
	r.writer = w
}

func (r *Response) Writer() io.Writer {
	return r.writer
}

func (r *Response) Hijack(fn func(net.Conn)) {
	r.context.Hijack(fasthttp.HijackHandler(fn))
	r.committed = true
}

func (r *Response) Body() []byte {
	switch strings.ToLower(r.header.Get(`Content-Encoding`)) {
	case `gzip`:
		body, err := r.context.Response.BodyGunzip()
		if err != nil {
			r.logger.Error(err)
		}
		return body
	case `deflate`:
		body, err := r.context.Response.BodyInflate()
		if err != nil {
			r.logger.Error(err)
		}
		return body
	default:
		return r.context.Response.Body()
	}
}

func (r *Response) Redirect(url string, code int) {
	//r.context.Redirect(url, code)  bug: missing port number
	r.header.Set(`Location`, url)
	r.WriteHeader(code)
}

func (r *Response) NotFound() {
	r.context.NotFound()
	r.committed = true
}

func (r *Response) SetCookie(cookie *http.Cookie) {
	r.header.Add(engine.HeaderSetCookie, cookie.String())
}

func (r *Response) ServeFile(file string) {
	fasthttp.ServeFile(r.context, file)
	r.committed = true
}

func (r *Response) Stream(step func(io.Writer) bool) {
	r.context.SetBodyStreamWriter(func(w *bufio.Writer) {
		//TODO
	})
}

func (r *Response) Error(errMsg string, args ...int) {
	if len(args) > 0 {
		r.status = args[0]
	} else {
		r.status = fasthttp.StatusInternalServerError
	}
	r.Write(engine.Str2bytes(errMsg))
	r.WriteHeader(r.status)
}

func (r *Response) reset(c *fasthttp.RequestCtx, h engine.Header) {
	r.context = c
	r.header = h
	r.status = http.StatusOK
	r.size = 0
	r.committed = false
	r.writer = c
	r.stdResponseWriter = nil
}

func (r *Response) StdResponseWriter() http.ResponseWriter {
	if r.stdResponseWriter != nil {
		return r.stdResponseWriter
	}
	w := &netHTTPResponseWriter{
		response: r,
	}
	r.stdResponseWriter = w
	return w
}

type netHTTPResponseWriter struct {
	h        http.Header
	response *Response
}

func (w *netHTTPResponseWriter) StatusCode() int {
	if w.response.Status() == 0 {
		return http.StatusOK
	}
	return w.response.Status()
}

func (w *netHTTPResponseWriter) Header() http.Header {
	if w.h == nil {
		w.h = make(http.Header)
	}
	return w.h
}

func (w *netHTTPResponseWriter) WriteHeader(statusCode int) {
	if w.response.committed {
		return
	}
	w.response.WriteHeader(statusCode)
	h := w.response.Header()
	for k, vv := range w.Header() {
		for _, v := range vv {
			h.Set(k, v)
		}
	}
}

func (w *netHTTPResponseWriter) Write(b []byte) (int, error) {
	if w.response.committed {
		return 0, ErrAlreadyCommitted
	}
	return w.response.Write(b)
}


text:
package javax.json.bind.adapter;

public interface JsonbAdapter<A, B> {
    A adaptToJson(B obj) throws Exception;
    B adaptFromJson(A obj) throws Exception;
}


text:
package com.mlick.demo.animation;

import android.view.View;

import com.mlick.base.BaseActivity;
import com.mlick.demo.R;
import com.mlick.demo.animation.view.RoundArcView;

import butterknife.BindView;

/**
 * Created by lxx on 2016/7/5 10:00
 */
public class RoundArcActivity extends BaseActivity {
    @BindView(R.id.roundArcView) RoundArcView roundArcView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_round_arc;
    }

    @Override
    public void initViewData() {
        roundArcView.evaluate(30, 40, 20, "", "", "");
    }

    @Override
    public void onClick(View v) {

    }
}


text:
(function (window, navigator) {
    "use strict";

    angular.module("ngAudioFxCore").run(run);

    function run() {
        // normalize AudioContext
        window.AudioContext = window.AudioContext || window.webkitAudioContext;
        // normalize getUserMedia
        navigator.getUserMedia = navigator.getUserMedia ||
                                navigator.webkitGetUserMedia ||
                                navigator.mozGetUserMedia ||
                                navigator.msGetUserMedia;

        // normalize requestAnimationFrame
        (function() {
            var lastTime = 0;
            var vendors = ['webkit', 'moz'];
            for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
                window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
                window.cancelAnimationFrame =
                    window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
            }

            if (!window.requestAnimationFrame)
                window.requestAnimationFrame = function(callback, element) {
                    var currTime = new Date().getTime();
                    var timeToCall = Math.max(0, 16 - (currTime - lastTime));
                    var id = window.setTimeout(function() { callback(currTime + timeToCall); },
                        timeToCall);
                    lastTime = currTime + timeToCall;
                    return id;
                };

            if (!window.cancelAnimationFrame)
                window.cancelAnimationFrame = function(id) {
                    clearTimeout(id);
                };
        }());
    }
})(window || {}, navigator || {});


text:
package org.elasticsearch.painless.ir;

import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.phase.IRTreeVisitor;

public class FlipDefIndexNode extends UnaryNode {

    /* ---- begin visitor ---- */

    @Override
    public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
        irTreeVisitor.visitFlipDefIndex(this, scope);
    }

    @Override
    public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
        getChildNode().visit(irTreeVisitor, scope);
    }

    /* ---- end visitor ---- */

    public FlipDefIndexNode(Location location) {
        super(location);
    }

}


text:
package net.novaviper.zeroquest.common.world.biome;

import java.util.Random;

import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.novaviper.zeroquest.ModBlocks;
import net.novaviper.zeroquest.common.entity.creature.EntityDarkZertum;
import net.novaviper.zeroquest.common.entity.mob.EntityKurr;
import net.novaviper.zeroquest.common.lib.Constants;

public class BiomeGenDarkLand extends BiomeGenBase {

    public Random par2Random;

	public BiomeGenDarkLand(int id) {
        super(id);
       	this.waterColorMultiplier = 0x666600;
       	this.theBiomeDecorator.treesPerChunk = 1;
       	this.theBiomeDecorator.grassPerChunk = 1;
       	this.theBiomeDecorator.flowersPerChunk = -999;
       	this.addFlower(ModBlocks.nileBlackFlower.getDefaultState(), 100);
        this.theBiomeDecorator.generateLakes = true;
        this.spawnableMonsterList.clear();
        this.spawnableCreatureList.clear();
        this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(EntityBat.class, 60, 1, 5));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityMagmaCube.class, 1, 4, 4));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityPigZombie.class, 20, 2, 3));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityGhast.class, 20, 1, 2));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntitySpider.class, 100, 4, 4));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(EntityZombie.class, 100, 4, 4));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public int getModdedBiomeGrassColor(int par1){return 0x660066;}
    @SideOnly(Side.CLIENT)
    @Override
    public int getModdedBiomeFoliageColor(int par1){return 0x660066;}
    @SideOnly(Side.CLIENT)
    @Override
    public int getSkyColorByTemp(float par1){return 0x333333;}
}


text:
import music21
import torch
import numpy as np

from music21 import interval, stream
from torch.utils.data import TensorDataset
from tqdm import tqdm

from DatasetManager.helpers import standard_name, SLUR_SYMBOL, START_SYMBOL, END_SYMBOL, \
    standard_note, OUT_OF_RANGE, REST_SYMBOL
from DatasetManager.metadata import FermataMetadata
from DatasetManager.music_dataset import MusicDataset

class ChoraleDataset(MusicDataset):
    """
    Class for all chorale-like datasets
    """

    def __init__(self,
                 corpus_it_gen,
                 name,
                 voice_ids,
                 metadatas=None,
                 sequences_size=8,
                 subdivision=4,
                 cache_dir=None):
        """
        :param corpus_it_gen: calling this function returns an iterator
        over chorales (as music21 scores)
        :param name: name of the dataset
        :param voice_ids: list of voice_indexes to be used
        :param metadatas: list[Metadata], the list of used metadatas
        :param sequences_size: in beats
        :param subdivision: number of sixteenth notes per beat
        :param cache_dir: directory where tensor_dataset is stored
        """
        super(ChoraleDataset, self).__init__(cache_dir=cache_dir)
        self.voice_ids = voice_ids
        # TODO WARNING voice_ids is never used!
        self.num_voices = len(voice_ids)
        self.name = name
        self.sequences_size = sequences_size
        self.index2note_dicts = None
        self.note2index_dicts = None
        self.corpus_it_gen = corpus_it_gen
        self.voice_ranges = None  # in midi pitch
        self.metadatas = metadatas
        self.subdivision = subdivision

    def __repr__(self):
        return f'ChoraleDataset(' \
               f'{self.voice_ids},' \
               f'{self.name},' \
               f'{[metadata.name for metadata in self.metadatas]},' \
               f'{self.sequences_size},' \
               f'{self.subdivision})'

    def iterator_gen(self):
        return (chorale
                for chorale in self.corpus_it_gen()
                if self.is_valid(chorale)
                )

    def make_tensor_dataset(self):
        """
        Implementation of the make_tensor_dataset abstract base class
        """
        # todo check on chorale with Chord
        print('Making tensor dataset')
        self.compute_index_dicts()
        self.compute_voice_ranges()
        one_tick = 1 / self.subdivision
        chorale_tensor_dataset = []
        metadata_tensor_dataset = []
        for chorale_id, chorale in tqdm(enumerate(self.iterator_gen())):

            # precompute all possible transpositions and corresponding metadatas
            chorale_transpositions = {}
            metadatas_transpositions = {}

            # main loop
            for offsetStart in np.arange(
                    chorale.flat.lowestOffset -
                    (self.sequences_size - one_tick),
                    chorale.flat.highestOffset,
                    one_tick):
                offsetEnd = offsetStart + self.sequences_size
                current_subseq_ranges = self.voice_range_in_subsequence(
                    chorale,
                    offsetStart=offsetStart,
                    offsetEnd=offsetEnd)

                transposition = self.min_max_transposition(current_subseq_ranges)
                min_transposition_subsequence, max_transposition_subsequence = transposition

                for semi_tone in range(min_transposition_subsequence,
                                       max_transposition_subsequence + 1):
                    start_tick = int(offsetStart * self.subdivision)
                    end_tick = int(offsetEnd * self.subdivision)

                    try:
                        # compute transpositions lazily
                        if semi_tone not in chorale_transpositions:
                            (chorale_tensor,
                             metadata_tensor) = self.transposed_score_and_metadata_tensors(
                                chorale,
                                semi_tone=semi_tone)
                            chorale_transpositions.update(
                                {semi_tone:
                                     chorale_tensor})
                            metadatas_transpositions.update(
                                {semi_tone:
                                     metadata_tensor})
                        else:
                            chorale_tensor = chorale_transpositions[semi_tone]
                            metadata_tensor = metadatas_transpositions[semi_tone]

                        local_chorale_tensor = self.extract_score_tensor_with_padding(
                            chorale_tensor,
                            start_tick, end_tick)
                        local_metadata_tensor = self.extract_metadata_with_padding(
                            metadata_tensor,
                            start_tick, end_tick)

                        # append and add batch dimension
                        # cast to int
                        chorale_tensor_dataset.append(
                            local_chorale_tensor[None, :, :].int())
                        metadata_tensor_dataset.append(
                            local_metadata_tensor[None, :, :, :].int())
                    except KeyError:
                        # some problems may occur with the key analyzer
                        print(f'KeyError with chorale {chorale_id}')

        chorale_tensor_dataset = torch.cat(chorale_tensor_dataset, 0)
        metadata_tensor_dataset = torch.cat(metadata_tensor_dataset, 0)

        dataset = TensorDataset(chorale_tensor_dataset,
                                metadata_tensor_dataset)

        print(f'Sizes: {chorale_tensor_dataset.size()}, {metadata_tensor_dataset.size()}')
        return dataset

    def transposed_score_and_metadata_tensors(self, score, semi_tone):
        """
        Convert chorale to a couple (chorale_tensor, metadata_tensor),
        the original chorale is transposed semi_tone number of semi-tones
        :param chorale: music21 object
        :param semi_tone:
        :return: couple of tensors
        """
        # transpose
        # compute the most "natural" interval given a number of semi-tones
        interval_type, interval_nature = interval.convertSemitoneToSpecifierGeneric(
            semi_tone)
        transposition_interval = interval.Interval(
            str(interval_nature) + str(interval_type))

        chorale_tranposed = score.transpose(transposition_interval)
        chorale_tensor = self.get_score_tensor(
            chorale_tranposed,
            offsetStart=0.,
            offsetEnd=chorale_tranposed.flat.highestTime)
        metadatas_transposed = self.get_metadata_tensor(chorale_tranposed)
        return chorale_tensor, metadatas_transposed

    def get_metadata_tensor(self, score):
        """
        Adds also the index of the voices
        :param score: music21 stream
        :return:tensor (num_voices, chorale_length, len(self.metadatas) + 1)
        """
        md = []
        if self.metadatas:
            for metadata in self.metadatas:
                sequence_metadata = torch.from_numpy(
                    metadata.evaluate(score, self.subdivision)).long().clone()
                square_metadata = sequence_metadata.repeat(self.num_voices, 1)
                md.append(
                    square_metadata[:, :, None]
                )
        chorale_length = int(score.duration.quarterLength * self.subdivision)

        # add voice indexes
        voice_id_metada = torch.from_numpy(np.arange(self.num_voices)).long().clone()
        square_metadata = torch.transpose(voice_id_metada.repeat(chorale_length, 1),
                                          0, 1)
        md.append(square_metadata[:, :, None])

        all_metadata = torch.cat(md, 2)
        return all_metadata

    def set_fermatas(self, metadata_tensor, fermata_tensor):
        """
        Impose fermatas for all chorales in a batch
        :param metadata_tensor: a (batch_size, sequences_size, num_metadatas)
            tensor
        :param fermata_tensor: a (sequences_size) binary tensor
        """
        if self.metadatas:
            for metadata_index, metadata in enumerate(self.metadatas):
                if isinstance(metadata, FermataMetadata):
                    # uses broadcasting
                    metadata_tensor[:, :, metadata_index] = fermata_tensor
                    break
        return metadata_tensor

    def add_fermata(self, metadata_tensor, time_index_start, time_index_stop):
        """
        Shorthand function to impose a fermata between two time indexes
        """
        fermata_tensor = torch.zeros(self.sequences_size)
        fermata_tensor[time_index_start:time_index_stop] = 1
        metadata_tensor = self.set_fermatas(metadata_tensor, fermata_tensor)
        return metadata_tensor

    def min_max_transposition(self, current_subseq_ranges):
        if current_subseq_ranges is None:
            # todo might be too restrictive
            # there is no note in one part
            transposition = (0, 0)  # min and max transpositions
        else:
            transpositions = [
                (min_pitch_corpus - min_pitch_current,
                 max_pitch_corpus - max_pitch_current)
                for ((min_pitch_corpus, max_pitch_corpus),
                     (min_pitch_current, max_pitch_current))
                in zip(self.voice_ranges, current_subseq_ranges)
            ]
            transpositions = [min_or_max_transposition
                              for min_or_max_transposition in zip(*transpositions)]
            transposition = [max(transpositions[0]),
                             min(transpositions[1])]
        return transposition

    def get_score_tensor(self, score, offsetStart, offsetEnd):
        chorale_tensor = []
        for part_id, part in enumerate(score.parts[:self.num_voices]):
            part_tensor = self.part_to_tensor(part, part_id,
                                              offsetStart=offsetStart,
                                              offsetEnd=offsetEnd)
            chorale_tensor.append(part_tensor)
        return torch.cat(chorale_tensor, 0)

    def part_to_tensor(self, part, part_id, offsetStart, offsetEnd):
        """
        :param part:
        :param part_id:
        :param offsetStart:
        :param offsetEnd:
        :return: torch IntTensor (1, length)
        """
        list_notes_and_rests = list(part.flat.getElementsByOffset(
            offsetStart=offsetStart,
            offsetEnd=offsetEnd,
            classList=[music21.note.Note,
                       music21.note.Rest]))
        list_note_strings_and_pitches = [(n.nameWithOctave, n.pitch.midi)
                                         for n in list_notes_and_rests
                                         if n.isNote]
        length = int((offsetEnd - offsetStart) * self.subdivision)  # in ticks

        # add entries to dictionaries if not present
        # should only be called by make_dataset when transposing
        note2index = self.note2index_dicts[part_id]
        index2note = self.index2note_dicts[part_id]
        voice_range = self.voice_ranges[part_id]
        min_pitch, max_pitch = voice_range
        for note_name, pitch in list_note_strings_and_pitches:
            # if out of range
            if pitch < min_pitch or pitch > max_pitch:
                note_name = OUT_OF_RANGE

            if note_name not in note2index:
                new_index = len(note2index)
                index2note.update({new_index: note_name})
                note2index.update({note_name: new_index})
                print('Warning: Entry ' + str(
                    {new_index: note_name}) + ' added to dictionaries')

        # construct sequence
        j = 0
        i = 0
        t = np.zeros((length, 2))
        is_articulated = True
        num_notes = len(list_notes_and_rests)
        while i < length:
            if j < num_notes - 1:
                if (list_notes_and_rests[j + 1].offset > i
                        / self.subdivision + offsetStart):
                    t[i, :] = [note2index[standard_name(list_notes_and_rests[j],
                                                        voice_range=voice_range)],
                               is_articulated]
                    i += 1
                    is_articulated = False
                else:
                    j += 1
                    is_articulated = True
            else:
                t[i, :] = [note2index[standard_name(list_notes_and_rests[j],
                                                    voice_range=voice_range)],
                           is_articulated]
                i += 1
                is_articulated = False
        seq = t[:, 0] * t[:, 1] + (1 - t[:, 1]) * note2index[SLUR_SYMBOL]
        tensor = torch.from_numpy(seq).long()[None, :]
        return tensor

    def voice_range_in_subsequence(self, chorale, offsetStart, offsetEnd):
        """
        returns None if no note present in one of the voices -> no transposition
        :param chorale:
        :param offsetStart:
        :param offsetEnd:
        :return:
        """
        voice_ranges = []
        for part in chorale.parts[:self.num_voices]:
            voice_range_part = self.voice_range_in_part(part,
                                                        offsetStart=offsetStart,
                                                        offsetEnd=offsetEnd)
            if voice_range_part is None:
                return None
            else:
                voice_ranges.append(voice_range_part)
        return voice_ranges

    def voice_range_in_part(self, part, offsetStart, offsetEnd):
        notes_in_subsequence = part.flat.getElementsByOffset(
            offsetStart,
            offsetEnd,
            includeEndBoundary=False,
            mustBeginInSpan=True,
            mustFinishInSpan=False,
            classList=[music21.note.Note,
                       music21.note.Rest])
        midi_pitches_part = [
            n.pitch.midi
            for n in notes_in_subsequence
            if n.isNote
        ]
        if len(midi_pitches_part) > 0:
            return min(midi_pitches_part), max(midi_pitches_part)
        else:
            return None

    def compute_index_dicts(self):
        print('Computing index dicts')
        self.index2note_dicts = [
            {} for _ in range(self.num_voices)
        ]
        self.note2index_dicts = [
            {} for _ in range(self.num_voices)
        ]

        # create and add additional symbols
        note_sets = [set() for _ in range(self.num_voices)]
        for note_set in note_sets:
            note_set.add(SLUR_SYMBOL)
            note_set.add(START_SYMBOL)
            note_set.add(END_SYMBOL)
            note_set.add(REST_SYMBOL)

        # get all notes: used for computing pitch ranges
        for chorale in tqdm(self.iterator_gen()):
            for part_id, part in enumerate(chorale.parts[:self.num_voices]):
                for n in part.flat.notesAndRests:
                    note_sets[part_id].add(standard_name(n))

        # create tables
        for note_set, index2note, note2index in zip(note_sets,
                                                    self.index2note_dicts,
                                                    self.note2index_dicts):
            for note_index, note in enumerate(note_set):
                index2note.update({note_index: note})
                note2index.update({note: note_index})

    def is_valid(self, chorale):
        # We only consider 4-part chorales
        if not len(chorale.parts) == 4:
            return False
        # todo contains chord
        return True

    def compute_voice_ranges(self):
        assert self.index2note_dicts is not None
        assert self.note2index_dicts is not None
        self.voice_ranges = []
        print('Computing voice ranges')
        for voice_index, note2index in tqdm(enumerate(self.note2index_dicts)):
            notes = [
                standard_note(note_string)
                for note_string in note2index
            ]
            midi_pitches = [
                n.pitch.midi
                for n in notes
                if n.isNote
            ]
            min_midi, max_midi = min(midi_pitches), max(midi_pitches)
            self.voice_ranges.append((min_midi, max_midi))

    def extract_score_tensor_with_padding(self, tensor_score, start_tick, end_tick):
        """
        :param tensor_chorale: (num_voices, length in ticks)
        :param start_tick:
        :param end_tick:
        :return: tensor_chorale[:, start_tick: end_tick]
        with padding if necessary
        i.e. if start_tick < 0 or end_tick > tensor_chorale length
        """
        assert start_tick < end_tick
        assert end_tick > 0
        length = tensor_score.size()[1]

        padded_chorale = []
        # todo add PAD_SYMBOL
        if start_tick < 0:
            start_symbols = np.array([note2index[START_SYMBOL]
                                      for note2index in self.note2index_dicts])
            start_symbols = torch.from_numpy(start_symbols).long().clone()
            start_symbols = start_symbols.repeat(-start_tick, 1).transpose(0, 1)
            padded_chorale.append(start_symbols)

        slice_start = start_tick if start_tick > 0 else 0
        slice_end = end_tick if end_tick < length else length

        padded_chorale.append(tensor_score[:, slice_start: slice_end])

        if end_tick > length:
            end_symbols = np.array([note2index[END_SYMBOL]
                                    for note2index in self.note2index_dicts])
            end_symbols = torch.from_numpy(end_symbols).long().clone()
            end_symbols = end_symbols.repeat(end_tick - length, 1).transpose(0, 1)
            padded_chorale.append(end_symbols)

        padded_chorale = torch.cat(padded_chorale, 1)
        return padded_chorale

    def extract_metadata_with_padding(self, tensor_metadata,
                                      start_tick, end_tick):
        """
        :param tensor_metadata: (num_voices, length, num_metadatas)
        last metadata is the voice_index
        :param start_tick:
        :param end_tick:
        :return:
        """
        assert start_tick < end_tick
        assert end_tick > 0
        num_voices, length, num_metadatas = tensor_metadata.size()
        padded_tensor_metadata = []

        if start_tick < 0:
            # TODO more subtle padding
            start_symbols = np.zeros((self.num_voices, -start_tick, num_metadatas))
            start_symbols = torch.from_numpy(start_symbols).long().clone()
            padded_tensor_metadata.append(start_symbols)

        slice_start = start_tick if start_tick > 0 else 0
        slice_end = end_tick if end_tick < length else length
        padded_tensor_metadata.append(tensor_metadata[:, slice_start: slice_end, :])

        if end_tick > length:
            end_symbols = np.zeros((self.num_voices, end_tick - length, num_metadatas))
            end_symbols = torch.from_numpy(end_symbols).long().clone()
            padded_tensor_metadata.append(end_symbols)

        padded_tensor_metadata = torch.cat(padded_tensor_metadata, 1)
        return padded_tensor_metadata

    def empty_score_tensor(self, score_length):
        start_symbols = np.array([note2index[START_SYMBOL]
                                  for note2index in self.note2index_dicts])
        start_symbols = torch.from_numpy(start_symbols).long().clone()
        start_symbols = start_symbols.repeat(score_length, 1).transpose(0, 1)
        return start_symbols

    def random_score_tensor(self, score_length):
        chorale_tensor = np.array(
            [np.random.randint(len(note2index),
                               size=score_length)
             for note2index in self.note2index_dicts])
        chorale_tensor = torch.from_numpy(chorale_tensor).long().clone()
        return chorale_tensor

    def tensor_to_score(self, tensor_score,
            fermata_tensor=None):
        """
        :param tensor_score: (num_voices, length)
        :return: music21 score object
        """
        slur_indexes = [note2index[SLUR_SYMBOL]
                        for note2index in self.note2index_dicts]

        score = music21.stream.Score()
        num_voices = tensor_score.size(0)
        name_parts = (num_voices == 4)
        part_names = ['Soprano', 'Alto', 'Tenor', 'Bass']

        for voice_index, (voice, index2note, slur_index) in enumerate(
                zip(tensor_score,
                    self.index2note_dicts,
                    slur_indexes)):
            add_fermata = False
            if name_parts:
                part = stream.Part(id=part_names[voice_index],
                partName=part_names[voice_index],
                partAbbreviation=part_names[voice_index],
                instrumentName=part_names[voice_index])
            else:
                part = stream.Part(id='part' + str(voice_index))
            dur = 0
            total_duration = 0
            f = music21.note.Rest()
            for note_index in [n.item() for n in voice]:
                # if it is a played note
                if not note_index == slur_indexes[voice_index]:
                    # add previous note
                    if dur > 0:
                        f.duration = music21.duration.Duration(dur / self.subdivision)

                        if add_fermata:
                            f.expressions.append(music21.expressions.Fermata())
                            add_fermata = False

                        part.append(f)

                    dur = 1
                    f = standard_note(index2note[note_index])
                    if fermata_tensor is not None and voice_index == 0:
                        if fermata_tensor[0, total_duration] == 1:
                            add_fermata = True
                        else:
                            add_fermata = False
                    total_duration += 1

                else:
                    dur += 1
                    total_duration += 1
            # add last note
            f.duration = music21.duration.Duration(dur / self.subdivision)
            if add_fermata:
                f.expressions.append(music21.expressions.Fermata())
                add_fermata = False

            part.append(f)
            score.insert(part)
        return score

# TODO should go in ChoraleDataset
# TODO all subsequences start on a beat
class ChoraleBeatsDataset(ChoraleDataset):
    def __repr__(self):
        return f'ChoraleBeatsDataset(' \
               f'{self.voice_ids},' \
               f'{self.name},' \
               f'{[metadata.name for metadata in self.metadatas]},' \
               f'{self.sequences_size},' \
               f'{self.subdivision})'

    def make_tensor_dataset(self):
        """
        Implementation of the make_tensor_dataset abstract base class
        """
        # todo check on chorale with Chord
        print('Making tensor dataset')
        self.compute_index_dicts()
        self.compute_voice_ranges()
        one_beat = 1.
        chorale_tensor_dataset = []
        metadata_tensor_dataset = []
        for chorale_id, chorale in tqdm(enumerate(self.iterator_gen())):

            # precompute all possible transpositions and corresponding metadatas
            chorale_transpositions = {}
            metadatas_transpositions = {}

            # main loop
            for offsetStart in np.arange(
                    chorale.flat.lowestOffset -
                    (self.sequences_size - one_beat),
                    chorale.flat.highestOffset,
                    one_beat):
                offsetEnd = offsetStart + self.sequences_size
                current_subseq_ranges = self.voice_range_in_subsequence(
                    chorale,
                    offsetStart=offsetStart,
                    offsetEnd=offsetEnd)

                transposition = self.min_max_transposition(current_subseq_ranges)
                min_transposition_subsequence, max_transposition_subsequence = transposition

                for semi_tone in range(min_transposition_subsequence,
                                       max_transposition_subsequence + 1):
                    start_tick = int(offsetStart * self.subdivision)
                    end_tick = int(offsetEnd * self.subdivision)

                    try:
                        # compute transpositions lazily
                        if semi_tone not in chorale_transpositions:
                            (chorale_tensor,
                             metadata_tensor) = self.transposed_score_and_metadata_tensors(
                                chorale,
                                semi_tone=semi_tone)
                            chorale_transpositions.update(
                                {semi_tone:
                                     chorale_tensor})
                            metadatas_transpositions.update(
                                {semi_tone:
                                     metadata_tensor})
                        else:
                            chorale_tensor = chorale_transpositions[semi_tone]
                            metadata_tensor = metadatas_transpositions[semi_tone]

                        local_chorale_tensor = self.extract_score_tensor_with_padding(
                            chorale_tensor,
                            start_tick, end_tick)
                        local_metadata_tensor = self.extract_metadata_with_padding(
                            metadata_tensor,
                            start_tick, end_tick)

                        # append and add batch dimension
                        # cast to int
                        chorale_tensor_dataset.append(
                            local_chorale_tensor[None, :, :].int())
                        metadata_tensor_dataset.append(
                            local_metadata_tensor[None, :, :, :].int())
                    except KeyError:
                        # some problems may occur with the key analyzer
                        print(f'KeyError with chorale {chorale_id}')

        chorale_tensor_dataset = torch.cat(chorale_tensor_dataset, 0)
        metadata_tensor_dataset = torch.cat(metadata_tensor_dataset, 0)

        dataset = TensorDataset(chorale_tensor_dataset,
                                metadata_tensor_dataset)

        print(f'Sizes: {chorale_tensor_dataset.size()}, {metadata_tensor_dataset.size()}')
        return dataset


text:
module Soolr
  TypeMismatch = Class.new(StandardError)

  autoload :Type, 'soolr/type'
  autoload :StringType, 'soolr/string_type'
  autoload :IntegerType, 'soolr/integer_type'
  autoload :FloatType, 'soolr/float_type'
  autoload :TimeType, 'soolr/time_type'
  autoload :BooleanType, 'soolr/boolean_type'

  autoload :Field, 'soolr/field'

  autoload :Dismax, 'soolr/dismax'

  autoload :AllOf, 'soolr/all_of'
  autoload :AnyOf, 'soolr/any_of'
  autoload :Between, 'soolr/between'
  autoload :Condition, 'soolr/condition'
  autoload :EqualTo, 'soolr/equal_to'
  autoload :Exists, 'soolr/exists'
  autoload :GreaterThan, 'soolr/greater_than'
  autoload :GreaterThanOrEqualTo, 'soolr/greater_than_or_equal_to'
  autoload :LessThan, 'soolr/less_than'
  autoload :LessThanOrEqualTo, 'soolr/less_than_or_equal_to'
  autoload :Prefix, 'soolr/prefix'
end


text:
<?php

namespace Pagekit\Database\ORM;

trait PropertyTrait
{
    /**
     * @var array
     */
    protected static $_properties = [];

    /**
     * Gets an object property.
     *
     * @param  string $name
     * @return mixed
     */
    public function __get($name)
    {
        if ($descriptor = static::getPropertyDescriptor($name)) {

            $get = $descriptor['get'];

            if (is_string($get)) {
                $get = [$this, $get];
            } elseif ($get instanceof \Closure) {
                $get = $get->bindTo($this, $this);
            }

            return call_user_func($get);

        } else {

            trigger_error(sprintf('Undefined property: %s::$%s', __CLASS__, $name), E_USER_NOTICE);
        }
    }

    /**
     * Sets an object property.
     *
     * @param string $name
     * @param mixed  $value
     */
    public function __set($name, $value)
    {
        if ($descriptor = static::getPropertyDescriptor($name)) {

            $set = $descriptor['set'];

            if (is_string($set)) {
                $set = [$this, $set];
            } elseif ($set instanceof \Closure) {
                $set = $set->bindTo($this, $this);
            }

            if (is_callable($set)) {
                call_user_func($set, $value);
            } elseif ($set === true) {
                $this->$name = $value;
            }

        } else {

            $this->$name = $value;
        }
    }

    /**
     * Clones the object properties.
     */
    public function __clone() {
        foreach (static::$_properties as $name => $value) {
            $this->$name = $this->__get($name);
        }
    }

    /**
     * Checks for an object property.
     *
     * @param  string $name
     * @return bool
     */
    public function __isset($name)
    {
        return isset(static::$_properties[$name]);
    }

    /**
     * Gets all object properties.
     *
     * @param  mixed $object
     * @return array
     */
    public static function getProperties($object)
    {
        $properties = get_object_vars($object);

        foreach (array_diff_key(static::$_properties, $properties) as $name => $value) {
            $properties[$name] = $object->$name;
        }

        if (isset(static::$properties)) {
            foreach (array_diff_key(static::$properties, $properties) as $name => $value) {
                $properties[$name] = $object->$name;
            }
        }

        return $properties;
    }

    /**
     * Defines an object property.
     *
     * @param  string                $name
     * @param  string|callable|array $get
     * @param  string|callable|bool  $set
     * @return array
     */
    public static function defineProperty($name, $get, $set = null)
    {
        $descriptor = is_array($get) ? $get : compact('get', 'set');

        if (isset($descriptor[0])) {
            $descriptor['get'] = $descriptor[0];
        }

        if (isset($descriptor[1])) {
            $descriptor['set'] = $descriptor[1];
        }

        unset($descriptor[0], $descriptor[1]);

        return static::$_properties[$name] = $descriptor;
    }

    /**
     * Gets an object property descriptor.
     *
     * @param  string $name
     * @return array
     */
    protected static function getPropertyDescriptor($name)
    {
        if (isset(static::$_properties[$name])) {
            return static::$_properties[$name];
        }

        if (isset(static::$properties, static::$properties[$name])) {
            return static::defineProperty($name, static::$properties[$name]);
        }
    }
}


text:
FROM kobotoolbox/kobocat_base:latest

# Install post-base-image `apt` additions from `apt_requirements.txt`, if modified.
COPY ./apt_requirements.txt "${KOBOCAT_TMP_DIR}/current_apt_requirements.txt"
RUN if ! diff "${KOBOCAT_TMP_DIR}/current_apt_requirements.txt" "${KOBOCAT_TMP_DIR}/base_apt_requirements.txt"; then \
        apt-get update && \
        apt-get install -y $(cat "${KOBOCAT_TMP_DIR}/current_apt_requirements.txt") && \
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    ; fi

# Install post-base-image `pip` additions/upgrades from `requirements/base.pip`, if modified.
COPY ./requirements/ "${KOBOCAT_TMP_DIR}/current_requirements/"
# FIXME: Replace this with the much simpler command `pip-sync ${KOBOCAT_TMP_DIR}/current_requirements/base.pip`.
RUN if ! diff "${KOBOCAT_TMP_DIR}/current_requirements/base.pip" "${KOBOCAT_TMP_DIR}/base_requirements/base.pip"; then \
        pip install --src "${PIP_EDITABLE_PACKAGES_DIR}/" -r "${KOBOCAT_TMP_DIR}/current_requirements/base.pip" \
    ; fi

# Uninstall `pip` packages installed in the base image from `requirements/uninstall.pip`, if present.
# FIXME: Replace this with the much simpler `pip-sync` command equivalent.
RUN if [ -e "${KOBOCAT_TMP_DIR}/current_requirements/uninstall.pip" ]; then \
        pip uninstall --yes -r "${KOBOCAT_TMP_DIR}/current_requirements/uninstall.pip" \
    ; fi

# Wipe out the base image's `kobocat` dir (**including migration files**) and copy over this directory in its current state.
RUN rm -rf "${KOBOCAT_SRC_DIR}"
COPY . "${KOBOCAT_SRC_DIR}"

# Prepare for execution.
RUN mkdir -p /etc/service/uwsgi && \
    cp "${KOBOCAT_SRC_DIR}/docker/run_uwsgi.bash" /etc/service/uwsgi/run && \
    mkdir -p /etc/service/celery && \
    cp "${KOBOCAT_SRC_DIR}/docker/run_celery.bash" /etc/service/celery/run && \
    cp "${KOBOCAT_SRC_DIR}/docker/init.bash" /etc/my_init.d/10_init_kobocat.bash && \
    cp "${KOBOCAT_SRC_DIR}/docker/sync_static.sh" /etc/my_init.d/11_sync_static.bash && \
    mkdir -p "${KOBOCAT_SRC_DIR}/emails/" && \
    chown -R wsgi "${KOBOCAT_SRC_DIR}/emails/"

RUN echo "db:*:*:kobo:kobo" > /root/.pgpass && \
    chmod 600 /root/.pgpass

# Using `/etc/profile.d/` as a repository for non-hard-coded environment variable overrides.
RUN echo 'source /etc/profile' >> /root/.bashrc

VOLUME ["${KOBOCAT_SRC_DIR}", "${KOBOCAT_SRC_DIR}/onadata/media", "/srv/src/kobocat-template"]

WORKDIR "${KOBOCAT_SRC_DIR}"

EXPOSE 8000


text:
'use strict';

angularEditApp.factory('setCommandParser', function() {

  return {
      parse:function(instruction) {
          function firstChar() {
              return instruction.charAt(0);
          }

          function lastChar() {
              return instruction.charAt(instruction.length - 1);
          }

          function isDoubleQuote(ch) {
              return ch === '"';
          }

          function isStartJSON(ch) {
              return ch === '{';
          }

          function isEndJSON(ch) {
              return ch === '}';
          }

          if (isDoubleQuote(firstChar()) && isDoubleQuote(lastChar())) {
              return {'html':instruction.substring(1, instruction.length-1).replace(/""/gi, '"')};
          }

          if (isStartJSON(firstChar()) && isEndJSON(lastChar())) {
              return angular.fromJson(instruction);
          }

          return {'html':instruction};
      }
  };
});


text:
package org.kie.dmn.feel.lang.types.impl;

import java.time.Period;
import java.util.Comparator;

public class InterceptNotComparableComparator implements Comparator<Object> {

    @Override
    public int compare(Object o1, Object o2) {
        Comparable c1 = coerceComparablePeriod(o1);
        Comparable c2 = coerceComparablePeriod(o2);
        return c1.compareTo(c2);
    }

    private Comparable<?> coerceComparablePeriod(Object o1) {
        Comparable<?> c1;
        try {
            c1 = (Comparable<?>) o1;
        } catch (ClassCastException e) {
            if (o1 instanceof Period) {
                c1 = new ComparablePeriod((Period) o1);
            } else {
                throw e;
            }
        }
        return c1;
    }

}


text:
<?hh //strict
namespace Hackdinium\Bot\Gadget;

use Hackdinium\Game\Board;
use Hackdinium\Game\Pos;
use Hackdinium\Input;
use Hackdinium\Tile;

<<__ConsistentConstruct>>
abstract class Guide implements Gadget {
    public function is(Pos $pos, (function(Tile\Tile): bool) $goal): bool {
        return $this->board->at($pos)->exists($goal);
    }

    public function isAir(Pos $p): bool {
        return $this->is($p, ($tile) ==> $tile->is(Tile\Air::class));
    }

    public function isAnyHero(Pos $p): bool {
        return $this->is($p, ($tile) ==> $tile->is(Tile\HeroTile::class));
    }

    public function isEnemy(int $id): (function(Pos): bool) {
        return (Pos $ePos) ==> {
            return $this->is($ePos, ($eTile) ==> {
                if (!is_a($eTile, Tile\HeroTile::class)) {
                    return false;
                }
                // UNSAFE
                return $id === $eTile->id;
            });
        };
    }

    public function isTavern(Pos $p): bool {
        return $this->is($p, ($tile) ==> $tile->is(Tile\Tavern::class));
    }

    public function isUnownedMine(int $id): (function(Pos): bool) {
        return (Pos $pos) ==> $this->is($pos, ($tile) ==> {
            if (!is_a($tile, Tile\MineTile::class)) {
                return false;
            }
            // UNSAFE
            return $id != $tile->heroId;
        });
    }

    public function posToInt(Pos $p): int {
        return $p->toInt($this->board->size);
    }

    public function validMoves(Pos $pos, Set<int> $visited = Set{}): ImmVector<Pos> {
        return $pos->neighbors()
            ->filter(($p) ==> $this->isAir($p))
            ->filter(($p2) ==> !$visited->contains($p2->toInt($this->board->size)))
        ;
    }

    protected function __construct(protected Board $board) {}
}


text:
EXTERN_C_BEGIN

bool DoAssert( const char * file, int line, const char * msg )
{
    LOG("ASSERT failed in file %s, line %d:\n(%s)", file, line, msg);
    DEBUG_BREAK();
    return  false;
}

// @TODO add an iPhone popup, so testers can see and report asserts

EXTERN_C_END


text:
""" Library for interfacing with Wink API for devices by Quirky, including:

    - "Eggminder" eggtray
    - "Nimbus" cloud_clock
    - "Pivot Power Genius" powerstrip
    - "Porkfolio" piggy_bank
    - "Spotter" sensor_pod

To get started, you will need:
    - Oauth tokens for the API
    - a Wink account

1) run 'login' and provide the requested information

2) run 'init' to instantiate the Wink class

"config_file_save" and "config_file_load" are convenience functions for
persisting auth data between sessions. However, since the auth data is just a
simple dictionary, you can easily replace this with whatever method is most
convenient for your application (e.g. convert to JSON).

"login" is a helper function that requests the necessary authentication
information from the user and saves it to a configuration file 'config.cfg'.

"init" is another helper function that reads from a config file, instantiates
the Wink class, and populates the devices from the Wink server.

"""

from .auth import auth, reauth, need_to_reauth

from . import persist

from .api import Wink

from .util import login, init


text:
//-----------------------------------------------------------------------
// <copyright file="OpenSslNativeWrapper.cs" company="Rare Crowds Inc">
// Copyright 2012-2013 Rare Crowds, Inc.
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// </copyright>
//-----------------------------------------------------------------------

using System;
using Utilities.Runtime.InteropServices;

namespace Utilities.Cryptography.OpenSsl.Native
{
    /// Base class for native wrappers of OpenSSL resources
    internal abstract class OpenSslNativeWrapper : NativeWrapper<IOpenSslInterop, OpenSslInterop32, OpenSslInterop64>
    {
        /// Initializes a new instance of the OpenSslNativeWrapper class
        /// <param name="handle">Handle to the wrapped resource</param>
        public OpenSslNativeWrapper(IntPtr handle)
            : base(handle)
        {
        }
    }
}


text:
<?php
namespace Isign\Exception;

use Symfony\Component\Validator\ConstraintViolationListInterface;

/**
 * Validator found violations while validating query field values
 */
class QueryValidator extends \InvalidArgumentException
{
    /** @var ConstraintViolationListInterface */
    private $violations;

    /**
     * @param string $message
     * @param ConstraintViolationListInterface $violations
     */
    public function __construct($message, ConstraintViolationListInterface $violations)
    {
        parent::__construct($message.': '.(string) $violations);

        $this->violations = $violations;
    }

    /**
     * Get validation violations
     * @return ConstraintViolationListInterface
     */
    public function getViolations()
    {
        return $this->violations;
    }
}


text:
<?php

namespace Roots\Sage\Setup;

use Roots\Sage\Assets;

/**
 * Theme setup
 */
function setup() {
  // Enable features from Soil when plugin is activated
  // https://roots.io/plugins/soil/
  add_theme_support('soil-clean-up');
  add_theme_support('soil-nav-walker');
  add_theme_support('soil-nice-search');
  add_theme_support('soil-jquery-cdn');
  add_theme_support('soil-relative-urls');

  // Make theme available for translation
  // Community translations can be found at https://github.com/roots/sage-translations
  load_theme_textdomain('sage', get_template_directory() . '/lang');

  // Enable plugins to manage the document title
  // http://codex.wordpress.org/Function_Reference/add_theme_support#Title_Tag
  add_theme_support('title-tag');

  // Register wp_nav_menu() menus
  // http://codex.wordpress.org/Function_Reference/register_nav_menus
  register_nav_menus([
    'primary_navigation' => __('Primary Navigation', 'sage'),
    'footer_menu' => __('Footer Menu', 'sage'),
    'footer_submenu' => __('Footer Submenu', 'sage'),
    'overlay_menu' => __('Overlay Menu', 'sage'),
  ]);

  // Enable post thumbnails
  // http://codex.wordpress.org/Post_Thumbnails
  // http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
  // http://codex.wordpress.org/Function_Reference/add_image_size
  add_theme_support('post-thumbnails');

  // Enable post formats
  // http://codex.wordpress.org/Post_Formats
  add_theme_support('post-formats', ['aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio']);

  // Enable HTML5 markup support
  // http://codex.wordpress.org/Function_Reference/add_theme_support#HTML5
  add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']);

  // Use main stylesheet for visual editor
  // To add custom styles edit /assets/styles/layouts/_tinymce.scss
  add_editor_style(Assets\asset_path('styles/main.css'));

  // add custom post types

}
add_action('after_setup_theme', __NAMESPACE__ . '\\setup');

/**
 * Register sidebars
 */
function widgets_init() {
  register_sidebar([
    'name'          => __('Primary', 'sage'),
    'id'            => 'sidebar-primary',
    'before_widget' => '
',
    'after_widget'  => '
',
    'before_title'  => '
',
    'after_title'   => '
'
  ]);

  register_sidebar([
    'name'          => __('Footer', 'sage'),
    'id'            => 'sidebar-footer',
    'before_widget' => '
',
    'after_widget'  => '
',
    'before_title'  => '
',
    'after_title'   => '
'
  ]);
}
add_action('widgets_init', __NAMESPACE__ . '\\widgets_init');

/**
 * Determine which pages should NOT display the sidebar
 */
function display_sidebar() {
  static $display;

  isset($display) || $display = !in_array(true, [
    // The sidebar will NOT be displayed if ANY of the following return true.
    // @link https://codex.wordpress.org/Conditional_Tags
    is_404(),
    is_front_page(),
    is_page_template('template-custom.php'),
  ]);

  return apply_filters('sage/display_sidebar', $display);
}

/**
 * Theme assets
 */
function assets() {
  wp_enqueue_style('sage/css', Assets\asset_path('styles/main.css'), false, null);

  if (is_single() && comments_open() && get_option('thread_comments')) {
    wp_enqueue_script('comment-reply');
  }

  wp_enqueue_script('sage/js', Assets\asset_path('scripts/main.js'), ['jquery'], null, true);
}
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 100);

// CUSTOM POST TYPES

function portfolio_register()
{
  global $avia_config;

  $labels = array(
    'name' => _x('Portfolio Items', 'post type general name','sage'),
    'singular_name' => _x('Portfolio Entry', 'post type singular name','sage'),
    'add_new' => _x('Add New', 'portfolio','sage'),
    'add_new_item' => __('Add New Portfolio Entry','sage'),
    'edit_item' => __('Edit Portfolio Entry','sage'),
    'new_item' => __('New Portfolio Entry','sage'),
    'view_item' => __('View Portfolio Entry','sage'),
    'search_items' => __('Search Portfolio Entries','sage'),
    'not_found' =>  __('No Portfolio Entries found','sage'),
    'not_found_in_trash' => __('No Portfolio Entries found in Trash','sage'),
    'parent_item_colon' => ''
  );

    $permalinks = get_option('avia_permalink_settings');
    if(!$permalinks) $permalinks = array();

    $permalinks['portfolio_permalink_base'] = empty($permalinks['portfolio_permalink_base']) ? __('portfolio-item', 'sage') : $permalinks['portfolio_permalink_base'];
    $permalinks['portfolio_entries_taxonomy_base'] = empty($permalinks['portfolio_entries_taxonomy_base']) ? __('portfolio_entries', 'sage') : $permalinks['portfolio_entries_taxonomy_base'];

  $args = array(
    'labels' => $labels,
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug'=>_x($permalinks['portfolio_permalink_base'],'URL slug','sage'), 'with_front'=>false),
    'query_var' => true,
    'show_in_nav_menus'=> true,
    'taxonomies' => array('post_tag'),
    'supports' => array('title','thumbnail','excerpt','editor','comments')
  );

  $args = apply_filters('avf_portfolio_cpt_args', $args);
  $avia_config['custom_post']['portfolio']['args'] = $args;

  register_post_type( 'portfolio' , $args );

  $tax_args = array(
    "hierarchical" => true,
    "label" => "Portfolio Categories",
    "singular_label" => "Portfolio Category",
    "rewrite" => array('slug'=>_x($permalinks['portfolio_entries_taxonomy_base'],'URL slug','sage'), 'with_front'=>true),
    "query_var" => true
  );

  $avia_config['custom_taxonomy']['portfolio']['portfolio_entries']['args'] = $tax_args;

  register_taxonomy("portfolio_entries", array("portfolio"), $tax_args);

  //deactivate the avia_flush_rewrites() function - not required because we rely on the default wordpress permalink settings
  // remove_action('wp_loaded', 'avia_flush_rewrites');
}
add_action('init', __NAMESPACE__ . '\\portfolio_register');