def __init__(self, rels, curies, base_uri, item_filter=lambda _: True):
        """Create a ``CanonicalRels`` instance.

        Arguments:

        - ``rels``:        the relationships to be queried. ``rels`` should be
                           a sequence of ``(key, value)`` tuples or an object
                           with an ``items`` method that returns such a
                           sequence (such as a dictionary). For each tuple in
                           the sequence, ``key`` is a string that identifies
                           the link relationship type and ``value`` is the
                           target of the relationship or a sequence of targets
                           of the relationship.
        - ``curies``:      a ``CurieCollection`` used to expand CURIE keys.
        - ``base_uri``:    URL used as the basis when expanding keys that are
                           relative URI references.
        - ``item_filter``: optional filter on target relationships.
                           ``item_filter`` should be a callable that accepts a
                           target relationship and returns False if the target
                           relationship should be excluded. ``item_filter``
                           will be called once with each target relationship.

        """
        if hasattr(rels, 'items'):
            items = rels.items()
        else:
            items = rels

        self.curies = curies
        self.base_uri = base_uri
        self.rels = {}

        for key, value in items:
            canonical_key = self.canonical_key(key)
            if not canonical_key in self.rels:
                self.rels[canonical_key] = (key, value)
                continue

            original_key, current_value = self.rels[canonical_key]

            new_value = [item for item in current_value if item_filter(item)]
            new_value.extend(item for item in value if item_filter(item))
            self.rels[canonical_key] = original_key, new_value

        self.rels = self.rels
def __init__ ( self , rels , curies , base_uri , item_filter = lambda _ : True ) : if hasattr ( rels , 'items' ) : items = rels . items ( ) else : items = rels self . curies = curies self . base_uri = base_uri self . rels = { } for key , value in items : canonical_key = self . canonical_key ( key ) if not canonical_key in self . rels : self . rels [ canonical_key ] = ( key , value ) continue original_key , current_value = self . rels [ canonical_key ] new_value = [ item for item in current_value if item_filter ( item ) ] new_value . extend ( item for item in value if item_filter ( item ) ) self . rels [ canonical_key ] = original_key , new_value self . rels = self . rels
Create a ``CanonicalRels`` instance.

        Arguments:

        - ``rels``:        the relationships to be queried. ``rels`` should be
                           a sequence of ``(key, value)`` tuples or an object
                           with an ``items`` method that returns such a
                           sequence (such as a dictionary). For each tuple in
                           the sequence, ``key`` is a string that identifies
                           the link relationship type and ``value`` is the
                           target of the relationship or a sequence of targets
                           of the relationship.
        - ``curies``:      a ``CurieCollection`` used to expand CURIE keys.
        - ``base_uri``:    URL used as the basis when expanding keys that are
                           relative URI references.
        - ``item_filter``: optional filter on target relationships.
                           ``item_filter`` should be a callable that accepts a
                           target relationship and returns False if the target
                           relationship should be excluded. ``item_filter``
                           will be called once with each target relationship.