コード例 #1
0
def test_from_dict():
    test_data = get_custom_dict_configuration()
    mc = RowMappingConfiguration()
    mc.from_dict(test_data)
    assert mc.confidence_threshold == 0.1234
    assert mc.model_type == "mttest"
    assert mc.get_model_config() == {"model": "config", "value": 0.9}
コード例 #2
0
def test_from_json():
    tempdir = tempfile.TemporaryDirectory()
    tmpfilename = os.path.join(tempdir.name, "test.json")
    with open(tmpfilename, "w") as fd:
        json.dump(get_custom_dict_configuration(), fd)
    mc = RowMappingConfiguration()
    mc.from_json(tmpfilename)
    assert mc.confidence_threshold == 0.1234
    assert mc.model_type == "mttest"
    assert mc.get_model_config() == {"model": "config", "value": 0.9}
コード例 #3
0
    def get_model_from_config(cls, mapping_config: RowMappingConfiguration):
        """Instantiate a new row mapping model."""
        model_fingerprint = mapping_config.get_fingerprint()
        if model_fingerprint in cls._model_instances:
            return cls._model_instances[model_fingerprint]

        model_type = mapping_config.get_model_type()
        if model_type == "weighted_linear":
            cls._model_instances[model_fingerprint] = WeightedLinearModel(
                **mapping_config.get_model_config())
            return cls._model_instances[model_fingerprint]
        else:
            raise NotImplementedError(
                "%s not currently supported as a matching model type" %
                model_type)