(request, context)
Execute functions for the spaCy natural language processing library.
        :param request: an iterable sequence of RowData
        :param context:
        :return: Refer to comments below as the response depends on the function called
Execute functions for the spaCy natural language processing library.
        :param request: an iterable sequence of RowData
        :param context:
        :return: Refer to comments below as the response depends on the function called
Execute functions for the spaCy natural language processing library . : param request : an iterable sequence of RowData : param context : : return : Refer to comments below as the response depends on the function called
def _spacy(request, context):
        """
        Execute functions for the spaCy natural language processing library.
        :param request: an iterable sequence of RowData
        :param context:
        :return: Refer to comments below as the response depends on the function called
        """
        # Get a list from the generator object so that it can be iterated over multiple times
        request_list = [request_rows for request_rows in request]
        
        # Get the function id from the header to determine the variant being called
        function = ExtensionService._get_function_id(context)
        
        # Create an instance of the SpaCyForQlik class
        model = SpaCyForQlik(request_list, context)
        
        # Call the function based on the mapping in functions.json
        # The if conditions are grouped based on similar output structure
        if function in (30, 31):    
            if function == 30:
                # Get entities from the default model
                response = model.get_entities()
            elif function == 31:
                # Get entities from a named model
                response = model.get_entities(default=False)
            
            # return six columns: key, entity, start, end, type, description
            dtypes = ["str", "str", "num", "num", "str", "str"]
        
        elif function == 32:
            # Retrain a model by supplying texts and labeled entities
            response = model.retrain()

            # return four columns: model_name, subset, metric, value
            dtypes = ["str", "str", "str", "num"]

        # Get the response as SSE.Rows
        response_rows = utils.get_response_rows(response.values.tolist(), dtypes) 

        # Get the number of rows in the request
        num_request_bundles = len(request_list)

        # Get the number of rows in the response
        num_rows = len(response_rows) 

        # Calculate the number of rows to send per bundle
        if num_rows >= num_request_bundles:
            rows_per_bundle = len(response_rows)//len(request_list)
        else:
            rows_per_bundle = num_rows

        # Stream response as BundledRows
        for i in range(0, len(response_rows), rows_per_bundle):
            # Yield Row data as Bundled rows
            yield SSE.BundledRows(rows=response_rows[i : i + rows_per_bundle])
def _spacy ( request , context ) : # Get a list from the generator object so that it can be iterated over multiple times request_list = [ request_rows for request_rows in request ] # Get the function id from the header to determine the variant being called function = ExtensionService . _get_function_id ( context ) # Create an instance of the SpaCyForQlik class model = SpaCyForQlik ( request_list , context ) # Call the function based on the mapping in functions.json # The if conditions are grouped based on similar output structure if function in ( 30 , 31 ) : if function == 30 : # Get entities from the default model response = model . get_entities ( ) elif function == 31 : # Get entities from a named model response = model . get_entities ( default = False ) # return six columns: key, entity, start, end, type, description dtypes = [ "str" , "str" , "num" , "num" , "str" , "str" ] elif function == 32 : # Retrain a model by supplying texts and labeled entities response = model . retrain ( ) # return four columns: model_name, subset, metric, value dtypes = [ "str" , "str" , "str" , "num" ] # Get the response as SSE.Rows response_rows = utils . get_response_rows ( response . values . tolist ( ) , dtypes ) # Get the number of rows in the request num_request_bundles = len ( request_list ) # Get the number of rows in the response num_rows = len ( response_rows ) # Calculate the number of rows to send per bundle if num_rows >= num_request_bundles : rows_per_bundle = len ( response_rows ) // len ( request_list ) else : rows_per_bundle = num_rows # Stream response as BundledRows for i in range ( 0 , len ( response_rows ) , rows_per_bundle ) : # Yield Row data as Bundled rows yield SSE . BundledRows ( rows = response_rows [ i : i + rows_per_bundle ] )