def test_get_minimum_for_query1(self):
     keywords_dont_matter_here = ['']
     query = KeywordCoordinate(0, 0, keywords_dont_matter_here)
     kwc1 = KeywordCoordinate(1, 1, keywords_dont_matter_here)
     kwc2 = KeywordCoordinate(2, 2, keywords_dont_matter_here)
     kwc3 = KeywordCoordinate(3, 3, keywords_dont_matter_here)
     kwc4 = KeywordCoordinate(4, 4, keywords_dont_matter_here)
     kwc5 = KeywordCoordinate(5, 5, keywords_dont_matter_here)
     dataset: dataset_type = [kwc1, kwc2, kwc3, kwc4, kwc5]
     cf = CostFunction(euclidean_distance, separated_cosine_similarity, 0.3,
                       0.3, 0.4)
     result = cf.get_minimum_for_query(query, dataset)
     self.assertAlmostEqual(result, 1.41, delta=0.01)
 def test_get_minimum_for_query4(self):
     keywords_dont_matter_here = ['']
     query = KeywordCoordinate(0, 0, keywords_dont_matter_here)
     kwc1 = KeywordCoordinate(8, 8, keywords_dont_matter_here)
     kwc2 = KeywordCoordinate(9, 9, keywords_dont_matter_here)
     kwc3 = KeywordCoordinate(13, 13, keywords_dont_matter_here)
     kwc4 = KeywordCoordinate(24, 24, keywords_dont_matter_here)
     kwc5 = KeywordCoordinate(35, 35, keywords_dont_matter_here)
     dataset: dataset_type = [kwc1, kwc2, kwc3, kwc4, kwc5]
     cf = CostFunction(manhattan_distance, separated_cosine_similarity, 0.3,
                       0.3, 0.4)
     result = cf.get_minimum_for_query(query, dataset)
     self.assertAlmostEqual(result, 16.0, delta=0.01)
Beispiel #3
0
def get_min_query_dataset_distances(costfunction: CostFunction,
                                    query: KeywordCoordinate, subsets):
    """
    This function gets executed inside every minimum query-dataset distance process.
    :param costfunction: The CostFunction
    :param query: The Query
    :param subsets: The subsets for the process
    :return: A list with tuples of the costs and their corresponding subset
    """
    results = []
    for subset in subsets:
        current_cost = costfunction.get_minimum_for_query(query, subset)
        results.append((current_cost, subset))
    return results