-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathgraphlib.po
More file actions
398 lines (358 loc) · 16.5 KB
/
Copy pathgraphlib.po
File metadata and controls
398 lines (358 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# Matt Wang <mattwang44@gmail.com>, 2023
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-02-07 00:19+0000\n"
"PO-Revision-Date: 2023-01-04 16:35+0800\n"
"Last-Translator: Matt Wang <mattwang44@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.2.2\n"
#: ../../library/graphlib.rst:2
msgid ""
":mod:`!graphlib` --- Functionality to operate with graph-like structures"
msgstr ":mod:`!graphlib` —-- 使用類圖 (graph-like) 結構進行操作的功能"
#: ../../library/graphlib.rst:8
msgid "**Source code:** :source:`Lib/graphlib.py`"
msgstr "**原始碼:**\\ :source:`Lib/graphlib.py`"
#: ../../library/graphlib.rst:20
msgid ""
"Provides functionality to topologically sort a graph of :term:`hashable` "
"nodes."
msgstr ""
"提供對包含\\ :term:`可雜湊 (hashable) <hashable>` 節點之圖 (graph) 進行拓撲排"
"序 (topologically sort) 的功能。"
#: ../../library/graphlib.rst:22
msgid ""
"A topological order is a linear ordering of the vertices in a graph such "
"that for every directed edge u -> v from vertex u to vertex v, vertex u "
"comes before vertex v in the ordering. For instance, the vertices of the "
"graph may represent tasks to be performed, and the edges may represent "
"constraints that one task must be performed before another; in this example, "
"a topological ordering is just a valid sequence for the tasks. A complete "
"topological ordering is possible if and only if the graph has no directed "
"cycles, that is, if it is a directed acyclic graph."
msgstr ""
"拓撲排序是圖中頂點 (vertex) 的線性排序,使得對於從頂點 u 到頂點 v 的每條有向"
"邊 (directed edge) u -> v,頂點 u 在排序中會位於頂點 v 之前。例如,圖的頂點可"
"能代表要執行的任務,而邊可能代表一個任務必須在另一個任務之前執行的限制;在此"
"範例中,拓撲排序只是任務的一種有效序列。若且唯若 (if and only if) 圖沒有有向"
"環 (directed cycle) 時,即如果它是個有向無環圖 (directed acyclic graph),則完"
"整的拓撲排序才是可行的。"
#: ../../library/graphlib.rst:31
msgid ""
"If the optional *graph* argument is provided it must be a dictionary "
"representing a directed acyclic graph where the keys are nodes and the "
"values are iterables of all predecessors of that node in the graph (the "
"nodes that have edges that point to the value in the key). Additional nodes "
"can be added to the graph using the :meth:`~TopologicalSorter.add` method."
msgstr ""
"如果提供了可選的 *graph* 引數,它必須是表示有向無環圖的字典,其中鍵是節點,值"
"是圖中該節點的包含所有前驅節點 (predecessor) 之可疊代物件(這些前驅節點具有指"
"向以鍵表示之節點的邊)。可以使用 :meth:`~TopologicalSorter.add` 方法將其他節"
"點新增到圖中。"
#: ../../library/graphlib.rst:37
msgid ""
"In the general case, the steps required to perform the sorting of a given "
"graph are as follows:"
msgstr "在一般情況下,對給定的圖執行排序所需的步驟如下:"
#: ../../library/graphlib.rst:40
msgid ""
"Create an instance of the :class:`TopologicalSorter` with an optional "
"initial graph."
msgstr "以選用的初始圖建立 :class:`TopologicalSorter` 的實例。"
#: ../../library/graphlib.rst:42
msgid "Add additional nodes to the graph."
msgstr "在圖中新增其他節點。"
#: ../../library/graphlib.rst:43
msgid "Call :meth:`~TopologicalSorter.prepare` on the graph."
msgstr "呼叫圖的 :meth:`~TopologicalSorter.prepare`。"
#: ../../library/graphlib.rst:44
msgid ""
"While :meth:`~TopologicalSorter.is_active` is ``True``, iterate over the "
"nodes returned by :meth:`~TopologicalSorter.get_ready` and process them. "
"Call :meth:`~TopologicalSorter.done` on each node as it finishes processing."
msgstr ""
"當 :meth:`~TopologicalSorter.is_active` 為 ``True`` 時,疊代 :meth:"
"`~TopologicalSorter.get_ready` 回傳的節點並處理它們。在每個節點完成處理時呼"
"叫 :meth:`~TopologicalSorter.done`。"
#: ../../library/graphlib.rst:49
msgid ""
"In case just an immediate sorting of the nodes in the graph is required and "
"no parallelism is involved, the convenience method :meth:`TopologicalSorter."
"static_order` can be used directly:"
msgstr ""
"如果只需要立即對圖中的節點進行排序且不涉及平行性 (parallelism),則可以直接使"
"用便捷方法 :meth:`TopologicalSorter.static_order`:"
#: ../../library/graphlib.rst:53
msgid ""
">>> graph = {\"D\": {\"B\", \"C\"}, \"C\": {\"A\"}, \"B\": {\"A\"}}\n"
">>> ts = TopologicalSorter(graph)\n"
">>> tuple(ts.static_order())\n"
"('A', 'C', 'B', 'D')"
msgstr ""
">>> graph = {\"D\": {\"B\", \"C\"}, \"C\": {\"A\"}, \"B\": {\"A\"}}\n"
">>> ts = TopologicalSorter(graph)\n"
">>> tuple(ts.static_order())\n"
"('A', 'C', 'B', 'D')"
#: ../../library/graphlib.rst:60
msgid ""
"The class is designed to easily support parallel processing of the nodes as "
"they become ready. For instance::"
msgstr "該類別設計為在節點準備就緒時,簡單支援節點的平行處理。例如: ::"
#: ../../library/graphlib.rst:63
msgid ""
"topological_sorter = TopologicalSorter()\n"
"\n"
"# Add nodes to 'topological_sorter'...\n"
"\n"
"topological_sorter.prepare()\n"
"while topological_sorter.is_active():\n"
" for node in topological_sorter.get_ready():\n"
" # Worker threads or processes take nodes to work on off the\n"
" # 'task_queue' queue.\n"
" task_queue.put(node)\n"
"\n"
" # When the work for a node is done, workers put the node in\n"
" # 'finalized_tasks_queue' so we can get more nodes to work on.\n"
" # The definition of 'is_active()' guarantees that, at this point, at\n"
" # least one node has been placed on 'task_queue' that hasn't yet\n"
" # been passed to 'done()', so this blocking 'get()' must (eventually)\n"
" # succeed. After calling 'done()', we loop back to call 'get_ready()'\n"
" # again, so put newly freed nodes on 'task_queue' as soon as\n"
" # logically possible.\n"
" node = finalized_tasks_queue.get()\n"
" topological_sorter.done(node)"
msgstr ""
#: ../../library/graphlib.rst:87
msgid ""
"Add a new node and its predecessors to the graph. Both the *node* and all "
"elements in *predecessors* must be :term:`hashable`."
msgstr ""
"向圖中新增新節點及其前驅節點。*node* 和 *predecessors* 中的所有元素都必須是"
"\\ :term:`可雜湊 <hashable>`\\ 的。"
#: ../../library/graphlib.rst:90
msgid ""
"If called multiple times with the same node argument, the set of "
"dependencies will be the union of all dependencies passed in."
msgstr ""
"如果以相同節點引數多次呼叫,則依賴項的集合將會是傳入的所有依賴項的聯集。"
#: ../../library/graphlib.rst:93
msgid ""
"It is possible to add a node with no dependencies (*predecessors* is not "
"provided) or to provide a dependency twice. If a node that has not been "
"provided before is included among *predecessors* it will be automatically "
"added to the graph with no predecessors of its own."
msgstr ""
"可以新增一個沒有依賴關係的節點(*predecessors* 未提供)或提供兩次依賴關係。如"
"果有之前未曾提供的節點被包含在 *predecessors* 中,它將自動新增到沒有前驅節點"
"的圖中。"
#: ../../library/graphlib.rst:98
msgid ""
"Raises :exc:`ValueError` if called after :meth:`~TopologicalSorter.prepare`."
msgstr ""
"如果在 :meth:`~TopologicalSorter.prepare` 之後呼叫,則引發 :exc:"
"`ValueError`。"
#: ../../library/graphlib.rst:102
msgid ""
"Mark the graph as finished and check for cycles in the graph. If any cycle "
"is detected, :exc:`CycleError` will be raised, but :meth:`~TopologicalSorter."
"get_ready` can still be used to obtain as many nodes as possible until "
"cycles block more progress. After a call to this function, the graph cannot "
"be modified, and therefore no more nodes can be added using :meth:"
"`~TopologicalSorter.add`."
msgstr ""
"將圖標記為已完成並檢查圖中的循環。如果檢測到任何循環,將引發 :exc:"
"`CycleError`,但 :meth:`~TopologicalSorter.get_ready` 仍可用於盡可能獲得更多"
"的節點,直到循環阻塞了進度。呼叫此函式後就無法修改圖,因此無法使用 :meth:"
"`~TopologicalSorter.add` 來新增更多節點。"
#: ../../library/graphlib.rst:109
msgid ""
"A :exc:`ValueError` will be raised if the sort has been started by :meth:`~."
"static_order` or :meth:`~.get_ready`."
msgstr ""
#: ../../library/graphlib.rst:114
msgid ""
"``prepare()`` can now be called more than once as long as the sort has not "
"started. Previously this raised :exc:`ValueError`."
msgstr ""
#: ../../library/graphlib.rst:119
msgid ""
"Returns ``True`` if more progress can be made and ``False`` otherwise. "
"Progress can be made if cycles do not block the resolution and either there "
"are still nodes ready that haven't yet been returned by :meth:"
"`TopologicalSorter.get_ready` or the number of nodes marked :meth:"
"`TopologicalSorter.done` is less than the number that have been returned by :"
"meth:`TopologicalSorter.get_ready`."
msgstr ""
"如果可以有更多進度則回傳 ``True``,否則回傳 ``False``。如果循環不阻塞解析 "
"(resolution) 並且仍有節點準備就緒但尚未由 :meth:`TopologicalSorter."
"get_ready` 回傳或標記為 :meth:`TopologicalSorter.done` 的節點數量較 :meth:"
"`TopologicalSorter.get_ready` 所回傳的少,則可以繼續取得進度。"
#: ../../library/graphlib.rst:126
msgid ""
"The :meth:`~object.__bool__` method of this class defers to this function, "
"so instead of::"
msgstr "此類別的 :meth:`~object.__bool__` 方法遵循此函式,因此以下做法: ::"
#: ../../library/graphlib.rst:129
msgid ""
"if ts.is_active():\n"
" ..."
msgstr ""
"if ts.is_active():\n"
" ..."
#: ../../library/graphlib.rst:132
msgid "it is possible to simply do::"
msgstr "可以簡單地用以下方式替換: ::"
#: ../../library/graphlib.rst:134
msgid ""
"if ts:\n"
" ..."
msgstr ""
"if ts:\n"
" ..."
#: ../../library/graphlib.rst:137 ../../library/graphlib.rst:160
msgid ""
"Raises :exc:`ValueError` if called without calling :meth:`~TopologicalSorter."
"prepare` previously."
msgstr ""
"如果呼叫之前沒有先呼叫 :meth:`~TopologicalSorter.prepare` 則引發 :exc:"
"`ValueError`。"
#: ../../library/graphlib.rst:142
msgid ""
"Marks a set of nodes returned by :meth:`TopologicalSorter.get_ready` as "
"processed, unblocking any successor of each node in *nodes* for being "
"returned in the future by a call to :meth:`TopologicalSorter.get_ready`."
msgstr ""
"將 :meth:`TopologicalSorter.get_ready` 回傳的一組節點標記為已處理,停止阻塞 "
"*nodes* 中每個節點的任何後繼節點 (successor),以便將來透過呼叫 :meth:"
"`TopologicalSorter.get_ready` 回傳。"
#: ../../library/graphlib.rst:146
msgid ""
"Raises :exc:`ValueError` if any node in *nodes* has already been marked as "
"processed by a previous call to this method or if a node was not added to "
"the graph by using :meth:`TopologicalSorter.add`, if called without calling :"
"meth:`~TopologicalSorter.prepare` or if node has not yet been returned by :"
"meth:`~TopologicalSorter.get_ready`."
msgstr ""
"若沒有和該呼叫一起呼叫 :meth:`~TopologicalSorter.prepare` 或節點還沒有被 :"
"meth:`~TopologicalSorter.get_ready` 回傳,且如果 *nodes* 中有任何節點已被先前"
"對此方法的呼叫標記為已處理、或者未使用 :meth:`TopologicalSorter.add` 將節點新"
"增到圖中,則引發 :exc:`ValueError`。"
#: ../../library/graphlib.rst:154
msgid ""
"Returns a ``tuple`` with all the nodes that are ready. Initially it returns "
"all nodes with no predecessors, and once those are marked as processed by "
"calling :meth:`TopologicalSorter.done`, further calls will return all new "
"nodes that have all their predecessors already processed. Once no more "
"progress can be made, empty tuples are returned."
msgstr ""
"回傳一個包含所有準備就緒節點的 ``tuple``。最初它回傳沒有前驅節點的所有節點,"
"一旦透過呼叫 :meth:`TopologicalSorter.done` 來將這些節點標記為已處理後,進一"
"步的呼叫將回傳所有其全部前驅節點都已被處理的新節點。若無法取得更多進度,將回"
"傳空 tuple。"
#: ../../library/graphlib.rst:165
msgid ""
"Returns an iterator object which will iterate over nodes in a topological "
"order. When using this method, :meth:`~TopologicalSorter.prepare` and :meth:"
"`~TopologicalSorter.done` should not be called. This method is equivalent "
"to::"
msgstr ""
"回傳一個可疊代物件,它將按拓撲排序疊代節點。使用此方法時,不應呼叫 :meth:"
"`~TopologicalSorter.prepare` 和 :meth:`~TopologicalSorter.done`。此方法等效"
"於: ::"
#: ../../library/graphlib.rst:170
msgid ""
"def static_order(self):\n"
" self.prepare()\n"
" while self.is_active():\n"
" node_group = self.get_ready()\n"
" yield from node_group\n"
" self.done(*node_group)"
msgstr ""
"def static_order(self):\n"
" self.prepare()\n"
" while self.is_active():\n"
" node_group = self.get_ready()\n"
" yield from node_group\n"
" self.done(*node_group)"
#: ../../library/graphlib.rst:177
msgid ""
"The particular order that is returned may depend on the specific order in "
"which the items were inserted in the graph. For example:"
msgstr "回傳的特定順序可能取決於將項目插入圖中的特定順序。例如:"
#: ../../library/graphlib.rst:180
msgid ""
">>> ts = TopologicalSorter()\n"
">>> ts.add(3, 2, 1)\n"
">>> ts.add(1, 0)\n"
">>> print([*ts.static_order()])\n"
"[2, 0, 1, 3]\n"
"\n"
">>> ts2 = TopologicalSorter()\n"
">>> ts2.add(1, 0)\n"
">>> ts2.add(3, 2, 1)\n"
">>> print([*ts2.static_order()])\n"
"[0, 2, 1, 3]"
msgstr ""
">>> ts = TopologicalSorter()\n"
">>> ts.add(3, 2, 1)\n"
">>> ts.add(1, 0)\n"
">>> print([*ts.static_order()])\n"
"[2, 0, 1, 3]\n"
"\n"
">>> ts2 = TopologicalSorter()\n"
">>> ts2.add(1, 0)\n"
">>> ts2.add(3, 2, 1)\n"
">>> print([*ts2.static_order()])\n"
"[0, 2, 1, 3]"
#: ../../library/graphlib.rst:194
msgid ""
"This is due to the fact that \"0\" and \"2\" are in the same level in the "
"graph (they would have been returned in the same call to :meth:"
"`~TopologicalSorter.get_ready`) and the order between them is determined by "
"the order of insertion."
msgstr ""
"這是因為 \"0\" 和 \"2\" 在圖中處於同一級別(它們將在對 :meth:"
"`~TopologicalSorter.get_ready` 的同一呼叫中回傳)並且它們之間的順序取決於插入"
"順序。"
#: ../../library/graphlib.rst:200
msgid "If any cycle is detected, :exc:`CycleError` will be raised."
msgstr "如果檢測到任何循環,則引發 :exc:`CycleError`。"
#: ../../library/graphlib.rst:206
msgid "Exceptions"
msgstr "例外"
#: ../../library/graphlib.rst:207
msgid "The :mod:`!graphlib` module defines the following exception classes:"
msgstr ":mod:`!graphlib` 模組定義了以下例外類別:"
#: ../../library/graphlib.rst:211
msgid ""
"Subclass of :exc:`ValueError` raised by :meth:`TopologicalSorter.prepare` if "
"cycles exist in the working graph. If multiple cycles exist, only one "
"undefined choice among them will be reported and included in the exception."
msgstr ""
":exc:`ValueError` 的子類別,如果作用的圖中存在循環則由 :meth:"
"`TopologicalSorter.prepare` 引發。如果存在多個循環,則只會報告未定義的其中一"
"個並包含在例外中。"
#: ../../library/graphlib.rst:215
msgid ""
"The detected cycle can be accessed via the second element in the :attr:"
"`~BaseException.args` attribute of the exception instance and consists in a "
"list of nodes, such that each node is, in the graph, an immediate "
"predecessor of the next node in the list. In the reported list, the first "
"and the last node will be the same, to make it clear that it is cyclic."
msgstr ""
"檢測到的循環可以透過例外實例的 :attr:`~BaseException.args` 屬性中第二個元素來"
"存取,其為一個節點列表,每個節點在圖中都是列表中下一個節點的直接前驅節點"
"(immediate predecessor,即父節點)。在報告列表中,第一個和最後一個節點將會是"
"相同的,用以明確表示它是循環的。"