/*
(non-Javadoc)

@see
mtas.search.spans.util.MtasSpanQuery#createWeight(org.apache.lucene.search.
IndexSearcher, boolean)
488867
@Override
  public MtasSpanWeight createWeight(IndexSearcher searcher,
      boolean needsScores, float boost) throws IOException {
    SpanWeight subWeight = subQuery.createWeight(searcher, needsScores, boost);
    return new MtasDisabledTwoPhaseIteratorWeight(subWeight, searcher,
        needsScores, boost);
  }
1150572
public synchronized double getWeight(PoolInfo poolInfo) {
    Double weight = (poolInfoToWeight == null) ? null :
        poolInfoToWeight.get(poolInfo);
    return weight == null ? 1.0 : weight;
  }
1079197
public int findClassIndex(HashMap<Integer, Integer> weightMap)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "findClassIndex");
    
    int classPos = 0;
    int randWeight = 0;
    // First of all determine total weight
    int totalWeight = 0;
    Iterator<Integer> iter = weightMap.values().iterator();
     while(iter.hasNext())
     {
      Integer weight = iter.next();
      totalWeight = totalWeight + weight.intValue();
    }
  
    // TotalWeight might be zero if a zero weighting has been applied to a class. In
    // that case we need to return a zero classPos
    if(totalWeight > 0)
    {
      // Generate a random number that is between zero and the total weight
      randWeight = Math.abs(rand.nextInt() % totalWeight);
      
      // Iterate over the weightMap again so that we can find a class index to use.
      // We search for the index that corresponds to the generated random value.
      //
      // So if we had 3 classes with weights 7, 2 and 1, then we'll have a total
      // weight of 10 and will generate a pseudo random number between 0 and 10. The
      // code will see if the random number...
      // * is less than 7, in which case it chooses index 1,
      // * is between 7 and 9, in which case it chooses index 2, 
      // * is between 9 and 10, in which case it chooses index 3.
      Iterator<Map.Entry<Integer, Integer>> iter2 = weightMap.entrySet().iterator();

      // An aggregate of the weight
      int aggregateWeight = 0;

      while(iter2.hasNext())
      {
        Map.Entry entry = (Map.Entry) iter2.next();
        Integer mappos = (Integer) entry.getKey();
        Integer weight = (Integer) entry.getValue();
      
        aggregateWeight = aggregateWeight + weight.intValue();
        
        // Move the classPos to the next value
        classPos = mappos.intValue(); 
        if(randWeight <= aggregateWeight)
          break;
      }
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "findClassIndex", classPos);
      
    return classPos;
  }
250230
public function createWeight(Zend_Search_Lucene_Interface $reader)
    {
        include_once 'Zend/Search/Lucene/Search/Weight/Term.php';
        $this->_weight = new Zend_Search_Lucene_Search_Weight_Term($this->_term, $this, $reader);
        return $this->_weight;
    }
274209
public static boolean recoverWeight(ProviderInfo providerInfo, int weight) {
        providerInfo.setStatus(ProviderStatus.RECOVERING);
        providerInfo.setWeight(weight);
        return true;
    }
288545
@Override
    public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException {
        this.weights = new HashMap<>();
        if (weights.containsKey(ALPHA))
            this.weights.put(PReLUParamInitializer.WEIGHT_KEY, weights.get(ALPHA));
        else
            throw new InvalidKerasConfigurationException("Parameter " + ALPHA + " does not exist in weights");
        if (weights.size() > 1) {
            Set<String> paramNames = weights.keySet();
            paramNames.remove(ALPHA);
            String unknownParamNames = paramNames.toString();
            log.warn("Attemping to set weights for unknown parameters: "
                    + unknownParamNames.substring(1, unknownParamNames.length() - 1));
        }
    }
622329
@Override
    public void set(int index, boolean value) {
        int i = Arrays.binarySearch(trueBits, index);
        // bit at index is set to true and shall be set to false
        if (i >= 0 && !value) {
            int[] tmp = new int[trueBits.length - 1];
            System.arraycopy(trueBits, 0, tmp, 0, i);
            System.arraycopy(trueBits, i + 1, tmp, i, trueBits.length - i - 1);
            trueBits = tmp;
        }
        // bit at index is set to false and shall be set to true
        else if (i < 0 && value) {
            int[] tmp = new int[trueBits.length + 1];
            System.arraycopy(trueBits, 0, tmp, 0, trueBits.length);
            tmp[tmp.length - 1] = index;
            trueBits = tmp;
            Arrays.sort(trueBits);
        }
    }
418867
public boolean createSingleIndex(String indexName) throws
            ElasticsearchException {
        CreateIndexRequest indexRequest = new CreateIndexRequest(indexName);
        CreateIndexResponse res = this.client.admin().indices().create(indexRequest).actionGet();
        return indexExists(indexName);
    }
735228
private void createIndex(String tableName, String indexName, String... fieldNames)
    {
        StringBuilder builder = new StringBuilder();
        builder.append("CREATE INDEX IF NOT EXISTS ");
        builder.append(indexName);
        builder.append(" ON ");
        builder.append(tableName);
        builder.append(Constants.OPEN_ROUND_BRACKET);
        for (String fieldName : fieldNames)
        {
            builder.append(fieldName);
            builder.append(Constants.COMMA);
        }
        builder.deleteCharAt(builder.length() - 1);
        builder.append(Constants.CLOSE_ROUND_BRACKET);
        StatementResult result = tableAPI.executeSync(builder.toString());
        if (!result.isSuccessful())
        {
            throw new SchemaGenerationException("Unable to CREATE Index with Index Name [" + indexName
                    + "] for table [" + tableName + "]");
        }
    }
799622
@Override
  public MtasSpanQuery rewrite(IndexReader reader) throws IOException {
    MtasSpanQuery newQ1 = (MtasSpanQuery) q1.rewrite(reader);
    MtasSpanQuery newQ2 = (MtasSpanQuery) q2.rewrite(reader);
    if (newQ1 == null || newQ1 instanceof MtasSpanMatchNoneQuery
        || newQ2 == null || newQ2 instanceof MtasSpanMatchNoneQuery) {
      return new MtasSpanMatchNoneQuery(field);
    } else if (!newQ1.equals(q1) || !newQ2.equals(q2)) {
      return new MtasSpanFullyAlignedWithQuery(newQ1, newQ2).rewrite(reader);
    } else if (newQ1.equals(newQ2)) {
      return newQ1;
    } else {
      boolean returnNone;
      returnNone = newQ1.getMaximumWidth() != null
          && newQ1.getMaximumWidth() == 0;
      returnNone |= newQ2.getMaximumWidth() != null
          && newQ2.getMaximumWidth() == 0;
      returnNone |= newQ1.getMinimumWidth() != null
          && newQ2.getMaximumWidth() != null
          && newQ1.getMinimumWidth() > newQ2.getMaximumWidth();
      returnNone |= newQ2.getMinimumWidth() != null
          && newQ1.getMaximumWidth() != null
          && newQ2.getMinimumWidth() > newQ1.getMaximumWidth();
      returnNone |= newQ2.getMinimumWidth() != null
          && newQ1.getMaximumWidth() != null
          && newQ2.getMinimumWidth() > newQ1.getMaximumWidth();
      if (returnNone) {
        return new MtasSpanMatchNoneQuery(this.getField());
      } else {
        return super.rewrite(reader);
      }
    }
  }
669332
public String toCreateIndexDDL(final String indexName, final String indexType) {
    final StringBuilder ddl = new StringBuilder("create index ");
    ddl.append(indexName).append(' ').append(indexType).append(' ');
    ddl.append("runtime ").append(serializer.getId());
    return ddl.toString();
  }
814278
@Override
  public MtasSpanWeight createWeight(IndexSearcher searcher,
      boolean needsScores, float boost) throws IOException {
    SpanWeight subWeight = clause.createWeight(searcher, false, boost);
    return new SpanUniquePositionWeight(subWeight, searcher,
        needsScores ? getTermContexts(subWeight) : null, boost);
  }
1252985
public function createWeight(Zend_Search_Lucene_Interface $reader)
    {
        include_once 'Zend/Search/Lucene/Search/Weight/MultiTerm.php';
        $this->_weight = new Zend_Search_Lucene_Search_Weight_MultiTerm($this, $reader);
        return $this->_weight;
    }
928507
public boolean create(String index) {
        CreateIndexRequestBuilder createIndexRequestBuilder =
                admin().indices().prepareCreate(index);
        return JMElasticsearchUtil.logRequestQueryAndReturn("create",
                createIndexRequestBuilder,
                createIndexRequestBuilder.execute())
                .isAcknowledged();
    }
263123
private boolean createIndex(String index, Map<String, Object> defaultSettings) {
        IndicesExistsResponse res = client.admin().indices().prepareExists(index).execute().actionGet();
        boolean created = false;
        if (!res.isExists()) {
            CreateIndexRequestBuilder req = client.admin().indices().prepareCreate(index);
            req.setSettings(defaultSettings);
            created = req.execute().actionGet().isAcknowledged();
            if (!created) {
                throw new RuntimeException("Could not create index [" + index + "]");
            }
        }

        return created;
    }
1194998
@When("^I create an elasticsearch index named '(.+?)'( removing existing index if exist)?$")
    public void createElasticsearchIndex(String index, String removeIndex) {
        if (removeIndex != null && commonspec.getElasticSearchClient().indexExists(index)) {
            commonspec.getElasticSearchClient().dropSingleIndex(index);
        }
        commonspec.getElasticSearchClient().createSingleIndex(index);
    }
292491
public static DenseTensor constant(int[] dimensions, int[] sizes, double weight) {
    DenseTensorBuilder builder = new DenseTensorBuilder(dimensions, sizes, weight);
    return builder.buildNoCopy();
  }