import requests


def fetch_output(input_prefix, input_value, output_prefix, enable_semantic_search=False):
    """Find APIs which can produce the output_prefix

    :arg str input_prefix: The prefix of the input, e.g. ncbigene, hgnc.symbol.
    :arg str output_prefix: The prefix of the output, e.g. ncbigene, hgnc.symbol.
    :arg str input_value: The actual value of the input
    :arg boolean enable_semantic_search:
    :returns:  list -- api endpoints which can produce the output prefix
    """
    if enable_semantic_search:
        response = requests.get('http://biothings.io/explorer/api/v2/semanticquery?input_prefix={{input}}&output_prefix={{output}}&input_value={{value}}'.
                                replace("{{input}}", input_prefix).replace("{{output}}", output_prefix).replace("{{value}}", input_value))
    else:
        response = requests.get('http://biothings.io/explorer/api/v2/directinput2output?input_prefix={{input}}&output_prefix={{output}}&input_value={{value}}'.
                                replace("{{input}}", input_prefix).replace("{{output}}", output_prefix).replace("{{value}}", input_value))
    if response.ok:
        doc = response.json()
        return doc['data'] if doc else []
    else:
        doc = response.json()
        if 'error message' in doc:
            print(doc['error message'])
        else:
            print("No results could be found for your query!")
        return []