Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions units/concepts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from functools import partial
from itertools import groupby
from typing import Optional

import structlog
import httpx
import structlog
from pydantic import BaseModel

from units.settings import get_settings

Expand Down Expand Up @@ -112,10 +114,27 @@ def get_all_data_for_qk_iri(
lang_checker = partial(language_filter, lang=lang.lower() if lang else None)

return {
key: [
reformat_predicate_object(obj, remove_namespaces=remove_namespaces)
for obj in group
if lang_checker(obj["o"])
]
key: {
(
remove_graph_namespaces(obj_key) if remove_namespaces else obj_key
): format_objects(obj, lang)
for obj_key, obj in groupby(group, key=lambda x: x["p"]["value"])
}
for key, group in groupby(results, key=lambda x: x["s"]["value"])
}


def format_objects(obj, lang: Optional[str] = None):
l = list(
map(
lambda x: x["o"]["value"],
filter(
lambda x: "xml:lang" not in x["o"] or language_filter(x["o"], lang),
obj,
),
)
)
if len(l) == 0:
return None
return l if len(l) > 1 else l[0]

1 change: 0 additions & 1 deletion units/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import uvicorn
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI

from starlette.middleware.cors import CORSMiddleware

from units.routes import router
Expand Down
4 changes: 2 additions & 2 deletions units/routes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from fastapi import APIRouter, Depends, Request, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import JSONResponse
from fastapi_versioning import version

from units.concepts import get_all_data_for_qk_iri, get_qk_for_iri
from units.schema import VersionResponse
from units.concepts import get_qk_for_iri, get_all_data_for_qk_iri

router = APIRouter()

Expand Down