コード例 #1
0
ファイル: datasets.py プロジェクト: ebengtsson/definitions
def nationalities():
    graph = Graph()
    items = decorate(
        read_csv(scriptpath('source/nationalitetskoder.tsv'),
                 encoding='latin-1'), {
                     "@id": BASE + "nationality/{code}",
                     "@type": 'Nationality'
                 })
    to_rdf(items,
           graph,
           context_data=[
               scriptpath("sys/context/base.jsonld"), {
                   "label_sv": {
                       "@id": "rdfs:label",
                       "@language": "sv"
                   }
               }
           ])
    return "/nationality/", build_jsonld(graph)
コード例 #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
ファイル: 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)
コード例 #4
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)