def checkRealtion7FinishedBy(epsilon, maxGap):

    rh = RelationHandler(RelationHandler.RELATION_ALLEN_7)

    logger.debug('Testing FINISH_BY in 7 relations, epsilon: ' + str(epsilon) +
                 ', max gap: ' + str(maxGap))

    sti1 = SymbolicTimeInterval(1, 5, 'A', 345)
    sti2 = SymbolicTimeInterval(3, 5, 'B', 567)

    checkRelation(rh, sti1, sti2, epsilon, maxGap,
                  AllenSevenRelationEngine.FINISHBY)
def checkRealtion7Overlaps(epsilon, maxGap):

    rh = RelationHandler(RelationHandler.RELATION_ALLEN_7)

    logger.debug('Testing OVERLAPS in 7 relations, epsilon: ' + str(epsilon) +
                 ', max gap: ' + str(maxGap))

    sti1 = SymbolicTimeInterval(1, 3, 'A', 345)
    sti2 = SymbolicTimeInterval(2, 6, 'B', 567)

    checkRelation(rh, sti1, sti2, epsilon, maxGap,
                  AllenSevenRelationEngine.OVERLAP)
def checkRealtion7Contains(epsilon, maxGap):

    rh = RelationHandler(RelationHandler.RELATION_ALLEN_7)

    logger.debug('Testing CONTAINS in 7 relations, epsilon: ' + str(epsilon) +
                 ', max gap: ' + str(maxGap))

    sti1 = SymbolicTimeInterval(1, 5, 'A', 345)
    sti2 = SymbolicTimeInterval(2, 4, 'B', 567)

    checkRelation(rh, sti1, sti2, epsilon, maxGap,
                  AllenSevenRelationEngine.CONTAIN)
def checkNotInGap(epsilon, maxGap):
    rh = RelationHandler(RelationHandler.RELATION_ALLEN_7)

    logger.debug('Testing Not in gap, epsilon: ' + str(epsilon) +
                 ', max gap: ' + str(maxGap))

    sti1 = SymbolicTimeInterval(1, 3, 'A', 345)

    sti2 = SymbolicTimeInterval(3 + maxGap + 1, 3 + maxGap + 8, 'B', 567)

    checkRelation(rh, sti1, sti2, epsilon, maxGap,
                  AllenSevenRelationEngine.NOT_DEFINED)
Exemplo n.º 5
0
def test_is_pair_exist():
    suportVec = 0.5
    logger.debug('loading file for karma with support vec value: ' +
                 str(suportVec))
    karma = Karma(suportVec)
    karma.fit('../KarmaLego_TestsData/single_entity_2_bins.csv')
    sti_a = SymbolicTimeInterval(0, 2, 1)
    sti_b = SymbolicTimeInterval(4, 6, 2)
    if karma.is_pair_exist(0, 1, sti_a, sti_b):
        logger.info('[PASSED] pair exist ' + str(sti_a) + ' ' + str(sti_b))
    else:
        logger.info('[FAILED] pair dont exist ' + str(sti_a) + ' ' +
                    str(sti_b))
Exemplo n.º 6
0
 def parse_file_into_symbolic_time_intervals(self,
                                             file_path,
                                             num_comma,
                                             start_index=0):
     """
     parse the file to a map of entities to detect with their symbolic time intervals
     sort the symbolic time intervals in a lexicographic order
     :param file_path: string, the path to the symbolic time intervals file
     :param start_index: int, the row fro mwhich to parse the symbolic time intervals
     :return: nothing
     """
     self._entities_map_to_detect = {}
     with open(file_path) as f:
         lines = f.readlines()[start_index:]
     for i in range(0, len(lines), 2):
         entity_id = int(lines[i].replace(";", ""))
         sym_ti_ls = lines[i + 1].split(";")
         for sym_ti in sym_ti_ls[:-1]:
             parts = sym_ti.split(",")
             st = int(parts[0])
             et = int(parts[1])
             symbol = parts[num_comma]
             sym_ti_obj = SymbolicTimeInterval(start_time=st,
                                               end_time=et,
                                               symbol=symbol)
             if entity_id not in self._entities_map_to_detect:
                 self._entities_map_to_detect[entity_id] = [sym_ti_obj]
             else:
                 self._entities_map_to_detect[entity_id].append(sym_ti_obj)
Exemplo n.º 7
0
 def parse_file_into_symbolic_time_intervals_parts(self, file_path,
                                                   start_index, symbol_type,
                                                   num_comma):
     """
     parse the file to a map of entities with their symbolic time intervals
     remove relevant symbols
     sort the symbolic time intervals in a lexicographic order
     :param file_path: string, the path to the symbolic time intervals file
     :param start_index: int, the row from which to parse the symbolic time intervals
     :return: nothing
     """
     symbols_map = {}
     with open(file_path) as f:
         lines = f.readlines()[start_index:]
     for i in range(0, len(lines), 2):
         entity_symbols = []
         entity_id = int(lines[i].replace(";", ""))
         sym_ti_ls = lines[i + 1].split(";")
         for sym_ti in sym_ti_ls[:-1]:
             parts = sym_ti.split(",")
             st = int(parts[0])
             et = int(parts[1])
             symbol = parts[num_comma]
             sym_ti_obj = SymbolicTimeInterval(start_time=st,
                                               end_time=et,
                                               symbol=symbol)
             if entity_id not in self._entities_map:
                 self._entities_map[entity_id] = [sym_ti_obj]
             else:
                 self._entities_map[entity_id].append(sym_ti_obj)
             if symbol not in symbols_map:
                 symbols_map[symbol] = 1
                 entity_symbols.append(symbol)
             elif symbol not in entity_symbols:
                 symbols_map[symbol] = symbols_map[symbol] + 1
                 entity_symbols.append(symbol)
     num_of_entitites = len(self._entities_map)
     unrelevent_symbols = [
         sym for sym in symbols_map
         if symbols_map[sym] < (num_of_entitites * self._min_ver_support)
     ]
     self._frequent_symbols = [
         sym for sym in symbols_map if sym not in unrelevent_symbols
     ]
     if symbol_type == 'int':
         for entity_id in self._entities_map:
             self._entities_map[entity_id] = sorted([
                 sym_ti for sym_ti in self._entities_map[entity_id]
                 if sym_ti._symbol not in unrelevent_symbols
             ],
                                                    key=self.sort_str_int)
     else:
         for entity_id in self._entities_map:
             self._entities_map[entity_id] = sorted(
                 [
                     sym_ti for sym_ti in self._entities_map[entity_id]
                     if sym_ti._symbol not in unrelevent_symbols
                 ],
                 key=operator.attrgetter('_start_time', '_end_time',
                                         '_symbol'))
Exemplo n.º 8
0
def test_get_pairs():
    suportVec = 0.5
    logger.debug('loading file for karma with support vec value: ' +
                 str(suportVec))
    karma = Karma(suportVec)
    karma.fit('../KarmaLego_TestsData/single_entity_2_bins.csv')
    sti = SymbolicTimeInterval(0, 2, 1)
    pairs = karma.get_pairs(1, 2, 0, 1, sti)

    if 2 == len(pairs):
        logger.info('[PASSED] pairs fetched ' + str(pairs))
    else:
        logger.info('[FAILED] pairs not fetched - ' + str(pairs))