def selection(xs: List[str]) -> str:
    xs_ = strip(xs)
    return xs_[np.sum(editMatrix(xs_), axis=1).argmax()]
def editMatrix(xs: List[str]) -> Array:
    return np.array([[levenshtein(x, y) for y in xs] for x in strip(xs)])
def selection(xs: List[str]) -> str:
    xs_ = strip(xs)
    return label(xs_)
def condition(xs: List[str]) -> float:
    "average edit distance on cluster"
    xs_ = strip(xs)
    return (0.0  # levenshtein returns 1 if they are identical
            if len(xs_) <= 1 else np.mean(
                [levenshtein(*ys) for ys in itertools.combinations(xs_, 2)]))
def condition(xs: List[str]) -> float:
    "longest common ngram"
    xs_ = strip(xs)
    return (0.0 if ((len(xs_) <= 1) or (np.min([len(x) for x in xs_]) < 3))
            #TODO: if there is only one item then its vacuously 0?
            else scorer(xs_))
Esempio n. 6
0

# and that's it so far for generics, but we have a lot more list operations
# and they revolve around the structure of your data types

# mapmap: for when you have multiple layers of structure to map a map over
mapmap(lambda x: x**2, [[1,2], [2,3,4]])

# unpack: make a list of lists into a list
# unpackG: as unpack but return a generator expression
unpack([[1,2], [2,3,4]])
for i in unpackG([[1,2], [2,3,4]]):
    print(i)

# strip: remove values from a list which evaluate to False
strip(['hi', '', 0,  'pepeHands'])

# all of these functions really form the backbone of how woffle was built and
# find use across a large swathe of the code

# if you think woffle may be of use to you or if you would like to add to it
# then you need to think about the steps in the workflow, if you can break it
# down into the 4 tasks mentioned then please PR and get things added!

# There is already a train directory in the hierarchy but there is nothing in
# it yet, if this is something you are interested in please PR and get it
# added.

# That is all for today, the examples you have seen are available in the
# examples directory of the repo along with a much more in depth re-working of
# optimus, pull it and give it a go!
Esempio n. 7
0
def condition(xs: List[str]) -> float:
    "implement hypernym lookup"
    xs_ = strip(xs)
    return (0.0 if len(xs_) <= 1 else 1.0)
Esempio n. 8
0
def condition(xs: List[str]) -> float:
    "average number of common words across the cluster"
    xs_ = strip(xs)
    return (0.0 if (len(xs_) <= 1) or (wordLen(xs_) < 3) else scorer(xs_))
Esempio n. 9
0
def test_strip(xs):
    assert lst.strip(xs) == [x for x in xs if x]