Message Boards Message Boards


Search an entity list?

Posted 6 months ago
6 Replies
3 Total Likes

I'm using the Wolfram General Topology EntityStore. From it, how would I search EntityList["GeneralTopologyTheorem"] to find, for example, those entities in the list that include the word "compact" in their name.

Here's where I am:

    obj = ResourceObject["General Topology EntityStore"];
    store = ResourceData[obj];
    data = EntityRegister[store]
(* {"GeneralTopologyConcept", "GeneralTopologyTheorem"} *)
    thms = EntityList["GeneralTopologyTheorem"]

The output from the last statement is a list of entites which display as "boxes" labeled with such things as "metric implies Hausdorff".

How do I search the list to find, say, which of those theorems in the store concern being compactt?

My notion is to somehow convert all the labels on those boxes into text and search the list of such texts. But how do I make that conversion? Or is there some better way?

6 Replies
Posted 6 months ago

Hi Murray,

Is this what you are looking for?

EntityList["GeneralTopologyTheorem"] // CanonicalName //
  Select[StringContainsQ[#, "compact", IgnoreCase -> True] &]

Yes, that Select together with CanonicalName did it. (The missing ingredient for me was CanonicalName.)

Now I have to figure out how to make the CamelCased entries in the output, e.g., change "CompactSubspaceOfHausdorffSpaceIsClosed" to "Compact Subspace Of Hausdorff Space Is Closed", so as to make the output more readable.

Posted 6 months ago

Here is one way

StringSplit["CompactSubspaceOfHausdorffSpaceIsClosed", RegularExpression["(?=[A-Z])"]] //

(* "Compact Subspace Of Hausdorff Space Is Closed" *)

Yes, that StringSplit with a RegularExpression expression does precisely what I need. (Even if it leaves prepositions and conjunctions upper-cased, contrary to usual rules for titles.) Thank you!

(One of these days I'll once again try to learn regular expressions. Each time I begin I'm distracted by other work.)

Posted 6 months ago

Hi Murray,

Presumably, you are not just interested in filtering just the names, but would also like to access other properties from the filtered list of names. Here is a way to do that.

Create a FilteredEntityClass that contains the entities whose name contains "compact".

compactTheorems = FilteredEntityClass["GeneralTopologyTheorem",
   EntityFunction[n, StringContainsQ[n["CanonicalName"], "Compact", IgnoreCase -> True]]];

Make a Dataset with name and some property

compactTheorems // EntityList // 
  Map[<|#["CanonicalName"] -> CanonicalName@#["RelatedConcepts"]|> &] // 

enter image description here

Add a "DisplayName" property using ExtendedEntityClass

extendedCompactTheorems = ExtendedEntityClass[compactTheorems,
   {"DisplayName" -> EntityFunction[n, 
      StringRiffle[StringSplit[n["CanonicalName"], RegularExpression["(?=[A-Z])"]]]]}];

extendedCompactTheorems // EntityList // 
  Map[<|#["DisplayName"] -> #["AlternateNames"]|> &] //

enter image description here

That last reply (with extendedCompactTheorems) is very helpful, since I'm still crawling around on the ground when dealing with entities and datasets and not yet beginning to stand up.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract