Group Abstract Group Abstract

Message Boards Message Boards

Create Metaphor, Epitaph and Personification Functions

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
POSTED BY: Omar Aguilar

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]] &]

enter image description here

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"}]

enter image description here

But other context would give a different result:

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

enter image description here

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

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard