Пример #1
0
    def board_dimensions(self) -> Dimensions:
        xs = {c.x for c in self.board}
        ys = {c.y for c in self.board}

        min_x, max_x = juxt(min, max)(xs)
        min_y, max_y = juxt(min, max)(ys)
        return Dimensions(Coord(min_x, min_y), Coord(max_x, max_y))
Пример #2
0
def get_text_from_xml_file(filename):
    """
    This is setup for extracting text from the Stackoverflow posts data dump
    that is stored in a xml file.

    Returns a stream of Post bodies (just the text).
    """

    @tlz.curry
    def _get_xml_attr(key, xml_element):
        return xml_element.attributes[key].value

    @tlz.curry
    def _try_to_get_xml_attr(key, xml_element, default=''):
        try:
            return _get_xml_attr(key, xml_element)
        except(KeyError):
            return default

    return tlz.pipe(filename,
                    minidom.parse,  # Not pure
                    lambda layer0: layer0.getElementsByTagName("posts")[0],
                    lambda layer1: layer1.getElementsByTagName("row"),
                    c_map(tlz.juxt(_try_to_get_xml_attr("Title"),
                                   _get_xml_attr("Body"))),
                    c_map(lambda titleAndBody: '\n\n\n'.join(titleAndBody)))
Пример #3
0
 def hist(self, *funcs):
     alphabet = self.alphabet
     length = self.length
     seqs = ("".join(p) for p in itertools.product(*[alphabet] * length))
     num = len(alphabet) ** length
     f = juxt(*funcs)
     counts = Counter(f(seq) for seq in seqs)
     return {k: v / num for (k, v) in counts.items()}
Пример #4
0
def read(specs, filepath):
    """Reads values from file specified by locations

    Args:
        filepath (str): Full path of raster file to read
        specs (sequence): dicts containing y_index, x_index, y, x

    Returns:
        sequence: dicts with 'value' key populated
    """

    ds = None
    try:
        ds = gdal.Open(filepath)
        val = partial(value, memarray=ds.GetRasterBand(1).GetVirtualMemArray())
        reader = juxt([identity, lambda spec: dict(value=val(spec=spec))])
        for spec in specs:
            yield (merge(reader(spec)))
    finally:
        ds = None
Пример #5
0
 def hash_values(self, key):
     """Return the hashes for the given key."""
     return juxt(self.hash_functions)(key)