Exemplo n.º 1
0
def handle_keywords(text, split=True):
    """
    Automatic handling of Keywords from a text.
    It runs the sanitize function for keywords on every
    keyword.

    If `split` it's True, it splits the text by white spaces.

    Returns an :class:`quepy.expression.Expression` that represents
    the fact of having the keywords extracted from text.
    """

    assert_valid_encoding(text)

    from quepy.semantics import HasKeyword

    if split:
        keywords = [HasKeyword.sanitize(x) for x in text.split()]
    else:
        keywords = (HasKeyword.sanitize(text), )

    if not keywords:
        raise ValueError(u"Couldn't extract any keyword from '%s'" % text)

    expr = None
    for keyword in keywords:
        if expr is not None:
            expr += HasKeyword(keyword)
        else:
            expr = HasKeyword(keyword)

    return expr
Exemplo n.º 2
0
def handle_keywords(text, split=True):
    """
    Automatic handling of Keywords from a text.
    It runs the sanitize function for keywords on every
    keyword.

    If `split` it's True, it splits the text by white spaces.

    Returns an :class:`quepy.expression.Expression` that represents
    the fact of having the keywords extracted from text.
    """

    assert_valid_encoding(text)

    from quepy.semantics import HasKeyword

    if split:
        keywords = [HasKeyword.sanitize(x) for x in text.split()]
    else:
        keywords = (HasKeyword.sanitize(text),)

    if not keywords:
        raise ValueError(u"Couldn't extract any keyword from '%s'" % text)

    expr = None
    for keyword in keywords:
        if expr is not None:
            expr += HasKeyword(keyword)
        else:
            expr = HasKeyword(keyword)

    return expr