How to use the quantulum3.classes function in quantulum3

To help you get started, we’ve selected a few quantulum3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nielstron / quantulum3 / quantulum3 / parser.py View on Github external
def get_unit_from_dimensions(dimensions, text, lang="en_US"):
    """
    Reconcile a unit based on its dimensionality.
    """

    key = load.get_key_from_dimensions(dimensions)

    try:
        unit = load.units(lang).derived[key]
    except KeyError:
        _LOGGER.debug(u"\tCould not find unit for: %s", key)
        unit = cls.Unit(
            name=build_unit_name(dimensions, lang),
            dimensions=dimensions,
            entity=get_entity_from_dimensions(dimensions, text, lang),
        )

    # Carry on original composition
    unit.original_dimensions = dimensions
    return unit
github nielstron / quantulum3 / quantulum3 / load.py View on Github external
def load_unit(self, unit):
        try:
            assert unit["name"] not in self.names
        except AssertionError:  # pragma: no cover
            msg = "Two units with same name in units.json: %s" % unit["name"]
            raise Exception(msg)

        obj = c.Unit(
            name=unit["name"],
            surfaces=unit.get("surfaces", []),
            entity=entities().names[unit["entity"]],
            uri=unit["URI"],
            symbols=unit.get("symbols", []),
            dimensions=unit.get("dimensions", []),
            currency_code=unit.get("currency_code"),
            lang=self.lang,
        )

        self.names[unit["name"]] = obj

        for symbol in unit.get("symbols", []):
            self.symbols[symbol].add(obj)
            self.symbols_lower[symbol.lower()].add(obj)
            if unit["entity"] == "currency":
github nielstron / quantulum3 / scripts / extract_vere.py View on Github external
filename='glove.6B.100d.magnitude'):

    from pymagnitude import Magnitude

    v = Magnitude(os.path.join(TOPDIR, filename))
    training_set = list()
    units = set()
    for unit_list in classifier.ambiguous_units():
        for unit in unit_list[1]:
            units.add(unit)
    for unit in units:
        print('Processing {}...'.format(unit.name))

        name = unit.name
        surfaces = set(unit.name)
        if isinstance(unit, classes.Unit):
            surfaces.update(unit.surfaces)
            surfaces.update(unit.symbols)
        for surface in surfaces:
            neighbours = v.most_similar(
                v.query(surface), topn=topn, min_similarity=min_similarity)
            training_set.append({
                'unit':
                name,
                'text':
                ' '.join(neighbour[0] for neighbour in neighbours)
            })
    print('Done')

    with open(
            os.path.join(load.TOPDIR, 'similars.json'), 'w',
            encoding='utf8') as file:
github nielstron / quantulum3 / scripts / extract_vere.py View on Github external
):

    from pymagnitude import Magnitude

    v = Magnitude(os.path.join(TOPDIR, filename))
    training_set = list()
    units = set()
    for unit_list in classifier.ambiguous_units():
        for unit in unit_list[1]:
            units.add(unit)
    for unit in units:
        print("Processing {}...".format(unit.name))

        name = unit.name
        surfaces = set(unit.name)
        if isinstance(unit, classes.Unit):
            surfaces.update(unit.surfaces)
            surfaces.update(unit.symbols)
        for surface in surfaces:
            neighbours = v.most_similar(
                v.query(surface), topn=topn, min_similarity=min_similarity
            )
            training_set.append(
                {
                    "unit": name,
                    "text": " ".join(neighbour[0] for neighbour in neighbours),
                }
            )
    print("Done")

    with language.topdir(lang).joinpath("train/similars.json").open(
        "w", encoding="utf-8"