<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def extract_relation_instance(cls, field_name, field, resource_instance, serializer):
 """ Determines what instance represents given relation and extracts it. Relation instance is determined by given field_name or source configured on field. As fallback is a serializer method called with name of field's source. """

        relation_instance = None

        try:
            relation_instance = getattr(resource_instance, field_name)
        except AttributeError:
            try:
                # For ManyRelatedFields if `related_name` is not set
                # we need to access `foo_set` from `source`
                relation_instance = getattr(resource_instance, field.child_relation.source)
            except AttributeError:
                if hasattr(serializer, field.source):
                    serializer_method = getattr(serializer, field.source)
                    relation_instance = serializer_method(resource_instance)
                else:
                    # case when source is a simple remap on resource_instance
                    try:
                        relation_instance = getattr(resource_instance, field.source)
                    except AttributeError:
                        pass

        return relation_instance