Beispiel #1
0
def concepts(vocab_id):
    return "/concept/"

    # check the vocab id is valid
    vocab_ids = {}
    for x in g.VOCABS.keys():
        vocab_ids[x.split("#")[-1].split("/")[-1]] = x

    if vocab_id not in vocab_ids.keys():
        msg = "The vocabulary ID that was supplied was not known. " \
              "It must be one of these: {}".format(", ".join(vocab_ids.keys()))
        return Response(msg, status=400, mimetype="text/plain")

    try:
        vocab_source = getattr(source, g.VOCABS[vocab_id].source)(vocab_id,
                                                                  request)
        concepts = vocab_source.list_concepts()
        # concepts.sort(key=lambda x: x["prefLabel"]) -- sort not needed when receiving pre-sorted tuples
        total = len(concepts)

        page = (int(request.values.get("page"))
                if request.values.get("page") is not None else 1)
        per_page = (int(request.values.get("per_page"))
                    if request.values.get("per_page") is not None else 20)
        start = (page - 1) * per_page
        end = start + per_page
        members = concepts[start:end]
    except Exception as e:
        return Response(str(e), status=500, mimetype="text/plain")

    return ContainerRenderer(request, url_for("concepts", vocab_id=vocab_id),
                             "All Concepts",
                             'All Concepts within Vocab {}'.format(vocab_id),
                             None, None, members, total).render()
Beispiel #2
0
def concepts(vocab_id):
    if vocab_id not in [x.id for x in g.VOCABS.values()]:
        return return_vocprez_error(
            "vocab_id not valid", 400,
            markdown.markdown(
                "The 'vocab_id' you supplied, {}, is not known. Valid vocab_ids are:\n\n{}"
                .format(
                    vocab_id, "\n".join([
                        "* [{}]({}): {}".format(x.id, u.get_content_uri(x.uri),
                                                x.title)
                        for x in g.VOCABS.values()
                    ]))))

    try:
        vocab_source = getattr(source, g.VOCABS[vocab_id].source)(vocab_id,
                                                                  request)
        cpts = vocab_source.list_concepts()
        # concepts.sort(key=lambda x: x["prefLabel"]) -- sort not needed when receiving pre-sorted tuples
        total = len(cpts)

        page = (int(request.values.get("page"))
                if request.values.get("page") is not None else 1)
        per_page = (int(request.values.get("per_page"))
                    if request.values.get("per_page") is not None else 20)
        start = (page - 1) * per_page
        end = start + per_page
        members = cpts[start:end]
    except Exception as e:
        return Response(str(e), status=500, mimetype="text/plain")

    return ContainerRenderer(request, url_for("concepts", vocab_id=vocab_id),
                             "All Concepts",
                             'All Concepts within Vocab {}'.format(vocab_id),
                             None, None, members, total).render()
Beispiel #3
0
def vocabularies():
    page = (int(request.values.get("page"))
            if request.values.get("page") is not None else 1)
    per_page = (int(request.values.get("per_page"))
                if request.values.get("per_page") is not None else 20)

    # get this instance's list of vocabs
    vocabs = list(g.VOCABS.keys())

    # respond to a filter
    if request.values.get("filter") is not None:
        vocabs = [
            v for v in vocabs
            if request.values.get("filter").lower() in g.VOCABS[v].id.lower()
            or request.values.get("filter").lower() in
            g.VOCABS[v].title.lower() or request.values.get(
                "filter").lower() in g.VOCABS[v].description.lower()
        ]

    vocabs = [(url_for("object", uri=v), g.VOCABS[v].title) for v in vocabs]
    vocabs.sort(key=lambda tup: tup[1])
    total = len(vocabs)
    start = (page - 1) * per_page
    end = start + per_page
    vocabs = vocabs[start:end]

    return ContainerRenderer(
        request, config.VOCS_URI
        if hasattr(config, "VOCS_URI") else url_for("vocabularies"),
        config.VOCS_TITLE if hasattr(config, "VOCS_TITLE") else 'Vocabularies',
        config.VOCS_DESC if hasattr(config, "VOCS_DESC") else None, None, None,
        vocabs, total).render()
