def replace_predicate(rdf, fromuri, touri, subjecttypes=None, inverse=False):
if fromuri == touri:<EOL><INDENT>return<EOL><DEDENT>for s, o in rdf.subject_objects(fromuri):<EOL><INDENT>if subjecttypes is not None:<EOL><INDENT>typeok = False<EOL>for t in subjecttypes:<EOL><INDENT>if (s, RDF.type, t) in rdf:<EOL><INDENT>typeok = True<EOL><DEDENT><DEDENT>if not typeok:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>rdf.remove((s, fromuri, o))<EOL>if touri is not None:<EOL><INDENT>if not isinstance(touri, (list, tuple)):<EOL><INDENT>touri = [touri]<EOL><DEDENT>for val in touri:<EOL><INDENT>if not isinstance(val, tuple):<EOL><INDENT>val = (val, False)<EOL><DEDENT>uri, inverse = val<EOL>if uri is None:<EOL><INDENT>continue<EOL><DEDENT>if inverse:<EOL><INDENT>rdf.add((o, uri, s))<EOL><DEDENT>else:<EOL><INDENT>rdf.add((s, uri, o))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Replace occurrences of fromuri as predicate with touri in given model.

    If touri=None, will delete all occurrences of fromuri instead.
    If touri is a list or tuple of URIRef, all values will be inserted. If
    touri is a list of (URIRef, boolean) tuples, the boolean value will be
    used to determine whether an inverse property is created (if True) or
    not (if False). If a subjecttypes sequence is given, modify only those
    triples where the subject is one of the provided types.