6
$\begingroup$

WolframLanguageSymbol has a property named Frequencies, such as

EntityValue[Entity["WolframLanguageSymbol","ImageCorrespondingPoints"], "Frequencies"]

{All->7.61224*10^-7,StackExchange->3.77444*10^-6,...,WolframDocumentation->0.000019245}

Now I want to get top 10 built-in functions in StackExchange. This is my code:

EntityList[Entity["WolframLanguageSymbol", {"Frequencies" -> (TakeLargest[
       Lookup[#, "All"], 10] &)}]]

But it doesn't work for me. How to do this?

$\endgroup$
  • $\begingroup$ Just something I saw, the "Ranks" property might interest you more $\endgroup$ – b3m2a1 Apr 10 '18 at 6:06
  • 1
    $\begingroup$ @b3m2a1 Thanks very much, I have seen your answer before this. It is a great answer. :) $\endgroup$ – yode Apr 10 '18 at 6:54
8
$\begingroup$

Here are at least two ways:

WolframLanguageData[All,
                    EntityProperty["WolframLanguageSymbol", "Frequencies",
                                   {"Corpus" -> "StackExchange"}],
                    "EntityAssociation"] // TakeLargest[10] // KeyMap[CommonName]

or

prop = EntityProperty["WolframLanguageSymbol", "Frequencies",
                      {"Corpus" -> "StackExchange"}];
tmp = EntityClass["WolframLanguageSymbol", prop -> TakeLargest[10]]];
EntityValue[tmp, prop, "EntityAssociation"] // KeyMap[CommonName]

Both give the result

<|"List" -> 0.171144, "Times" -> 0.115336, "Set" -> 0.0546105, 
  "Power" -> 0.0539598, "Rule" -> 0.0488813, "Blank" -> 0.0330909, 
  "Pattern" -> 0.0324028, "Slot" -> 0.0254302, 
  "CompoundExpression" -> 0.0214271, "Plus" -> 0.0213214|>
$\endgroup$
  • $\begingroup$ You can actually get away without the EntityList. It'll do that automatically. $\endgroup$ – b3m2a1 Apr 10 '18 at 5:00
  • $\begingroup$ Indeed it does; thanks! $\endgroup$ – J. M. will be back soon Apr 10 '18 at 5:04
8
$\begingroup$

Not An Answer


Here's a cute way to look at what we like vs. what WRI likes:

symEnt[s_String] :=
  Entity["WolframLanguageSymbol", s];
symProp[cor_] :=
 EntityProperty["WolframLanguageSymbol", 
  "Frequencies", {"Corpus" -> cor}];
symClass[cor_ -> n_, props___] :=
 EntityClass[
  "WolframLanguageSymbol", {symProp[cor] -> TakeLargest[n], props}];
symClass[cor_ -> n_] :=

  EntityClass["WolframLanguageSymbol", symProp[cor] -> TakeLargest[n]];
symAssoc[e : _EntityClass | {__Entity}, cor_] :=

  KeyMap[CanonicalName]@
   EntityValue[e, symProp[cor], "EntityAssociation"];
symAssoc[cor_ -> n_] :=
 symAssoc[symClass[cor -> n], cor]

BarChart[likeRatio, 
 ChartLabels -> 
  Map[Rotate[Style[#, Bold, Black], Pi/2] &, Keys@likeRatio]]

blah

Notably this suffers from lots of things with no DownValues but which are common return values.

More Precise Comparison

Perhaps more interesting is this comparison:

whatWeReallyLike =
  EntityValue["WolframLanguageSymbol", 
   EntityProperty["WolframLanguageSymbol", 
    "Ranks", {"Corpus" -> "StackExchange"}],
   "EntityAssociation"
   ];
whatWRIReallyLikes =
  EntityValue["WolframLanguageSymbol", 
   EntityProperty["WolframLanguageSymbol", 
    "Ranks", {"Corpus" -> "TypicalProductionCode"}],
   "EntityAssociation"
   ];
whatWRIReallyDocuments =
  EntityValue["WolframLanguageSymbol", 
   EntityProperty["WolframLanguageSymbol", 
    "Ranks", {"Corpus" -> "WolframDocumentation"}],
   "EntityAssociation"
   ];

What we really like:

whatWeReallyLike // TakeSmallest[25] // KeyMap[CanonicalName]

<|"List" -> 1, "Times" -> 2, "Set" -> 3, "Power" -> 4, "Rule" -> 5, 
 "Blank" -> 6, "Pattern" -> 7, "Slot" -> 8, "CompoundExpression" -> 9,
  "Plus" -> 10, "Part" -> 11, "Function" -> 12, "SetDelayed" -> 13, 
 "Equal" -> 14, "Map" -> 15, "Null" -> 16, "Pi" -> 17, 
 "ReplaceAll" -> 18, "Table" -> 19, "Sin" -> 20, "All" -> 21, 
 "Apply" -> 22, "Sqrt" -> 23, "True" -> 24, "Length" -> 25|>

What WRI really likes:

whatWRIReallyLikes // TakeSmallest[25] // KeyMap[CanonicalName]

<|"List" -> 1, "Times" -> 2, "Set" -> 3, "Power" -> 4, 
 "CompoundExpression" -> 5, "Plus" -> 6, "Rule" -> 7, "Null" -> 8, 
 "Pattern" -> 9, "Blank" -> 10, "Subscript" -> 11, "Part" -> 12, 
 "SetDelayed" -> 13, "HoldComplete" -> 15, "Print" -> 16, 
 "Slot" -> 17, "Equal" -> 18, "ReplaceAll" -> 19, "If" -> 20, 
 "Pi" -> 21, "False" -> 22, "Function" -> 23, "True" -> 24, 
 "MessageName" -> 25, "Table" -> 26|>

What we use more than WRI:

KeySelect[whatWeReallyLike - whatWRIReallyLikes, 
   whatWeReallyLike[#] <= 500 &] // TakeSmallest[10] // 
 KeyMap[CanonicalName]

<|"RepeatedTiming" -> -4490, "RightComposition" -> -1754, 
 "ArrayPad" -> -1680, "Query" -> -1431, "EdgeList" -> -1280, 
 "ComponentMeasurements" -> -1238, "VertexLabels" -> -1176, 
 "GatherBy" -> -1174, "Unitize" -> -1083, "GroupBy" -> -1057|>

What WRI uses more than us:

KeySelect[whatWeReallyLike - whatWRIReallyLikes, 
   whatWeReallyLike[#] <= 500 &] // TakeLargest[10] // 
 KeyMap[CanonicalName]

<|"ComplexExpand" -> 338, "Information" -> 319, 
 "NonCommutativeMultiply" -> 282, "Sinh" -> 258, "Message" -> 252, 
 "Italic" -> 248, "SelectionMove" -> 239, "Det" -> 236, 
 "Identity" -> 224, "Switch" -> 211|>

What WRI uses in its docs more than we use here:

KeySelect[whatWeReallyLike - whatWRIReallyDocuments, 
   whatWeReallyLike[#] <= 500 &] // TakeLargest[10] // 
 KeyMap[CanonicalName]

<|"Switch" -> 355, "DateListPlot" -> 325, "DateObject" -> 313, 
 "Histogram" -> 282, "Cuboid" -> 275, "ExampleData" -> 264, 
 "Distributed" -> 263, "Labeled" -> 260, "ContourPlot3D" -> 259, 
 "CountryData" -> 245|>

What we use in similar amounts:

KeySelect[whatWeReallyLike - whatWRIReallyLikes, 
   whatWeReallyLike[#] <= 250 &] // TakeSmallestBy[Abs, 25] // 
 KeyMap[CanonicalName]

<|"SetDelayed" -> 0, "Times" -> 0, "Power" -> 0, "Set" -> 0, 
 "List" -> 0, "True" -> 0, "Prepend" -> -1, "Mesh" -> 1, "Part" -> -1,
  "Unequal" -> 1, "ReplaceAll" -> -1, "Rule" -> -2, "Automatic" -> 2, 
 "Integrate" -> 2, "I" -> -2, "PatternTest" -> 2, "Cos" -> -2, 
 "Pattern" -> -2, "Integer" -> 3, "Blank" -> -4, "Equal" -> -4, 
 "Sqrt" -> -4, "Floor" -> -4, "Plus" -> 4, "Pi" -> -4|>

What WRI likes more than it documents:

KeySelect[whatWRIReallyLikes - whatWRIReallyDocuments, 
   whatWRIReallyDocuments[#] <= 500 && 
     whatWRIReallyLikes[#] <= 500 &] // TakeSmallest[10] // 
 KeyMap[CanonicalName]

<|"BlankNullSequence" -> -420, "MessageName" -> -420, 
 "Integer" -> -353, "AppendTo" -> -336, "Head" -> -331, 
 "AbsoluteThickness" -> -318, "Ticks" -> -310, "Bold" -> -309, 
 "PlotPoints" -> -309, "C" -> -305|>

What WRI documents more than it likes:

KeySelect[whatWRIReallyLikes - whatWRIReallyDocuments, 
   whatWRIReallyDocuments[#] <= 500 && 
     whatWRIReallyLikes[#] <= 500 &] // TakeLargest[10] // 
 KeyMap[CanonicalName]

<|"Hyperlink" -> 435, "Histogram" -> 393, "CDF" -> 380, 
 "Graph" -> 331, "PDF" -> 299, "Lighter" -> 296, "Sphere" -> 273, 
 "SeedRandom" -> 271, "Reduce" -> 260, "ColorData" -> 253|>
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.