def roads():
    # Search specific items using keywords
    search_string = request.values.get('search')

    try:

        # get the register length from the online DB
        sql = 'SELECT COUNT(*) FROM "transportroads"'
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("name") LIKE '%{search_string}%';
                   '''.format(search_string=search_string.strip().upper())

        no_of_items = conf.db_select(sql)[0][0]

        page = int(request.values.get('page')) if request.values.get(
            'page') is not None else 1
        per_page = int(request.values.get('per_page')) \
                   if request.values.get('per_page') is not None else DEFAULT_ITEMS_PER_PAGE
        offset = (page - 1) * per_page

        # get the id and name for each record in the database
        sql = '''SELECT "id", "name" FROM "transportroads"'''
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("name") LIKE '%{search_string}%'
                   '''.format(search_string=search_string.strip().upper())
        sql += '''ORDER BY "name"
                OFFSET {} LIMIT {}'''.format(offset, per_page)

        items = []
        for item in conf.db_select(sql):
            items.append((item[0], item[1]))
    except Exception as e:
        print(e)
        return Response('The Roads database is offline',
                        mimetype='text/plain',
                        status=500)

    return ContainerRenderer(
        request=request,
        instance_uri=request.url,
        label='Roads Register',
        comment='A register of Roads',
        parent_container_uri=
        'http://linked.data.gov.au/def/placenames/PlaceName',
        parent_container_label='QLD_Roads',
        members=items,
        members_total_count=no_of_items,
        profiles=None,
        default_profile_token=None,
        super_register=None,
        page_size_max=1000,
        register_template=None,
        per_page=per_page,
        search_query=search_string,
        search_enabled=True).render()
Beispiel #5
0
def get_register_items():
    # Search specific items using keywords
    search_string = request.values.get('search')
    try:
        # get the register length from the online DB
        # sql = 'SELECT COUNT(*) FROM "AEIP_SA1join84"'
        sql = 'SELECT COUNT(*) FROM "{table}"'.format(table=TABLE_NAME)
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("{name}") LIKE '%{search_string}%';
                   '''.format(name=NAME_FIELD, search_string=search_string.strip().upper())

        no_of_items = conf.db_select(sql)[0][0]

        page = int(request.values.get('page')) if request.values.get('page') is not None else 1
        per_page = int(request.values.get('per_page')) \
                   if request.values.get('per_page') is not None else DEFAULT_ITEMS_PER_PAGE
        offset = (page - 1) * per_page

        # get the id and name for each record in the database
        sql = '''SELECT "id", "{name}" FROM "{table}"'''.format(name=NAME_FIELD, table=TABLE_NAME)
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("{name}") LIKE '%{search_string}%'
                   '''.format(name=NAME_FIELD, search_string=search_string.strip().upper())
        sql += '''ORDER BY "{name}"
                OFFSET {offset} LIMIT {per_page}'''.format(name=NAME_FIELD, offset=offset, per_page=per_page)

        items = []
        for item in conf.db_select(sql):
            items.append(
                (item[0], item[1])
            )
    except Exception as e:
        print(e)
        return Response('The database is offline', mimetype='text/plain', status=500)

    return ContainerRenderer(request=request,
                            instance_uri=request.url,
                            label='SA1 with AEIP Register',
                            comment='A register of SA1s with info from AEIP (Australian Exposure Information Platform)',
                            parent_container_uri='http://linked.data.gov.au/def/placenames/PlaceName',
                            parent_container_label='SA1',
                            members=items,
                            members_total_count=no_of_items,
                            profiles=None,
                            default_profile_token=None,
                            super_register=None,
                            page_size_max=1000,
                            register_template=None,
                            per_page=per_page,
                            search_query=search_string,
                            search_enabled=True
                            ).render()
Beispiel #6
0
def collections():
    collections = get_collections()
    return ContainerRenderer(
        request,
        "https://w3id.org/dggs/tb16pix/grid/",
        "Collections",
        "DGGs are made of hierarchical layers of Cell geometries. In TB16Pix, these layers are called Grids. "
        "Additionally, this API delivers TB16Pix Zones in Collections too.",
        "https://w3id.org/dggs/tb16pix",
        "TB16Pix Dataset",
        collections,
        len(collections)
    ).render()
Beispiel #7
0
def vocabularies():
    page = (int(request.values.get("page"))
            if request.values.get("page") is not None else 1)
    per_page = (int(request.values.get("per_page"))
                if request.values.get("per_page") is not None else 20)
    #
    # # TODO: replace this logic with the following
    # #   1. read all static vocabs from g.VOCABS
    # get this instance's list of vocabs
    vocabs = []  # local copy (to this request) for sorting
    for k, voc in g.VOCABS.items():
        vocabs.append((url_for("routes.vocabulary", vocab_id=k), voc.title))
    vocabs.sort(key=lambda tup: tup[1])
    total = len(g.VOCABS.items())
    #
    # # Search
    # query = request.values.get("search")
    # results = []
    # if query:
    #     for m in match(vocabs, query):
    #         results.append(m)
    #     vocabs[:] = results
    #     vocabs.sort(key=lambda v: v.title)
    #     total = len(vocabs)
    #
    # # generate vocabs list for requested page and per_page
    start = (page - 1) * per_page
    end = start + per_page
    vocabs = vocabs[start:end]
    #
    # # render the list of vocabs
    # return SkosRegisterRenderer(
    #     request,
    #     [],
    #     vocabs,
    #     "Vocabularies",
    #     total,
    #     search_query=query,
    #     search_enabled=True,
    #     vocabulary_url=["http://www.w3.org/2004/02/skos/core#ConceptScheme"],
    # ).render()

    return ContainerRenderer(
        request, 'https://vocab.gsq/digital/vocabulary/', 'Vocabularies',
        'Vocabularies published by the Geological Survey of Queensland', None,
        None, vocabs, total).render()
