# Create Metaphor, Epitaph and Personification Functions

**URL:** <https://community.wolfram.com/t/create-metaphor-epitaph-and-personification-functions/6997>\
**Category:** Ideas\
**Tags:** machine-learning, computational-linguistics\
**Created:** [October 21, 2015, 1:56am UTC](https://community.wolfram.com/t/create-metaphor-epitaph-and-personification-functions/6997 "2015-10-21T01:56:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![omaraguilar2019](https://avatars.discourse-cdn.com/v4/letter/o/b77776/32.png) [@omaraguilar2019](https://community.wolfram.com/u/omaraguilar2019)\
**Post date:** [October 21, 2015, 1:56am UTC](https://community.wolfram.com/t/create-metaphor-epitaph-and-personification-functions/6997/1 "2015-10-21T01:56:45Z")

</div>

Hi Everybody! My name is Omar Aguilar and I am new here. I would like to know how can I create a function that for a given thing as input will give me a sensorial or abstract characteristic.

Examples of my goals:

```
Metaphor[cloud]
    soft, fluffy, etc

Epiteth[landscape]
    green

Personification[rock]
   serious, tough

```

---

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [October 24, 2015, 1:03am UTC](https://community.wolfram.com/t/create-metaphor-epitaph-and-personification-functions/6997/2 "2015-10-24T01:03:13Z")

</div>

Perhaps you need a context for that, some texts that use that sort of expressions? For example, a scientific text would not call “cloud” to be “flaffy”, but a fairy tale would. Let’s get Alice In Wonderland text.

```
alice = ToLowerCase[ExampleData[{"Text", "AliceInWonderland"}]];

```

Strangely it does not talk about clouds a single time:

```
StringCases[alice, "cloud"]
(*{}*)

```

But it does talk a lot about animals in a sort of metaphoric way, so I will try to build the `metaphor ` function for animals. This gets only sentences containing the word in question, say “cat”:

```
Select[TextSentences[alice], StringContainsQ[#, "cat"] &]

```

Now, in all those sentences, you find only words that can be adjectives. Of course minus the stop words. When you get them, tally by frequency of appearance:

```
Sort[Tally[Select[DeleteStopwords[
    Flatten[TextWords[Select[TextSentences[alice], StringContainsQ[#, "cat"] &]]]], 
   MemberQ[WordData[#, "PartsOfSpeech"], "Adjective"] &]], #1[[2]] > #2[[2]] &]

```

 ![2015-10-23_19-21-43.jpg](https://global.discourse-cdn.com/wolfram/original/3X/5/5/553411ce407dbe2a6ed6de53fcadd3bb5bc6125f.jpeg)

So say 3 top words will do:

```
metaphor[cont_String][s_String] := 
 Sort[Tally[Select[DeleteCases[DeleteStopwords[
 Flatten[TextWords[Select[TextSentences[cont], StringContainsQ[#, s] &]]]], "said"], 
 MemberQ[WordData[#, "PartsOfSpeech"], "Adjective"] &]], #1[[2]] > #2[[2]] &][[;; 3, 1]]

```

Now let’s see:

```
Grid[{#, metaphor[alice][#]} & /@ {"cat", "rat"}]

```

![2015-10-23_19-57-46.png](https://global.discourse-cdn.com/wolfram/original/3X/6/8/68dcb4e43905274c18cd06282a76c3fbf4b76682.png)

But other context would give a different result:

```
beowulf = ToLowerCase[ExampleData[{"Text", "BeowulfModern"}]];
Grid[{#, metaphor[beowulf][#]} & /@ {"cat", "rat"}]

```

![2015-10-23_19-59-09.png](https://global.discourse-cdn.com/wolfram/original/3X/0/d/0d2f2d68df50cafd74dc79df792e551db735ef95.png)

So if you get some large corpus of text reflecting on the context you target, then perhaps this would work.
