Message Boards Message Boards

0
|
6359 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Sorting synonyms

Posted 11 years ago
Example query recieved by email:
Need a more convoluted way to say something's convoluted?
synonyms convoluted:
http://url.wolfram.com/MACJrS/


Suppose I'm composing a tweet, the most useful synonym for a word would be the shortest. How do I sort the results by length? So far I've figured out that "character count" will tell me the length of an input string, but I haven't figured out how to apply it to the results list of "synonyms convoluted".
POSTED BY: Elijah Pogonatus
3 Replies
Here is a solution:
 synonyms[word_] := Module[
    {wordData , likeTypes},
    wordData = WordData[word, "Synonyms"];
    If[ Head[wordData] == WordData, Return[{word}]];
    (*Print[wordData];*)
    likeTypes = Flatten[Last /@ wordData];
    If[Length[likeTypes] == 0 , Return[{word}]];
    Union@likeTypes
    ] /; StringQ[word]

try this:
synonyms["face"]

or
synonyms[word_, type_] := Module[
   {wordData = WordData[word, "Synonyms"], likeTypes},
   likeTypes =
    Union@Flatten[
      Last /@ Select[wordData, MemberQ[First[#], type] &]]
   ] /; StringQ[word] && StringQ[type]
Then try,
synonyms["face", "Verb"]

so your shortest solutions would be something like this:
SortBy[synonyms["convoluted", "Adjective"], StringLength]

SortBy[synonyms["convoluted"], StringLength]

SortBy[synonyms["convoluted", "Noun"], StringLength]

or
First[SortBy[synonyms["convoluted", "Adjective"], StringLength]]
POSTED BY: W. Craig Carter
There is also a nice example in documentation. It has combinatorial nature so I would not use it for too many words - you will need more time then.

Find the shortest versions of a phrase based on synonyms for its constituent words:

In
text = StringSplit["operational fracture conceptualization"]

Out
{"operational", "fracture", "conceptualization"}

In
Take[SortBy[StringJoin[Riffle[#, " "]] & /@
   Tuples[WordData[#, "Synonyms", "List"] & /@ text], StringLength],3]

Out
{"usable break formulation", "usable crack formulation", "usable fault formulation"}
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

Group Abstract Group Abstract