def term_from_uri(uri):
    """Removes prepended URI information from terms."""
    if uri is None:
        return None
    # This insures that if we get a Literal with an integer value (as we
    # do for modification positions), it will get converted to a string,
    # not an integer.
    if isinstance(uri, rdflib.Literal):
        uri = str(uri.toPython())
    # This is to handle URIs like
    # http://www.openbel.org/bel/namespace//MAPK%20Erk1/3%20Family
    # or
    # http://www.openbel.org/bel/namespace/MAPK%20Erk1/3%20Family
    # In the current implementation, the order of the patterns
    # matters.
    patterns = ['http://www.openbel.org/bel/namespace//(.*)',
                'http://www.openbel.org/vocabulary//(.*)',
                'http://www.openbel.org/bel//(.*)',
                'http://www.openbel.org/bel/namespace/(.*)',
                'http://www.openbel.org/vocabulary/(.*)',
                'http://www.openbel.org/bel/(.*)']
    for pr in patterns:
        match = re.match(pr, uri)
        if match is not None:
            term = match.groups()[0]
            term = unquote(term)
            return term
    # If none of the patterns match then the URI is actually a simple term
    # for instance a site: "341" or a substitution: "sub(V,600,E)"
    return uri
def term_from_uri ( uri ) : if uri is None : return None if isinstance ( uri , rdflib . Literal ) : uri = str ( uri . toPython ( ) ) patterns = [ 'http://www.openbel.org/bel/namespace//(.*)' , 'http://www.openbel.org/vocabulary//(.*)' , 'http://www.openbel.org/bel//(.*)' , 'http://www.openbel.org/bel/namespace/(.*)' , 'http://www.openbel.org/vocabulary/(.*)' , 'http://www.openbel.org/bel/(.*)' ] for pr in patterns : match = re . match ( pr , uri ) if match is not None : term = match . groups ( ) [ 0 ] term = unquote ( term ) return term return uri
Removes prepended URI information from terms.