余弦相似度

@param what 一个词
@param with 另一个词
@return 余弦相似度
544496
public float similarity(K what, K with)
    {
        Vector vectorWhat = storage.get(what);
        if (vectorWhat == null)
        {
            return -1f;
        }
        Vector vectorWith = storage.get(with);
        if (vectorWith == null)
        {
            return -1f;
        }
        return vectorWhat.cosineForUnitVector(vectorWith);
    }
529087
def _merge_wheres_to_has(self, has_query, relation):
        
        relation_query = relation.get_base_query()

        has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings())

        self._query.merge_bindings(has_query.get_query())
1027772
public static <T> T that(Object key, T what) {
        CACHE.put(key, what);
        return what;
    }
797477
public function withJoin($with, $joinType = '')
    {
        if (empty($with)) {
            return $this;
        }

        if (is_string($with)) {
            $with = explode(',', $with);
        }

        $first = true;

        /** @var Model $class */
        $class = $this->model;
        foreach ($with as $key => $relation) {
            $closure = null;
            $field   = true;

            if ($relation instanceof \Closure) {
                // 支持闭包查询过滤关联条件
                $closure  = $relation;
                $relation = $key;
            } elseif (is_array($relation)) {
                $field    = $relation;
                $relation = $key;
            } elseif (is_string($relation) && strpos($relation, '.')) {
                list($relation, $subRelation) = explode('.', $relation, 2);
            }

            /** @var Relation $model */
            $relation = Db::parseName($relation, 1, false);
            $model    = $class->$relation();

            if ($model instanceof OneToOne) {
                $model->eagerly($this, $relation, $field, $joinType, $closure, $first);
                $first = false;
            } else {
                // 不支持其它关联
                unset($with[$key]);
            }
        }

        $this->via();

        $this->options['with_join'] = $with;

        return $this;
    }
185488
function string_starts_with(str, what) {
		return (str.substr(0, what.length) === what) ? true : false;
	}
786402
public <T> T with( Closure<T> closure ) {
        return DefaultGroovyMethods.with( null, closure ) ;
    }
174691
private void XreadWithList(WithList withList) {
        // <with list element> ::= <query name>
        //                         [ <left paren> <with column list> <right paren> ]
        //                         AS <left paren> <query expression> <right paren>
        //                         [ <search or cycle clause> ]
        //
        boolean recursive = withList.isRecursive();
        for (boolean done = false; ! done; done = ! readIfThis(Tokens.COMMA)) {
            HsqlName queryName = readNewSchemaObjectName(SchemaObject.TABLE);
            queryName.setSchemaIfNull(session.getCurrentSchemaHsqlName());
            List<HsqlName> columnNames = parseColumnNames();
            readThis(Tokens.AS);
            readThis(Tokens.OPENBRACKET);
            // Read a query.  If it's recursive it has to be of the form:
            //    Q1 union all Q2.
            // In Q1 we can't use an order by or limit.  It's ok
            // to use group by, aggregates and having, though.  The
            // query name will be visible in Q2 but not in Q1.
            //
            // If this with statement is not recursive then anything goes,
            // but the query name will not be visible in the query.
            QueryExpression baseQueryExpression = null;
            QueryExpression recursionQueryExpression = null;
            // This is not really standard behavior.  This should
            // really be just reading a query expression.  However,
            // This short circuits a great deal of complexity, and
            // will serve for prototype purposes.
            if (recursive) {
                baseQueryExpression = XreadQueryPrimary();
            } else {
                baseQueryExpression = XreadQueryExpressionBodyAndSortAndSlice();
            }
            // We have to resolve this here because we need
            // to fetch the types and perhaps the column aliases.
            // But we can't define the table now, because it is
            // not visible in the base query expression.
            baseQueryExpression.resolve(session);
            //
            // Calculate the schema of the common table.
            //
            HsqlName[] colNames = null;
            if (columnNames != null) {
                colNames = columnNames.toArray(new HsqlName[columnNames.size()]);
            } else {
                String[] queryNames = baseQueryExpression.getColumnNames();
                colNames = new HsqlName[queryNames.length];
                for (int idx = 0; idx < queryNames.length; idx += 1) {
                    String queryColumnName = queryNames[idx];
                    colNames[idx] = database.nameManager.newHsqlName(queryColumnName,
                                                                     false,
                                                                     SchemaObject.COLUMN);
                }
            }
            Type[] colTypes = baseQueryExpression.getColumnTypes();
            String cmp = null;
            if (colNames.length > colTypes.length) {
                cmp = "many";
            }
            else if (colNames.length < colTypes.length) {
                cmp = "few";
            }
            if (cmp != null) {
                throw Error.error("Too " + cmp + " column names in common table expression " + queryName.name);
            }
            // Now, define it.
            Table newTable = session.defineLocalTable(queryName, colNames, colTypes);
            if (recursive) {
                readThis(Tokens.UNION);
                readThis(Tokens.ALL);
                recursionQueryExpression = XreadQueryExpressionBody();
            }
            readThis(Tokens.CLOSEBRACKET);
            WithExpression withExpression = new WithExpression();
            withExpression.setQueryName(queryName);
            withExpression.setBaseQuery(baseQueryExpression);
            withExpression.setRecursiveQuery(recursionQueryExpression);
            withExpression.setTable(newTable);
            withList.add(withExpression);
        }
    }
