What kind of bigram probability smoothing is this?
This looks like it might be implementing Laplace smoothing (though I can't explain the extra +2 in the first two calculations).

There are many smoothing methods, e.g., Lidstone, Good-Turing, Kneser-Tey,  Witten-Bell.  You can also use interpolation and backoff to handle rare or low-probability events when computing conditional probabilities like this.