I am trying to visualize a heterogeneous graph which nodes are categorical. Here is a dummy graph for implementation:

Input is

graph = UndirectedEdge @@@ {{"u0", "c1"}, {"u1", "c3"}, {"u2", "c0"}, {"u3", 
   "c2"}, {"u4", "c1"}, {"u0", "i0"}, {"u1", "i0"}, {"u2", 
   "i0"}, {"u3", "i1"}, {"u4", "i2"}}

And it looks like this by specifying vertex coordinates.

enter image description here

I would like to customize vertex shape by using VertexShapeFunction, but I cannot make the pattern matching work, for instance, I would like to make the nodes starts with m have shape square:

Graph[graph, VertexLabels -> "Name", VertexShapeFunction -> {_?StringStartsQ["u"] -> "Square" }]

I am aware the it should be a pattern, as

CompleteGraph[5, VertexShapeFunction -> {_?EvenQ -> "Star"}, VertexSize -> 0.2]

but I don't know how to make pattern work, I tried:

Cases[{"u1", "p1"}, _?StringStartsQ[#, "u"] &]

Returns empty list.

I know StringCases and Select can easily returns the strings I want, but unfortunately, seems only Cases with pattern matching would work for VertexShapeFunction

The following two works but it's not pattern matching.

StringCases[{"u1", "p1"}, "u" ~~ _]
Select[{"u1", "p1"}, StringStartsQ[#, "u"] &]
  • $\begingroup$ you define graph but then reference eMC. None of the vertices in graph start with m. $\endgroup$
    – Jason B.
    Commented Apr 9, 2021 at 19:43
  • $\begingroup$ It seems counterintuitive, but you have to use VertexShapeFunction -> {_?(StringStartsQ["m"]) -> "Square" }] $\endgroup$
    – Jason B.
    Commented Apr 9, 2021 at 19:46
  • $\begingroup$ Thank you for pointing out Jason, I just fixed the inconsistency. $\endgroup$
    – Wenzhen
    Commented Apr 9, 2021 at 19:50
  • $\begingroup$ but VertexShapeFunction -> {_?(StringStartsQ["u"]) -> "Square" }] doesn't work at all. $\endgroup$
    – Wenzhen
    Commented Apr 9, 2021 at 19:54
  • $\begingroup$ this doesn't work for you? What version are you using? $\endgroup$
    – Jason B.
    Commented Apr 9, 2021 at 20:00