コード例 #1
0
ファイル: datasets.py プロジェクト: ebengtsson/definitions
def vocab():
    graph = construct(compiler.cached_rdf,
                      sources=[{
                          'source':
                          Graph().parse(scriptpath('source/vocab/index.ttl'),
                                        format='turtle'),
                          'dataset':
                          '?'
                      }, {
                          "source":
                          "http://id.loc.gov/ontologies/bibframe/"
                      }],
                      query=scriptpath("source/vocab/bf-to-kbv-base.rq"))

    for part in (SCRIPT_DIR / 'source/vocab').glob('**/*.ttl'):
        graph.parse(str(part), format='turtle')

    graph.update((SCRIPT_DIR / 'source/vocab/update.rq').read_text())

    data = build_jsonld(graph)

    lib_context = make_context(graph, BASE + 'vocab/', DEFAULT_NS_PREF_ORDER)
    add_overlay(lib_context, load_json(scriptpath('sys/context/base.jsonld')))
    add_overlay(lib_context,
                load_json(scriptpath('source/vocab-overlay.jsonld')))
    lib_context['@graph'] = [{'@id': BASE + 'vocab/context'}]

    compiler.write(lib_context, 'vocab/context')

    return "/vocab", data
コード例 #2
0
ファイル: datasets.py プロジェクト: ebengtsson/definitions
def countries():
    graph = construct(
        compiler.cached_rdf,
        sources=[
            {
                "source":
                decorate(read_csv(scriptpath('source/landskoder.tsv')),
                         {"@id": BASE + "country/{code}"}),
                "dataset":
                BASE + "dataset/countries",
                # TODO: fix rdflib_jsonld so urls in external contexts are loaded
                "context":
                load_json(
                    scriptpath("source/table-context.jsonld"))['@context']
            },
            {
                "source": "http://id.loc.gov/vocabulary/countries"
            }
        ],
        query=scriptpath("source/construct-countries.rq"))
    return "/country/", build_jsonld(graph)
コード例 #3
0
def vocab():
    graph = construct(compiler.cached_rdf,
                      sources=[{
                          'source':
                          Graph().parse(scriptpath('source/vocab/bf-map.ttl'),
                                        format='turtle'),
                          'dataset':
                          '?'
                      }, {
                          "source":
                          "http://id.loc.gov/ontologies/bibframe/"
                      }],
                      query=scriptpath("source/vocab/bf-to-kbv-base.rq"))

    for part in (SCRIPT_DIR / 'source/vocab').glob('**/*.ttl'):
        graph.parse(str(part), format='turtle')

    #cg = ConjunctiveGraph()
    #cg.parse(str(SCRIPT_DIR/'source/vocab/display.jsonld'), format='json-ld')
    #graph += cg

    graph.update((SCRIPT_DIR / 'source/vocab/update.rq').read_text())

    data = build_jsonld(graph)
    del data['@context']

    version = _get_repo_version()
    if version:
        data['@graph'][0]['version'] = version

    lib_context = make_context(graph, BASE + 'vocab/', DEFAULT_NS_PREF_ORDER)
    add_overlay(lib_context, load_json(scriptpath('sys/context/base.jsonld')))
    add_overlay(lib_context,
                load_json(scriptpath('source/vocab-overlay.jsonld')))
    lib_context['@graph'] = [{'@id': BASE + 'vocab/context'}]

    compiler.write(lib_context, 'vocab/context')
    compiler.write(load_json(str(SCRIPT_DIR / 'source/vocab/display.jsonld')),
                   'vocab/display')
    compiler.write(data, "vocab")
コード例 #4
0
ファイル: datasets.py プロジェクト: ebengtsson/definitions
def languages():
    loclangpath, fmt = compiler.get_cached_path(
        "loc-language-data.ttl"), 'turtle'
    loclanggraph = Graph()
    if not Path(loclangpath).exists():
        # More than <http://id.loc.gov/vocabulary/iso639-*> but without inferred SKOS
        cherry_pick_loc_lang_data = (
            SCRIPT_DIR / 'source/construct-loc-language-data.rq').read_text()
        loclanggraph += _get_zipped_graph(
            compiler.cache_url(
                'http://id.loc.gov/static/data/vocabularyiso639-1.ttl.zip'),
            'iso6391.ttl').query(cherry_pick_loc_lang_data)
        loclanggraph += _get_zipped_graph(
            compiler.cache_url(
                'http://id.loc.gov/static/data/vocabularyiso639-2.ttl.zip'),
            'iso6392.ttl').query(cherry_pick_loc_lang_data)
        loclanggraph.serialize(loclangpath, format=fmt)
    else:
        loclanggraph.parse(loclangpath, format=fmt)

    languages = decorate(read_csv(scriptpath('source/spraakkoder.tsv')),
                         {"@id": BASE + "language/{code}"})

    graph = construct(
        compiler.cached_rdf,
        sources=[{
            "source":
            languages,
            "dataset":
            BASE + "dataset/languages",
            "context":
            load_json(scriptpath("source/table-context.jsonld"))['@context']
        }, {
            "source": loclanggraph,
            "dataset": "http://id.loc.gov/vocabulary/languages"
        }],
        query=scriptpath("source/construct-languages.rq"))

    return "/language/", build_jsonld(graph)
コード例 #5
0
ファイル: datasets.py プロジェクト: ebengtsson/definitions
def relators():
    def relitem(item):
        mk_uri = lambda leaf: BASE + "relator/" + leaf
        item['@id'] = mk_uri(
            item.get('term') or to_camel_case(item['label_en'].strip()))
        item['sameAs'] = {'@id': mk_uri(item['code'])}
        return item

    graph = construct(
        compiler.cached_rdf,
        sources=[{
            "source":
            map(relitem, read_csv(scriptpath('source/funktionskoder.tsv'))),
            "dataset":
            BASE + "dataset/relators",
            "context": [
                scriptpath("sys/context/ns.jsonld"), {
                    "code": "skos:notation",
                    "label_sv": {
                        "@id": "skos:prefLabel",
                        "@language": "sv"
                    },
                    "label_en": {
                        "@id": "skos:prefLabel",
                        "@language": "en"
                    },
                    "comment_sv": {
                        "@id": "rdfs:comment",
                        "@language": "sv"
                    },
                    "term": "rdfs:label",
                    "sameAs": "owl:sameAs"
                }
            ]
        }, {
            "source": "http://id.loc.gov/vocabulary/relators"
        }],
        query=scriptpath("source/construct-relators.rq"))
    return "/relator/", build_jsonld(graph)