<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_token_to_document(self, token, token_id, connected):
 """ adds a token to the document graph as a node with the given ID. Parameters token : str the token to be added to the document graph token_id : int the node ID of the token to be added, which must not yet exist in the document graph connected : bool Make the graph connected, i.e. add an edge from root this token. """

        regex_match = ANNOTATED_ANAPHORA_REGEX.search(token)
        if regex_match:  # token is annotated
            unannotated_token = regex_match.group('token')
            unicode_token = ensure_unicode(unannotated_token)
            annotation = regex_match.group('annotation')
            anno_type = ANNOTATION_TYPES[annotation]
            certainty = "1.0" if not regex_match.group('uncertain') else "0.5"
            self.add_node(
                token_id,
                layers={self.ns, self.ns+':token', self.ns+':annotated'},
                attr_dict={
                    self.ns+':annotation': anno_type,
                    self.ns+':certainty': certainty,
                    self.ns+':token': unicode_token,
                    'label': u"{0}_{1}".format(unicode_token, anno_type)})
        else:  # token is not annotated
            self.add_node(
                token_id,
                layers={self.ns, self.ns+':token'},
                attr_dict={self.ns+':token': ensure_unicode(token),
                           'label': ensure_unicode(token)})

        if connected:
            self.add_edge(self.root, token_id,
                          layers={self.ns, self.ns+':token'})