Research Article

Predicting Mental Health Problems with Automatic Identification of Metaphors

Algorithm 2

Metaphor identification algorithm.
Input: sentence; A dictionary that returns the corresponding word vector of key, Word2vec; A dictionary that returns the related word set of key, WordNet.
Output: A list of the corresponding metaphority labels of words in sentence, labels.
(1)function TokenMetaphorIdentify (detected word; sentence)
(2) context = [];  = 0
(3) = WordNet [detected word]
(4)for each wordsentence and word ≠ detected_word do
(5)  context = context word
(6)end for
(7) = average (Word2vec [context])
(8)for each k do
(9)  if cosine(Word2vec[k],) ˃ max_cosine then
(10)   max_cosine = cosine(Word2vec[k],)
(11)    = k
(12)  end if
(13)end for
(14)metaphor_value = cosine (Word2vec [detected_word], Word2vec [])
(15)if metaphor value < threshold then
(16)  return True
(17)else
(18)  return False
(19)end if
(20)end function
(21)
(22)function MetaphorIdentify (sentence)
(23)labels = []
(24)for each wordsentence do
(25)  label = TokenMetaphorIdentify (word; sentence)
(26)  labels = labelslabel
(27)end for
(28)return labels
(29)end function