Convert Finnish library YKL classification XML dump to a text file.
Usage:
$ wget http://ykl.kirjastot.fi/YKL/File/YKL_20140901_041500_fi-FI.xml $ python yklXml2txt.py YKL*.xml|tee ykl.txt
The 11 MB XML file is not human readable. The XML dump is converted to human
readable text file that has class number and name, one class per line. Other
data in XML dump is ignored. The text file is human readable and small (<100 kB).
Example of output text:
02 KIRJASTOTOIMI. KIRJASTOTIEDE. INFORMATIIKKA 02.1 Kirjastojen hallinto ja suunnittelu 02.3 Kirjastonhoito. Kirjastotekniikka 02.31 Kirjastoautomaatio
Currently, the XML file is available in Finnish[2] but not in English[3].
The license of the XML dump (and thus, the converted text file) is
CC-by-sa [2][4]. This can considerably limit using the YKL classification.
The YKL classification is also browsable in the web in Finnish [5] and in
English [6].
[1] http://ykl.kirjastot.fi/YKL/File/YKL_20140901_041500_fi-FI.xml
[2] http://ykl.kirjastot.fi/fi-FI/ohje/
[3] http://ykl.kirjastot.fi/en-GB/ohje
[4] https://creativecommons.org/licenses/by-sa/3.0/
[5] http://ykl.kirjastot.fi/fi-FI/paaluokat/
[6] http://ykl.kirjastot.fi/en-GB/paaluokat/
yklXml2txt.py Copyright 2014 Tero Karvinen http://TeroKarvinen.com
GNU General Public License, version 3 or later
Download YKL classification as text – ykl.txt
# Finnish Public Libraries Classification System - Yleisten kirjastojen luokitusjärjestelmä # ykl.txt generated with yklXml2txt.py by Tero Karvinen # Dump license CC-by-sa, copyright 2014 OKM / Kirjastot.fi # Converted from http://ykl.kirjastot.fi/YKL/File/YKL_20140901_041500_fi-FI.xml 0 YLEISTEOKSET. KIRJA-ALA. KIRJASTOTOIMI YLEINEN KULTTUURIPOLITIIKKA. JOUKKOTIEDOTUS 00 KIRJA-ALA 00.1 Kirjoitus 00.109 Kirjoituksen historia. Paleografia. Epigrafia 00.2 Symbolit. Koodit. Merkkijärjestelmät 00.4 Kirjapainotaito. Graafinen teollisuus [...]
Download converter – yklXml2txt.py
#!/usr/bin/python
# Copyright 2014 Tero Karvinen http://TeroKarvinen.com
"""yklXml2txt converts Finnish library YKL classification XML dump to a text file.
Usage:
$ wget http://ykl.kirjastot.fi/YKL/File/YKL_20140901_041500_fi-FI.xml
$ python yklXml2txt.py YKL*.xml|tee ykl.txt
The 11 MB XML file[1] is not human readable. The XML dump is converted to human
readable text file that has class number and name, one class per line. Other
data in XML dump is ignored. The text file is human readable and small (<100 kB).
Example of output text:
02 KIRJASTOTOIMI. KIRJASTOTIEDE. INFORMATIIKKA
02.1 Kirjastojen hallinto ja suunnittelu
02.3 Kirjastonhoito. Kirjastotekniikka
02.31 Kirjastoautomaatio
Currently, the XML file is available in Finnish[2] but not in English[3].
The license of the XML dump (and thus, the converted text file) is
CC-by-sa [2][4]. This can considerably limit using the YKL classification.
The YKL classification is also browsable in the web in Finnish [5] and in
English [6].
[1] http://ykl.kirjastot.fi/YKL/File/YKL_20140901_041500_fi-FI.xml
[2] http://ykl.kirjastot.fi/fi-FI/ohje/
[3] http://ykl.kirjastot.fi/en-GB/ohje
[4] https://creativecommons.org/licenses/by-sa/3.0/
[5] http://ykl.kirjastot.fi/fi-FI/paaluokat/
[6] http://ykl.kirjastot.fi/en-GB/paaluokat/
yklXml2txt.py Copyright 2014 Tero Karvinen http://TeroKarvinen.com
GNU General Public License, version 3 or later
"""
import sys
sys.path.insert(0, "../lib/")
from lxml import etree
import argparse
from lxml.cssselect import CSSSelector
from argparse import RawTextHelpFormatter
def parseArgs(argv):
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=RawTextHelpFormatter)
parser.add_argument("xmlfile",
default= "ykl.xml",
help="Input XML file")
return parser.parse_args(argv)
def main(argv):
global logger, d, v
args = parseArgs(argv)
root = etree.root = etree.parse(args.xmlfile)
sel = CSSSelector('ykl classes class, ykl classes class') # ykl classes class name
for e in sel(root):
yc={} # single numbered class in YKL, eg. "78.356 Pelimusiikki"
for x in e.getchildren():
yc[x.tag]=x.text
s = u"%s %s" % (yc["number"], yc["name"])
print s.encode("utf8")
if __name__ == '__main__':
main(sys.argv[1:])