def follow(self,
             rel_specification,
             inverted = +1):
    """Follow a relation, or relation group, in the knowledge graph.

    Specifically, if x evaluates to a set of knowledge graph entities, then
    x.follow('foo') evaluates to the set of all entities which are related to x
    via the relation 'foo'.

    When rel_specification is a string naming a relation - ie it is a relation
    named in the expression's context - then follow only that relation in the
    knowledge graph. If inverted == -1, then follow the inverse of the relation.

    When rel_specification is an expression that evaluates to a a type
    associated with a relation group, then follow all the relations in that
    group, and return an appropriately weighted mixture of the results. If
    inverted == -1, then do the same for the inverses of the relation.

    Args:
      rel_specification: a string or NeuralQueryExpression for what to follow.
      inverted: +1 to follow the relations normally, -1 to use inverses

    Returns:
      A NeuralQueryExpression from following the relation.

    Raises:
      RelationNameError: If the relation cannot be found.
    """
    if inverted != +1 and inverted != -1:
      raise ValueError('Inverted (%d) is neither +1 nor -1' % inverted)
    if (isinstance(rel_specification, str) and
        self.context.is_relation(rel_specification)):
      what_to_follow = rel_specification + ('_inverse' if inverted < 0 else '')
      with tf.name_scope('follow_%s' % what_to_follow):
        return self._follow_named_rel(rel_specification, inverted)
    elif isinstance(rel_specification, NeuralQueryExpression):
      return self._follow_relation_set(rel_specification, inverted)
    else:
      raise RelationNameError(
          str(rel_specification), 'Illegal rel_specification.')
Follow a relation, or relation group, in the knowledge graph.

    Specifically, if x evaluates to a set of knowledge graph entities, then
    x.follow('foo') evaluates to the set of all entities which are related to x
    via the relation 'foo'.

    When rel_specification is a string naming a relation - ie it is a relation
    named in the expression's context - then follow only that relation in the
    knowledge graph. If inverted == -1, then follow the inverse of the relation.

    When rel_specification is an expression that evaluates to a a type
    associated with a relation group, then follow all the relations in that
    group, and return an appropriately weighted mixture of the results. If
    inverted == -1, then do the same for the inverses of the relation.

    Args:
      rel_specification: a string or NeuralQueryExpression for what to follow.
      inverted: +1 to follow the relations normally, -1 to use inverses

    Returns:
      A NeuralQueryExpression from following the relation.

    Raises:
      RelationNameError: If the relation cannot be found.
    
language/nql/nql/__init__.py