The following program in a Pascal-like language may help
if plural(word)
then
if possessive(word)
then
if lastchar(word) = "s"
then word := word + "'"
else word := word + "s'"
else word := word + "s"
else
if word = "it is"
then word := "it's"
else
if possessive(word)
then
if word = "it"
then word := "its"
else
if lastchar(word) = "s"
then word := word + "'"
else word := word + "'s"