def get_inline_xpath_flight_number(flight_number_paths, useful_path, segment_path, root, namespace): flight_number_verified_paths = set() for path in flight_number_paths: if verify_flight_number(path, root, namespace): flight_number_verified_paths.add(path) if len(flight_number_verified_paths) == 0: for path in useful_path: if verify_flight_number(path, root, namespace): flight_number_verified_paths.add(path) possible_xpath = [] for flight_number_path in flight_number_verified_paths: if is_include_carrier(flight_number_path, root, namespace): possible_xpath.append(generate_inclusion_carrier_flight_number_xpath(flight_number_path, segment_path)) else: flight_carrier_paths = set() for path in flight_number_paths: if path in flight_number_verified_paths: continue if verify_flight_carrier(path, root, namespace): flight_carrier_paths.add(path) if len(flight_carrier_paths) == 0: for path in useful_path: if path in flight_number_verified_paths: continue if verify_flight_carrier(path, root, namespace): flight_carrier_paths.add(path) for flight_carrier_path in flight_carrier_paths: possible_xpath.append((inline_xpath_decoration(flight_carrier_path), inline_xpath_decoration(flight_number_path))) return possible_xpath
def generate_inclusion_carrier_flight_number_xpath(flight_number_path, segment_path): return inline_xpath_decoration(flight_number_path.replace(segment_path, '.'))+"[0:2]",\ inline_xpath_decoration(flight_number_path.replace(segment_path, '.'))
def get_inline_xpath_for_datetime(xpath_from_code, xpath_to_code, dates, times, segment_path): if len(dates)!=2: return None, None xpath_dates = [] xpath_times = [] for date in dates: xpath_dates.append(date.replace(segment_path, '.')) if times is None: if len(longestSubstringFinder(xpath_from_code, xpath_dates[0])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_dates[1]))>0: return inline_xpath_decoration(xpath_dates[0]), inline_xpath_decoration(xpath_dates[1]) if len(longestSubstringFinder(xpath_from_code, xpath_dates[1])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_dates[0]))>0: return inline_xpath_decoration(xpath_dates[1]), inline_xpath_decoration(xpath_dates[0]) else: if len(times)!=2: return None, None for time in times: xpath_times.append(time.replace(segment_path, '.')) xpath_times = list(xpath_times) date_from_str = '' time_from_str = '' date_to_str = '' time_to_str = '' if len(longestSubstringFinder(xpath_from_code, xpath_dates[0])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_dates[1]))>0: date_from_str, date_to_str = inline_xpath_decoration(xpath_dates[0]), inline_xpath_decoration(xpath_dates[1]) if len(longestSubstringFinder(xpath_from_code, xpath_dates[1])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_dates[0]))>0: date_from_str, date_to_str = inline_xpath_decoration(xpath_dates[1]), inline_xpath_decoration(xpath_dates[0]) if len(longestSubstringFinder(xpath_from_code, xpath_times[0])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_times[1]))>0: time_from_str, time_to_str = inline_xpath_decoration(xpath_times[0]), inline_xpath_decoration(xpath_times[1]) if len(longestSubstringFinder(xpath_from_code, xpath_times[1])) > 0 and \ len(longestSubstringFinder(xpath_to_code, xpath_times[0]))>0: time_from_str, time_to_str = inline_xpath_decoration(xpath_times[1]), inline_xpath_decoration(xpath_times[0]) if time_from_str == '' or time_to_str =='' or date_from_str=='' or date_to_str=='': return None, None else: return date_from_str+'+'+time_from_str, date_to_str+'+'+time_to_str