Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.3K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to find all classes that FormulaData is organized into?

I am trying to find all the classes that FormulaData and FormulaLookup have. I can find all of the formulas with FormulaData[] and the classes for a particular formula with FormulaData[#,"Classes"]. I have the following code which maps this function over all classes:

AssociationMap[FormulaData[#, "Classes"] &][FormulaData[]]

I've tried two methods to find all the classes but I have an issue with the level. Some of the classes are just a string like "Physics", but others are lists like {"Athletics", "Basketball"}. I am wondering how I can find both classes maybe with Flatten, Union, DeleteDuplcates, Join, or some other list operation.

I found a way to do it:

Union[Union[
DeleteMissing[
Map[TreeExpression][
Select[TreeDepth[#] == 1 &][
TreeLevel[
ExpressionTree[
Values[AssociationMap[FormulaData[#, "Classes"] &][
FormulaData[]]]], {-2, -1}]]]]] /. {{} -> Nothing}, 
DeleteMissing[
Union[Flatten[
TreeExpression[
RootTree[
ExpressionTree[
Values[AssociationMap[FormulaData[#, "Classes"] &][
FormulaData[]]]], 2]] /. {{} -> Nothing}]]]]
POSTED BY: Peter Burbery
4 Replies
Posted 2 years ago

That is quite convoluted. A simpler way to get the same result and ~10x faster.

AssociationMap[FormulaData[#, "Classes"] &][FormulaData[]] // Values //
    DeleteMissing // Flatten[#, 1] & // Union
POSTED BY: Rohit Namjoshi
Posted 2 years ago

It is not clear what you mean by

how I can find both classes

For

"AbbeNumberHelium" -> {"Physics", {"Physics", "Optics"}}

Which of the following do you want?

"AbbeNumberHelium" -> {"Physics", "Optics"}
"AbbeNumberHelium" -> "Physics", "AbbeNumberHelium" -> "Optics"
"AbbeNumberHelium" -> "Physics", "AbbeNumberHelium" -> {"Physics", "Optics"}}
POSTED BY: Rohit Namjoshi

That's much simpler and easier to read and understand.

POSTED BY: Peter Burbery

I would use Values on an association of the last line and then Union to delete duplicates and order them.

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