示例#1
0
 def test_get_maximum_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_maximum_for_query(query, dataset)
     self.assertAlmostEqual(result, 7.07, delta=0.01)
示例#2
0
 def test_get_maximum_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_maximum_for_query(query, dataset)
     self.assertAlmostEqual(result, 70.0, delta=0.01)
示例#3
0
def get_max_query_dataset_distances(costfunction: CostFunction,
                                    query: KeywordCoordinate, subsets):
    """
    This function gets executed inside every maximum 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_maximum_for_query(query, subset)
        results.append((current_cost, subset))
    return results