Skip to content

API timeout for large tables #7

@TheRazorace

Description

@TheRazorace

Hi! When I try to use the service for tables typically larger than 100 rows and 5 columns, the API fails to return results even after retrying loops. Is there any solution to that?

My code:

def mtab(file):

    print("Querying the MTab API to retrieve semantic table annotations...")
    api_url = "https://mtab.kgraph.jp/api/v1/mtab"

    # Open the file in binary mode
    with open(file, 'rb') as table:
        # Create a dictionary for the file parameter to send
        files = {'file': table}
        
        # Make the POST request to the API
        retry_count = 10
        backoff_factor = 2
        retrieve_success = False
        for attempt in range(retry_count):
            try:
                response = requests.post(api_url, files=files, verify=False)
                response.raise_for_status()
                retrieve_success = True
                break
            except requests.exceptions.RequestException as e:
                time.sleep(backoff_factor**attempt)
                retrieve_success = False
        
    # Check the status of the request
    if retrieve_success == True:
        # Parse the JSON response (assuming the API returns JSON)
        annotations = response.json()
        #print(annotations)
        if annotations["tables"][0]["status"] == "Error":
            #print("Error")
            (subject_column, primary_annotations, secondary_annotations, new_cea, new_cpa, new_cta, cqa) = mtab(file)
        else:
            #print("Mtab retrieved", annotations)
            (subject_column, primary_annotations, secondary_annotations, new_cea, new_cpa, new_cta, cqa) = standard_annotation_formatter(annotations)
    else:
        sys.exit(f"Failed to annotate. Status code: {response.status_code}, Response: {response.text}")

    return (subject_column, primary_annotations, secondary_annotations, new_cea, new_cpa, new_cta, cqa)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions