MCPcopy Create free account
hub / github.com/alibaba/GraphScope / preprocess_args

Method preprocess_args

python/graphscope/learning/graph.py:98–207  ·  view source on GitHub ↗
(handle, nodes, edges, gen_labels)

Source from the content-addressed store, hash-verified

96
97 @staticmethod # noqa: C901
98 def preprocess_args(handle, nodes, edges, gen_labels): # noqa: C901
99 handle = json.loads(base64.b64decode(handle).decode("utf-8", errors="ignore"))
100 node_names = []
101 node_attributes = {}
102 edge_names = []
103 edge_attributes = {}
104
105 def selected_property_schema(attr_types, attributes):
106 prop_counts = collections.defaultdict(lambda: 0)
107 for attr in attributes:
108 prop_counts[attr_types[attr]] += 1
109 return [prop_counts["i"], prop_counts["f"], prop_counts["s"]]
110
111 if nodes is not None:
112 for node in nodes:
113 if isinstance(node, str):
114 if node in node_names:
115 raise InvalidArgumentError("Duplicate node type: %s" % node)
116 node_names.append(node)
117 elif isinstance(node, tuple):
118 if node[0] in node_names:
119 raise InvalidArgumentError("Duplicate node type: %s" % node[0])
120 node_names.append(node[0])
121 attr_types = handle["node_attribute_types"][node[0]]
122 attr_schema = selected_property_schema(attr_types, node[1])
123 node_attributes[node[0]] = (node[1], attr_schema)
124 else:
125 raise InvalidArgumentError(
126 "The node parameter is in bad format: %s" % node
127 )
128 else:
129 for node in handle["node_schema"]:
130 node_names.append(node.split(":")[0])
131
132 if edges is not None:
133 for edge in edges:
134 if isinstance(edge, str):
135 if len(node_names) > 1:
136 raise InvalidArgumentError(
137 "Cannot inference edge type when multiple kinds of nodes exists"
138 )
139 edge_names.append((node_names[0], edge, node_names[0]))
140 elif (
141 isinstance(edge, tuple)
142 and isinstance(edge[0], str)
143 and isinstance(edge[1], str)
144 ):
145 edge_names.append(edge)
146 elif (
147 isinstance(edge, tuple)
148 and isinstance(edge[0], str)
149 and isinstance(edge[1], list)
150 ):
151 if len(node_names) > 1:
152 raise InvalidArgumentError(
153 "Cannot inference edge type when multiple kinds of nodes exists"
154 )
155 edge_names.append((node_names[0], edge[0], node_names[0]))

Callers 1

graphlearnMethod · 0.80

Calls 6

check_argumentFunction · 0.90
splitMethod · 0.80
itemsMethod · 0.80
appendMethod · 0.65
decodeMethod · 0.45

Tested by

no test coverage detected