Rayne/wz2008-graph
Rayne/wz2008-graph
parses the "Classification of Economic Activities"
issued by the Statistisches Bundesamt.
It builds multiple hierarchically structured
and object oriented in-memory trees
from flat file structures with implicit hierarchy., (*1)
, (*2)
, (*3)
Contents
Paketbeschreibung (German)
Diese Bibliothek extrahiert die implizit vorliegende hierarchische Branchen-Struktur
aus der Klassifikation der Wirtschaftszweige, Ausgabe 2008 (WZ 2008).
Als Daten-Grundlage wird die vollstÀndige Klassifikation als XML-Datei genutzt., (*4)
Die Klassifikation der Wirtschaftszweige, Ausgabe 2008 (WZ 2008), wurde unter intensiver Beteiligung von Datennutzern und Datenproduzenten in Verwaltung, Wirtschaft, Forschung und Gesellschaft geschaffen und dient dazu, die wirtschaftlichen TĂ€tigkeiten von Unternehmen, Betrieben und anderen statistischen Einheiten in allen amtlichen Statistiken einheitlich zu erfassen. Sie berĂŒcksichtigt die Vorgaben der statistischen Systematik der Wirtschaftszweige in der EuropĂ€ischen Gemeinschaft (NACE Rev. 2), die mit der Verordnung (EG) Nr. 1893/2006 des EuropĂ€ischen Parlaments und des Rates vom 20. Dezember 2006 (ABl. EG Nr. L 393 S. 1) veröffentlicht wurde und auf der International Standard Industrial Classification (ISIC Rev. 4) der Vereinten Nationen basiert. Die Zustimmung der EuropĂ€ischen Kommission gemÀà Artikel 4, Absatz 3, der oben genannten Verordnung liegt vor., (*5)
Die Anwendung der WZ 2008 fĂŒr statistische Zwecke ergibt sich aus Artikel 8 der oben genannten Verordnung. Danach sind Statistiken, die sich auf vom 1. Januar 2008 an durchgefĂŒhrte WirtschaftstĂ€tigkeiten beziehen (Berichtsperiode), auf der Grundlage der NACE Rev. 2 (in Deutschland auf der Grundlage der WZ 2008) zu erstellen. Abweichend hiervon sind Konjunkturstatistiken gemÀà der Verordnung (EG) Nr. 1165/98 und der Arbeitskostenindex gemÀà der Verordnung (EG) Nr. 450/2003 ab dem 1. Januar 2009 auf Basis der NACE Rev. 2 (in Deutschland auf Basis der WZ 2008) zu erstellen. Die Anwendung ab 2008/2009 gilt nicht fĂŒr folgende Statistiken: Statistiken der Volkswirtschaftlichen Gesamtrechnungen gemÀà der Verordnung (EG) Nr. 2223/96, die Landwirtschaftliche Gesamtrechnung gemÀà der Verordnung (EG) Nr. 138/2004 und Statistiken der Zahlungsbilanz, des internationalen Dienstleistungsverkehrs und der Direktinvestitionen gemÀà der Verordnung (EG) Nr. 184/2005. Diese Statistiken wenden die NACE Rev. 2 / WZ 2008 ab einem spĂ€teren Zeitpunkt an., (*6)
Quelle: https://www.klassifikationsserver.de/klassService/index.jsp?variant=wz2008, (*7)
Dependencies
Production
Development
Licence
-
The library is published under the MIT licence., (*8)
-
The shipped /assets/WZ2008-[âŠ].xml
file is intellectual property of the
Statistisches Bundesamt (Federal Statistical Office), Wiesbaden, Section âClassificationsâ., (*9)
File content: Classification (complete)
Further information: https://www.klassifikationsserver.de/
Copyright: © Statistisches Bundesamt, Wiesbaden 2008 Distribution (also in parts) permitted, provided that the source is mentioned.
Owner: Issued by: Statistisches Bundesamt (Federal Statistical Office), Wiesbaden, Section âClassificationsâ, Phone.: 0611/75-2510, -2294, -2280, Fax: 0611/75-3953, E-Mail: wz@destatis.de
Type: 'ex' = Part of (see help of the classification server)
Setup
Download Composer and install rayne/wz2008-graph
., (*10)
composer require rayne/wz2008-graph
Alternatives, (*11)
Benchmarks
It is recommended to call the phpbench
program directly
instead of using the provided composer bench
script.
The latter will kill the benchmark after five minutes., (*12)
./vendor/bin/phpbench run
Tests
-
Clone the repository, (*13)
git clone https://github.com/rayne/wz2008-graph.git
-
Install the development dependencies, (*14)
composer install --dev --prefer-dist
-
Run the tests, (*15)
composer test
Usage
use Rayne\wz2008\Graph\Factory\WzClassificationFactory;
use Rayne\wz2008\Graph\WzClassificationInterface;
/**
* @var WzClassificationInterface $classification
*/
// Load the library's classification file âŠ
$classification = WzClassificationFactory::build();
// ⊠or load a custom classification file.
$classification = WzClassificationFactory::buildFromFile(
'WZ2008-2016-07-29-Classification_(complete).xml');
Search WzItem by ID
use Rayne\wz2008\Graph\WzClassificationInterface;
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzClassificationInterface $classification
* @var WzItemInterface $item
*/
$id = '26.20.0';
if ($classification->has($id)) {
$item = $classification->get($id);
}
Traverse WzItems
It's possible to traverse parents and children
relative to a given WzItemInterface
object.
Every item has a hierarchy level between 1
and 5
.
WzItemInterface
provides the following human readable constants., (*16)
DE |
EN |
Level |
Constant |
Abschnitt |
Section |
1 |
WzItemInterface::LEVEL_SECTION |
Abteilung |
Division |
2 |
WzItemInterface::LEVEL_DIVISION |
Gruppe |
Group |
3 |
WzItemInterface::LEVEL_GROUP |
Klasse |
Class |
4 |
WzItemInterface::LEVEL_CLASS |
Unterklasse |
Subclass |
5 |
WzItemInterface::LEVEL_SUBCLASS |
Traverse Parents
Fetch the direct parent or traverse one level up., (*17)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var WzItemInterface|null $parent
*/
$parent = $item->getParent();
Fetch the parent on a specific level or move up to a specific level., (*18)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var WzItemInterface|null $parent
*/
$parent = $item->getParentByLevel($item::LEVEL_SECTION);
Traverse Children
Fetch all direct children., (*19)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var WzItemInterface[] $children
*/
$children = $item->getChildren();
Fetch all children by a specific level.
Children on other levels are skipped., (*20)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var WzItemInterface[] $children
*/
$children = $item->getChildrenByLevel($item::LEVEL_CLASS);
Filter WzItems by Level
Get all WzItemInterface
items with a specific level., (*21)
use Rayne\wz2008\Graph\WzClassificationInterface;
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzClassificationInterface $classification
* @var WzItemInterface[] $sections
*/
$sections = $classification->getItemsByLevel(WzItemInterface::LEVEL_SECTION);
Get translated Labels
WzItemInterface
throws an InvalidArgumentException
when there isn't a translation for the given language code.
The official XML files are limited to DE
and EN
., (*22)
The $langCode
of WzItemInterface->getLabel($langCode)
is case-insensitive., (*23)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var string $label
*/
$label = $item->getLabel('de');
Get all translated labels and their language codes., (*24)
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
* @var string[] $labels
*/
$labels = $item->getLabels();
WzItemInterface->getLabels()
returns simple
key (language code)
value (translated label)
maps., (*25)
$labels = [
'de' => 'Wirtschafts- und ArbeitgeberverbÀnde',
'en' => 'Activities of business and employers membership organisations',
];
Get WzItem ID
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
*/
$item->getId();
Get WzItem Level
use Rayne\wz2008\Graph\WzItemInterface;
/**
* @var WzItemInterface $item
*/
$item->getLevel();
Custom Data Sets
-
Download a WZ2008-20XX-XX-XX-Classification_(complete).xml
file, (*26)
-
Visit klassifikationsserver.de/klassService/index.jsp?variant=wz2008, (*27)
-
Locate the ZIP
download in the download matrix at position, (*28)
("Klassifikation komplett", "XML (Claset)")
-
Extract the downloaded ZIP
file, (*29)
-
Use the factory to build a WzClassificationInterface
object
based upon the downloaded XML file, (*30)
use Rayne\wz2008\Graph\Factory\WzClassificationFactory;
use Rayne\wz2008\Graph\WzClassificationInterface;
/**
* @var WzClassificationInterface $classification
*/
$classification = WzClassificationFactory::buildFromFile(
'WZ2008-2016-07-29-Classification_(complete).xml');