<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_offsets(self, offset_ns=None):
 """ adds the onset and offset to each token in the document graph, i.e. the character position where each token starts and ends. """

        if offset_ns is None:
            offset_ns = self.ns

        onset = 0
        offset = 0

        for token_id, token_str in self.get_tokens():
            offset = onset + len(token_str)
            self.node[token_id]['{0}:{1}'.format(offset_ns, 'onset')] = onset
            self.node[token_id]['{0}:{1}'.format(offset_ns, 'offset')] = offset
            onset = offset + 1