How to connect rating to individual comments?

This is almost entirely an HTML and/or Javascript question. You just need to make proper forms and have some PHP to process it.

function additional_fields ($below) {
  global $comment;
  $ratsec="<form action="".get_permalink().'" method="get" class="comment-form-rating">';
    $ratsec .= '<input type="hidden" name="p" value="'.get_the_ID().'"';
    $ratsec .= '<label for="rating">'. __('Rating') . '<span class="required">*</span></label>';
    $ratsec .= '<span class="commentratingbox">';

      //Current rating scale is 1 to 5. If you want the scale to be 1 to 10, then set the value of $i to 10.
      for( $i=1; $i <= 5; $i++ ) {
        $ratsec .= '<span class="commentrating"><input type="radio" name="rating['.$comment->comment_ID.']" id="rating" value="'. $i .'"/>'. $i .'</span>';
      }

      $ratsec .= '<input type="submit" name="rate" value="Rate" />';
    $ratsec .= '</span>';
  $ratsec .= '</form>';
  $below = $below .$ratsec;
  return $below;
}
add_filter( 'comment_text', 'additional_fields' );

You now have a form that will submit and in the GET string you should see your comment ID.

Use CSS to format it and if you want use Javascript to hijack the form submission entirely, so that you don’t need the submit button at all (hide it with Javascript but keep it in case Javascript is disabled). For that see the AJAX API.

The following will save the data.

function save_comment_meta_data() {
  if ( !empty($_GET['rating'])) {
    foreach ($_GET['rating'] as $k => $v) {
      if (!ctype_digit("$k")) {
        return;
      } else {
        $k = (int)$k;
      }
      $comment = get_comment($k);
      if (!empty($comment)) {
        $rating = wp_filter_nohtml_kses($_GET['rating'][$k]);
        add_comment_meta( $k, 'rating', $rating );
      }
    }
  }
}
add_action( 'wp_head', 'save_comment_meta_data' );