neuroscout/populate/extract.py
def extract_tokenized_features(extractors, dataset_name=None, task_name=None):
    """ Extract features that require a ComplexTextStim to give context to
    individual words within a run """

    if dataset_name is None:
        return [extract_features(
            extractors, dataset.name, None)
                for dataset in Dataset.query.filter_by(active=True)]

    stims = _load_complex_text_stim_models(dataset_name, task_name)

    if not stims:
        print(f"Dataset {dataset_name} has no matching stimuli")
        return None

    results = []
    # For every extractor, extract from complex stims
    for graph, cts_params in extractors:
        print("Graph: {}".format(graph))
        g = Graph(nodes=graph)
        window = cts_params.get("window", "transcript")
        window_n = cts_params.get("n", 25) if window == "pre" else None

        object_id = 'max' if window == 'pre' else None
        serializer = FeatureSerializer(
            object_id=object_id, splat=True, add_all=False, round_n=4)

        # Save window params as Graph attributes
        for node in g.nodes.values():
            setattr(node.transformer, "window_method", window)
            if window_n:
                setattr(node.transformer, "window_n", window_n)

        for sm, s in tqdm(stims):
            # Slice stims if window type is "pre"
            w_stim = _window_stim(s, window_n) if window == "pre" else [s]

            # Extract for every windowed slice
            for sli in w_stim:
                results += [
                    (sm.id, serializer.load(res)) 
                    for res in g.transform(sli, merge=False)
                ]

    # Serialize result objects first
    ext_feats = _create_efs(results)

    return create_predictors([ef for ef in ext_feats.values() if ef.active],
                             dataset_name, task_name)
 Extract features that require a ComplexTextStim to give context to
    individual words within a run 
Extract features that require a ComplexTextStim to give context to
individual words within a run
Extract features that require a ComplexTextStim to give context to individual words within a run
def extract_tokenized_features(extractors, dataset_name=None, task_name=None):
    if dataset_name is None:
        return [extract_features(
            extractors, dataset.name, None)
                for dataset in Dataset.query.filter_by(active=True)]
    stims = _load_complex_text_stim_models(dataset_name, task_name)
    if not stims:
        print(f"Dataset {dataset_name} has no matching stimuli")
        return None
    results = []
    for graph, cts_params in extractors:
        print("Graph: {}".format(graph))
        g = Graph(nodes=graph)
        window = cts_params.get("window", "transcript")
        window_n = cts_params.get("n", 25) if window == "pre" else None
        object_id = 'max' if window == 'pre' else None
        serializer = FeatureSerializer(
            object_id=object_id, splat=True, add_all=False, round_n=4)
        for node in g.nodes.values():
            setattr(node.transformer, "window_method", window)
            if window_n:
                setattr(node.transformer, "window_n", window_n)
        for sm, s in tqdm(stims):
            w_stim = _window_stim(s, window_n) if window == "pre" else [s]
            for sli in w_stim:
                results += [
                    (sm.id, serializer.load(res)) 
                    for res in g.transform(sli, merge=False)
                ]
    ext_feats = _create_efs(results)
    return create_predictors([ef for ef in ext_feats.values() if ef.active],
                             dataset_name, task_name)
def extract_tokenized_features ( extractors , dataset_name = None , task_name = None ) : if dataset_name is None : return [ extract_features ( extractors , dataset . name , None ) for dataset in Dataset . query . filter_by ( active = True ) ] stims = _load_complex_text_stim_models ( dataset_name , task_name ) if not stims : print ( f"Dataset {dataset_name} has no matching stimuli" ) return None results = [ ] for graph , cts_params in extractors : print ( "Graph: {}" . format ( graph ) ) g = Graph ( nodes = graph ) window = cts_params . get ( "window" , "transcript" ) window_n = cts_params . get ( "n" , 25 ) if window == "pre" else None object_id = 'max' if window == 'pre' else None serializer = FeatureSerializer ( object_id = object_id , splat = True , add_all = False , round_n = 4 ) for node in g . nodes . values ( ) : setattr ( node . transformer , "window_method" , window ) if window_n : setattr ( node . transformer , "window_n" , window_n ) for sm , s in tqdm ( stims ) : w_stim = _window_stim ( s , window_n ) if window == "pre" else [ s ] for sli in w_stim : results += [ ( sm . id , serializer . load ( res ) ) for res in g . transform ( sli , merge = False ) ] ext_feats = _create_efs ( results ) return create_predictors ( [ ef for ef in ext_feats . values ( ) if ef . active ] , dataset_name , task_name )
Extract features that require a ComplexTextStim to give context to
individual words within a run
Extract features that require a ComplexTextStim to give context to individual words within a run
""" Extract features that require a ComplexTextStim to give context to
    individual words within a run """ # For every extractor, extract from complex stims # Save window params as Graph attributes # Slice stims if window type is "pre" # Extract for every windowed slice # Serialize result objects first
extractors
dataset_name
task_name