Beispiel #8
0
def vocabularies():
    page = (int(request.values.get("page"))
            if request.values.get("page") is not None else 1)
    per_page = (int(request.values.get("per_page"))
                if request.values.get("per_page") is not None else 20)

    vocabs = []  # local copy (to this request) for sorting

    # get this instance's list of vocabs
    for k, voc in g.VOCABS.items():
        # respond to a filter
        if request.values.get("filter") is not None:
            if request.values.get("filter") in voc.title:
                vocabs.append((url_for("object", uri=k), voc.title))
        else:
            # no filter: list all
            vocabs.append((url_for("object", uri=k), voc.title))
    vocabs.sort(key=lambda tup: tup[1])
    total = len(vocabs)
    #
    # # Search
    # query = request.values.get("search")
    # results = []
    # if query:
    #     for m in match(vocabs, query):
    #         results.append(m)
    #     vocabs[:] = results
    #     vocabs.sort(key=lambda v: v.title)
    #     total = len(vocabs)
    #
    # # generate vocabs list for requested page and per_page
    start = (page - 1) * per_page
    end = start + per_page
    vocabs = vocabs[start:end]

    return ContainerRenderer(
        request, config.VOCS_URI
        if config.VOCS_URI is not None else url_for("vocabularies"),
        config.VOCS_TITLE if config.VOCS_TITLE is not None else 'Vocabularies',
        config.VOCS_DESC if config.VOCS_DESC is not None else None, None, None,
        vocabs, total).render()
Beispiel #9
0
def mediatypes():
    per_page = request.args.get("per_page", type=int, default=20)
    page = request.args.get("page", type=int, default=1)

    total = s.total_mediatypes()
    if total is None:
        return Response("_data store is unreachable", status=500, mimetype="text/plain")

    # get list of org URIs and labels from the triplestore
    q = """
        PREFIX dct: <http://purl.org/dc/terms/>
        SELECT ?uri ?title
        WHERE {{
            ?uri a dct:FileFormat ;
                 dct:title ?title .
        }}
        ORDER BY ?title
        LIMIT {}
        OFFSET {}
    """.format(
        per_page, (page - 1) * per_page
    )

    register = []
    for r in s.sparql_query(q):
        register.append((url_for("controller.object") + "?uri=" + str(r[0]), str(r[1])))

    return ContainerRenderer(
        request,
        "https://mediatypes.conneg.info/mediatype/",
        "Register of Media Types",
        "All the Media Types in IANA's list at <code>https://www.iana.org/assignments/media-types/media-types.xml.</code>",
        "https://mediatypes.conneg.info/reg/",
        "MediaTypes Service",
        register,
        total,
    ).render()
Beispiel #10
0
def agents():
    per_page = request.args.get("per_page", type=int, default=20)
    page = request.args.get("page", type=int, default=1)

    total = s.total_mediatypes()
    if total is None:
        return Response("_data store is unreachable", status=500, mimetype="text/plain")

    # get list of org URIs and labels from the triplestore
    q = """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
        SELECT ?uri ?name
        WHERE {{
            ?uri a foaf:Agent ;
                 foaf:name ?name .
        }}
        ORDER BY ?name
    """.format(
        per_page, (page - 1) * per_page
    )

    register = []
    for r in s.sparql_query(q):
        register.append((str(r[0]), str(r[1])))

    return ContainerRenderer(
        request,
        "http://localhost:5000/person/",
        "Register of Agents",
        "People and Organizations who have registered Media Types",
        "http://localhost:5000/reg/",
        "MediaTypes Service",
        register,
        total,
    ).render()
def container_response(container_uri, container_name, members):
    return ContainerRenderer(request, container_uri,
                             'Container of ' + container_name,
                             'Queensland\'s geological ' + container_name,
                             config.DATASET_URI, config.DATASET_LABEL, members,
                             len(members)).render()
Beispiel #12
0
    comment=
    "Schema.org is a collaborative, community activity with a mission to create, maintain, and promote schemas "
    "for structured data on the Internet, on web pages, in email messages, and beyond.",
    mediatypes=RDF_MEDIATYPES,
    default_mediatype="text/turtle",
    languages=["en"],
    default_language="en",
)

cr = ContainerRenderer(
    req,
    "http://example.com",
    "Dummy Label",
    "Dummy Comment",
    None,
    None,
    [
        ("http://example.com/one", "One"),
        ("http://example.com/two", "Two"),
        ("http://example.com/three", "Three"),
        ("http://example.com/four", "Four"),
        ("http://example.com/five", "Five"),
    ],
    60,
    None,
    profiles={"sdo": sdo},
    default_profile_token="sdo",
)

txt = cr._render_mem_profile_html()
print(txt.body.decode())