Ejemplo n.º 1
0
def link_to_bio2rdf(*args,**kwargs):
    # Retrieve the article from the post
    article_id = kwargs['article']['id']
    match_items = kwargs['inputs']
    match_type = kwargs['link']

    app.logger.debug("Running Bio2RDF plugin for article {}".format(article_id))
    

    try :
        # Initialize the plugin
        plugin = SPARQLPlugin(endpoint = endpoints,
                          template = "bio2rdf.query",
                          match_type = match_type,
                          id_base = 'label',
                          all=True)
        
        # Run the plugin, and retrieve matches using the default label property (rdfs:label)
        
        matches = plugin.match(match_items)
        
        app.logger.debug("Plugin is done, returning the following matches")
        app.logger.debug(matches)
        
        # Return the matches
        return matches
        
    except Exception as e:
        app.logger.error(e.message)
        return {'error': e.message }
Ejemplo n.º 2
0
def link_to_neurolex(*args, **kwargs):
    # Retrieve the article from the wrapper
    article_id = kwargs['article']['id']
    
    app.logger.debug("Running Neurolex plugin for article {}".format(article_id))
    
    match_items = kwargs['inputs']
    
    try :
        # Initialize the plugin
        plugin = SPARQLPlugin(endpoint = "http://rdf-stage.neuinfo.org/ds/query",
                          template = "neurolex.query")
        
        # Run the plugin, and retrieve matches using the default label property (rdfs:label)
        matches = plugin.match(match_items)

        app.logger.debug(matches)
        
        # Run the plugin with a NeuroLex specific property (namespace is defined in the neurolex.query template)
        specific_matches = plugin.match(match_items, property="property:Label")
        
        matches_keys_lower = {k.lower(): k for k,v in matches.items()}
        specific_keys_lower = {k.lower(): k for k,v in specific_matches.items()}
        
        app.logger.debug("Removing duplicates from matches")
        app.logger.debug(matches_keys_lower.keys())
        app.logger.debug(specific_keys_lower.keys())
        for k, K in specific_keys_lower.items():
            app.logger.debug(k)
            if not k in matches_keys_lower.items():
                app.logger.debug("{} is not in {}".format(k,matches_keys_lower))
                matches[K] = specific_matches[K]
        
        matches_keys_lower = {k.lower(): k for k,v in matches.items()}
        unique_matches = {}     
        for k, K in matches_keys_lower.items():
            unique_matches[K] = matches[K]

        app.logger.debug(unique_matches)
        
        # Return the matches
        return unique_matches
        
    except Exception as e:
        return {'error': e.message }
Ejemplo n.º 3
0
def link_to_wikipedia(*args,**kwargs):
    # Retrieve the article from the post
    article_id = kwargs['article']['id']
    match_items = kwargs['inputs']
    match_type = kwargs['link']

    app.logger.debug("Running DBPedia plugin for article {}".format(article_id))
    

    # Rewrite the match_items to strip the inchikey= prefix from the tag, if present. This allows the SPARQLPlugin to find additional matches for the dbpprop:inchikey property.
    match_items = [{'id': item['id'], 
                    'label': re.findall('^.*?\=(.*)$',item['label'])[0] if item['label'].lower().startswith('inchikey=') else item['label']} 
                    for item in match_items]
    
    try :
        # Initialize the plugin
        plugin = SPARQLPlugin(endpoint = endpoints,
                          template = "dbpedia.query",
                          match_type = match_type,
                          rewrite_function = lambda x: re.sub('dbpedia.org/resource','en.wikipedia.org/wiki',x),
                          id_function = lambda x: re.sub('http://dbpedia.org/resource/','',x),
                          id_base = 'uri')
        
        # Run the plugin, and retrieve matches using the default label property (rdfs:label)
        
        matches = plugin.match(match_items)
        # Run the plugin with a specific property for the InchiKeys (namespace is defined in the dbpedia.query template)
        matches.update(plugin.match(match_items, property="dbpprop:inchikey"))
        
        app.logger.debug("Plugin is done, returning the following matches")
        app.logger.debug(matches)
        
        # Return the matches
        return matches
        
    except Exception as e:
        app.logger.error(e.message)
        return {'error': e.message }