/*
(non-Javadoc)

@see
org.apache.lucene.search.spans.SpanQuery#createWeight(org.apache.lucene.
search.IndexSearcher, boolean)
12931
@Override
  public MtasSpanWeight createWeight(IndexSearcher searcher,
      boolean needsScores, float boost) throws IOException {
    return new SpanAllWeight(searcher, null, boost);
  }
420958
def create(index_name, body, force, verbose):
    """"""
    result = current_search_client.indices.create(
        index=index_name,
        body=json.load(body),
        ignore=[400] if force else None,
    )
    if verbose:
        click.echo(json.dumps(result))
275628
@Override
  public MtasSpanWeight createWeight(IndexSearcher searcher,
      boolean needsScores, float boost) throws IOException {
    if (q1 == null || q2 == null) {
      return null;
    } else {
      MtasSpanIntersectingQueryWeight w1 = new MtasSpanIntersectingQueryWeight(
          q1.createWeight(searcher, needsScores, boost));
      MtasSpanIntersectingQueryWeight w2 = new MtasSpanIntersectingQueryWeight(
          q2.createWeight(searcher, needsScores, boost));
      // subWeights
      List<MtasSpanIntersectingQueryWeight> subWeights = new ArrayList<>();
      subWeights.add(w1);
      subWeights.add(w2);
      // return
      return new SpanIntersectingWeight(w1, w2, searcher,
          needsScores ? getTermContexts(subWeights) : null, boost);
    }
  }
112119
public double weight() {
        double result = 0;
        Iterator edgeIterator = edgeSet().iterator();
        while (edgeIterator.hasNext()) {
            result += ((Edge) edgeIterator.next()).getWeight();
        }
        return result;
    }
244561
public WeightRandom<T> add(WeightObj<T> weightObj) {
		if(null != weightObj) {
			final double weight = weightObj.getWeight();
			if(weightObj.getWeight() > 0) {
				double lastWeight = (this.weightMap.size() == 0) ? 0 : this.weightMap.lastKey();
				this.weightMap.put(weight + lastWeight, weightObj.getObj());// 权重累加
			}
		}
		return this;
	}
869995
public static <K, V> EntryWeigher<K, V> asEntryWeigher(
      final Weigher<? super V> weigher) {
    return (weigher == singleton())
        ? Weighers.<K, V>entrySingleton()
        : new EntryWeigherView<K, V>(weigher);
  }
438489
@Override
  public IndexRequestBuilder createIndexRequest(Client client,
        String indexPrefix, String indexType, Event event) throws IOException {
    IndexRequestBuilder request = prepareIndex(client);
    String realIndexPrefix = BucketPath.escapeString(indexPrefix, event.getHeaders());
    String realIndexType = BucketPath.escapeString(indexType, event.getHeaders());

    TimestampedEvent timestampedEvent = new TimestampedEvent(event);
    long timestamp = timestampedEvent.getTimestamp();

    String indexName = getIndexName(realIndexPrefix, timestamp);
    prepareIndexRequest(request, indexName, realIndexType, timestampedEvent);
    return request;
  }
697504
private static boolean handleLegacyWeightInitFromJson(String json, Layer l, ObjectMapper mapper, JsonNode confs, int layerCount) {
        if ((l instanceof BaseLayer) && ((BaseLayer) l).getWeightInitFn() == null) {
            try {
                JsonNode jsonNode = mapper.readTree(json);
                if (confs == null) {
                    confs = jsonNode.get("confs");
                }
                if (confs instanceof ArrayNode) {
                    ArrayNode layerConfs = (ArrayNode) confs;
                    JsonNode outputLayerNNCNode = layerConfs.get(layerCount);
                    if (outputLayerNNCNode == null)
                        return false; //Should never happen...
                    JsonNode layerWrapperNode = outputLayerNNCNode.get("layer");

                    if (layerWrapperNode == null || layerWrapperNode.size() != 1) {
                        return true;
                    }

                    JsonNode layerNode = layerWrapperNode.elements().next();
                    JsonNode weightInit = layerNode.get("weightInit"); //Should only have 1 element: "dense", "output", etc
                    JsonNode distribution = layerNode.get("dist");

                    Distribution dist = null;
                    if(distribution != null) {
                        dist = mapper.treeToValue(distribution, Distribution.class);
                    }

                    if (weightInit != null) {
                        final IWeightInit wi = WeightInit.valueOf(weightInit.asText()).getWeightInitFunction(dist);
                        ((BaseLayer) l).setWeightInitFn(wi);
                    }
                }

            } catch (IOException e) {
                log.warn("Layer with null WeightInit detected: " + l.getLayerName() + ", could not parse JSON",
                        e);
            }
        }
        return true;

    }
599966
public Weight invertSign() {
        if (isInfinity) {
            if (posOrNeg) {
                return WeightFactory.NEG_INFINITY;
            } else {
                return WeightFactory.POS_INFINITY;
            }
        }
        return new Weight(-val);
    }
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);
    }
1282189
public void createMapping(String indexName, String mappingName, ArrayList<XContentBuilder> mappingSource) {
        IndicesExistsResponse existsResponse = this.client.admin().indices().prepareExists(indexName).execute()
                .actionGet();
        //If the index does not exists, it will be created without options
        if (!existsResponse.isExists()) {
            if (!createSingleIndex(indexName)) {
                throw new ElasticsearchException("Failed to create " + indexName
                        + " index.");
            }
        }
        BulkRequestBuilder bulkRequest = this.client.prepareBulk();
        for (int i = 0; i < mappingSource.size(); i++) {
            int aux = i + 1;

            IndexRequestBuilder res = this.client
                    .prepareIndex(indexName, mappingName, String.valueOf(aux)).setSource(mappingSource.get(i));
            bulkRequest.add(res);
        }
        bulkRequest.execute();
    }
1044234
public static <T> FactorComparator<T> create(final String factorName, final int weight,
      final Comparator<T> comparator) {

    if (null == factorName || factorName.length() == 0 || weight < 0 || null == comparator) {
      logger.error(
          "failed to create instance of FactorComparator, at least one of the input paramters are invalid");
      return null;
    }

    return new FactorComparator<>(factorName, weight, comparator);
  }
640709
@Override
	public DataRow create(Object rs, int index)
	{
		JavaBean.acceptVisitor(rs, this);
		
		DataRow dataRow = this.getDataRow();
		
		dataRow.setRowNum(index);
		
		this.clear();
		
		return dataRow;
	}
441627
def create_weight(self, weight, date=None):
        
        url = self._build_url('my', 'body', 'weight')
        data = {'weightInKilograms': weight}
        if date:
            if not date.is_aware():
                raise ValueError("provided date is not timezone aware")
            data.update(date=date.isoformat())
        headers = {'Content-Type': 'application/json; charset=utf8'}
        r = self.session.post(url, data=json.dumps(data), headers=headers)
        r.raise_for_status()
        return r
963259
public static CharTrie indexFulltext(Collection<String> documents, int maxLevels, int minWeight) {
    return create(documents, maxLevels, minWeight, false);
  }
281773
public int compareTo(CandidateField o) {
		if (o == null) {
			return 1;
		}
		
		int myWeight = this.weight == null ? 0 : this.weight.toInteger();
		int otherWeight = o.getWeight() == null ? 0 : o.getWeight().toInteger();
		
		if(myWeight > otherWeight) {
			return 1;
		}
		if(myWeight < otherWeight) {
			return -1;
		}
		return 0;
	}
544309
public final Cache2kBuilder<K, V> weigher(Weigher<K,V> v) {
    config().setWeigher(new CustomizationReferenceSupplier<Weigher>(v));
    return this;
  }