  We have studied the high-mass star-forming complex NGC 6334 with ALMA in the
continuum emission at a frequency of 87.6 GHz, achieving a spatial resolution
of 1300 au. Detecting 142 compact sources distributed over the whole observed
area, we then used machine learning algorithms to group the compact cores in
different clusters. A total of four main clusters were identified: NGC 6334-E,
NGC 6334-I, NGC 6334-I(N) and NGC 6334-I(NW). The typical separations between
cluster members (4000-12000 au) together with the core masses (0.2-100
$M_{\odot}$) are in agreement with turbulent fragmentation at scales of 0.1 pc.
We find that the CMFs (core mass functions) show an excess of massive cores
compared to the IMF. Typical uncertainties in temperature or unresolved
multiplicity may mimic the observed excess of massive cores. Evidence of mass
segregation in NGC 6334-I and NGC 6334-I(N), with the most massive cores
located closer to the center, was found. Correlations between the physical
properties of the clusters and their evolutionary stage were searched for, and
found to show a larger separation between cores in the more evolved clusters,
favouring the role of gas expulsion and stellar ejection over time. From these
results, we suggest that NGC 6334-I(N) was primordially segregated, while NGC
6334-I may have become mass-segregated over time due to dynamical effects.
Finally, the lack of massive cores in the most evolved cluster suggests that
the gas reservoir may be already exhausted, while the less evolved clusters
still have access to a larger gas mass reservoir. In general, the fragmentation
in NGC 6334 at large scales (about 1 pc) is governed by turbulent pressure,
while at smaller scales (a few hundred au), thermal pressure regulates the
fragmentation process.