578387
def _split_what(what):
    
    return (
        frozenset(cls for cls in what if isclass(cls)),
        frozenset(cls for cls in what if isinstance(cls, Attribute)),
    )
321474
public function getBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->get();
    }
966437
public static int indexAny(String target, Integer fromIndex, List<String> indexWith) {
		if (isNull(target)) {
			return INDEX_NONE_EXISTS;
		}
		
		return matcher(target).indexs(fromIndex, checkNotNull(indexWith).toArray(new String[indexWith.size()]));
	}
151525
public String joinWith(String separator, Object... join) {
		return Joiner.on(separator).join(delegate.get(), EMPTY, join);
	}
359706
function (which) {
        var top = document.getElementsByClassName('RRFixTop'),
            right = document.getElementsByClassName('RRFixRight'),
            bottom = document.getElementsByClassName('RRFixBottom'),
            left = document.getElementsByClassName('RRFixLeft');
        if (top && top.length > 1) {
            console.error('fixes的元素同一方向只允许存在一个，top方向有多个fixes元素存在')
        }
        if (right && right.length > 1) {
            console.error('fixes的元素同一方向只允许存在一个，right方向有多个fixes元素存在')
        }
        if (bottom && bottom.length > 1) {
            console.error('fixes的元素同一方向只允许存在一个，bottom方向有多个fixes元素存在')
        }
        if (left && left.length > 1) {
            console.error('fixes的元素同一方向只允许存在一个，left方向有多个fixes元素存在')
        }
        var getF = function (node, i) {
            switch (i) {
                case 0:
                    node[0] = top[0] || false;
                    break;
                case 1:
                    node[1] = right[0] || false;
                    break;
                case 2:
                    node[2] = bottom[0] || false;
                    break;
                case 3:
                    node[3] = left[0] || false;
                    break;
                default:
                    throw new Error('方法：getFixes，参数：which，是个只能包含0-3之间整数的数组，或者为空')
            }
        };
        var node = [];
        if (which && which.length > 0) {
            for (var a = 0; a < which.length; a++) {
                getF(node, which[a])
            }
        } else {
            var _witch = [0, 1, 2, 3];
            for (var b = 0; b < _witch.length; b++) {
                getF(node, _witch[b])
            }
        }
        return node;
    }
202571
public SqlBuilder groupBy(final String what) {
    if (Strings.isNotEmpty(what)) groups.add(what);
    return this;
  }
633064
public boolean intersectsWith(Range other) {
        return !other.isEmpty() && !this.isEmpty() &&
                (this.contains(other.lower) || other.contains(this.lower)
                        || (other.upper > upper && other.lower < lower));
    }
169311
public static <T> Collection<T> eachWithIndex(Collection<T> self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
        return (Collection<T>) eachWithIndex((Iterable<T>) self, closure);
    }
513406
public JcString with(JcString with) {
		JcString ret = new JcString(with, this,
				new FunctionInstance(FUNCTION.String.REPLACE, 3));
		QueryRecorder.recordInvocationConditional(this, "with", ret, QueryRecorder.placeHolder(with));
		return ret;
	}
1276816
public static <T> Iterable<T> eachWithIndex(Iterable<T> self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
        eachWithIndex(self.iterator(), closure);
        return self;
    }