Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into datalaoder-sma…
Browse files Browse the repository at this point in the history
…ll-fix
  • Loading branch information
root committed Jun 1, 2024
2 parents 44dd9d7 + bcb6c1d commit 8aec732
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 290 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ add-sources:
@docker exec -ti dataloader bash -c "invoke add-sources"

clean-db:
@docker exec -t dataloader bash -c "invoke clean-all-collections"
@docker exec -t dataloader bash -c "invoke clean-all"
@docker exec -t dataloader bash -c "invoke create-db create-collections"

# these commands are for loading individual datasets asynchronously
Expand Down
9 changes: 6 additions & 3 deletions api/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def calculate_color_maps_table_view(data):
par_colormap[par_start:par_end] = [1] * (par_end - par_start)
par_fulltext = create_segmented_text_color_only(par_fulltext, par_colormap)
entry["par_fulltext"] = par_fulltext
entry["par_segnr"] = shorten_segment_names(entry["par_segnr"])
entry["root_segnr"] = shorten_segment_names(entry["root_segnr"])
entry["par_segnr_range"] = shorten_segment_names(entry["par_segnr"])
entry["root_segnr_range"] = shorten_segment_names(entry["root_segnr"])
entry["score"] = prettify_score(entry["score"])
del entry["par_segment"]
del entry["root_seg_text"]
Expand All @@ -156,6 +156,8 @@ def calculate_color_maps_table_view(data):
del entry["par_offset_beg"]
del entry["par_offset_end"]
del entry["par_pos_beg"]
del entry["par_segnr"]
del entry["root_segnr"]
return data


Expand All @@ -179,9 +181,10 @@ def calculate_color_maps_middle_view(data):
par_fulltext = create_segmented_text_color_only(par_fulltext, par_colormap)
entry["par_fulltext"] = par_fulltext
entry["score"] = prettify_score(entry["score"])
entry["par_segnr"] = shorten_segment_names(entry["par_segnr"])
entry["par_segnr_range"] = shorten_segment_names(entry["par_segnr"])
del entry["par_offset_beg"]
del entry["par_offset_end"]
del entry["par_segnr"]
return data


Expand Down
64 changes: 61 additions & 3 deletions api/endpoints/graph_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,71 @@
@router.post("/graph-view/", response_model=GraphViewOutput)
async def get_graph_for_file(input: GraphInput) -> Any:
"""
Endpoint for graph view
Endpoint for graph view.
Input fields are:
```
{
"file_name": "",
"score": 0,
"par_length": 0,
"target_collection": []
}
```
The "target_collection" input comes from a dropdown list that lists collections only.
This comes from the `/menus/graphcollections/` endpoint. It is possible to choose
more than one option, hence it is a list. F.i.
```
...
"target_collection": ["pli_Suttas-Early-1", "pli_Vinaya"]
```
"score", "par_length" and "file_name" are the same as for the other views.
Output is f.i.:
```
{
"piegraphdata": [
[
"dn Dīghanikāya",
"62063"
],
[
"mn Majjhimanikāya",
"54783"
],
[
"an Aṅguttaranikāya",
"24871"
],
...
]
],
"histogramgraphdata": [
[
"Kūṭadanta Sutta (Dn 5)",
"36982"
],
[
"Caṅkī Sutta (Mn 95)",
"19661"
],
[
"Bhesajjakkhandhaka (Pli-tv-kd 6)",
"7773"
],
etc.
```
"""

target_collection = create_cleaned_limit_collection(input.target_collection)

print(target_collection)

query_graph_result = execute_query(
graph_view_queries.QUERY_GRAPH_VIEW,
bind_vars={
Expand Down
75 changes: 75 additions & 0 deletions api/endpoints/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ async def get_categories_for_filter_menu(
) -> Any:
"""
Given a language, return list of categories for the filter menu
in text view, table view and numbers view.
Input is the language string like "pli".
Output is:
```
{
"categoryitems": [
{
"category": "pli_Suttas-Early-1",
"categoryname": "SUTTAS-EARLY-1 (ALL)"
},
{
"category": "dn",
"categoryname": "• Dīghanikāya (DN)"
},
{
"category": "mn",
"categoryname": "• Majjhimanikāya (MN)"
},
etc.
```
Where "category" is the value that needs to be returns to the backend once
selected and "categoryname" is what displays in the dropdown menu:
```
SUTTAS-EARLY-1 (ALL)
• Dīghanikāya (DN)
• Majjhimanikāya (MN)
etc.
```
"""
query_result = execute_query(
menu_queries.QUERY_CATEGORIES_FOR_LANGUAGE,
Expand Down Expand Up @@ -92,3 +125,45 @@ async def get_data_for_sidebar_menu(

query_sidebar_menu = execute_query(menu_query, current_bind_vars)
return {"navigationmenudata": query_sidebar_menu.result}


@router.get("/graphcollections/", response_model=GraphCollectionOutput)
async def get_categories_for_filter_menu(
language: str = Query(..., description="language to be used")
) -> Any:
"""
Given a language, return list of collections for the filter menu
of graph view and the input menus of the visual view.
Input is the language string like "pli".
Output is:
```
{
"result": [
{
"collection": "pli_Suttas-Early-1",
"collectiondisplayname": "Suttas-Early-1"
},
{
"collection": "pli_Suttas-Early-2",
"collectiondisplayname": "Suttas-Early-2"
},
etc.
```
Where "collection" is the value that needs to be returns to the backend once
selected and "collectiondisplayname" is what displays in the dropdown menu:
```
Suttas-Early-1
Suttas-Early-2
Suttas-Late-1
etc.
```
"""
query_result = execute_query(
menu_queries.QUERY_COLLECTIONS_FOR_LANGUAGE, bind_vars={"language": language}
)
return {"result": query_result.result[0]}
6 changes: 1 addition & 5 deletions api/endpoints/models/graph_view_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from pydantic import BaseModel
from typing import List, Dict, Tuple, Union

"""
THE GRAPH VIEW IS NOT WORKING. NEEDS TOTAL REVAMP!
"""
from typing import List, Union


class GraphInput(BaseModel):
Expand Down
9 changes: 9 additions & 0 deletions api/endpoints/models/menus_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ class SideBar(BaseModel):

class SideBarOutput(BaseModel):
navigationmenudata: List[SideBar]


class GraphCollection(BaseModel):
collection: Union[str, None] = None
collectiondisplayname: Union[str, None] = None


class GraphCollectionOutput(BaseModel):
result: List[GraphCollection]
14 changes: 2 additions & 12 deletions api/endpoints/models/table_view_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


class Segment(BaseModel):
par_segnr: str
par_segnr_range: str
par_full_names: FullNames
root_full_names: FullNames
file_name: str
root_segnr: str
root_segnr_range: str
par_length: int
root_length: int
score: int
Expand All @@ -28,13 +28,3 @@ class TableDownloadInput(GeneralInput):

class TableDownloadOutput(BaseModel):
__root__: str


# Is this still needed as the function doesn't seem to exist any more?

# class MultiLangInput(BaseModel):
# file_name: str
# score: int = 0
# multi_lingual: list = []
# page: int = 0
# folio: str = ""
2 changes: 1 addition & 1 deletion api/endpoints/models/text_view_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextViewMiddleInput(BaseModel):


class Segment(BaseModel):
par_segnr: str
par_segnr_range: str
display_name: Union[str, None] = None
tgt_lang: str
par_offset_beg: Optional[int]
Expand Down
11 changes: 11 additions & 0 deletions api/endpoints/models/visual_view_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pydantic import BaseModel
from typing import List, Union


class VisualViewInput(BaseModel):
inquiry_collection: str = ""
hit_collections: list = []


class VisualViewOutput(BaseModel):
__root__: List[List[Union[str, str, int]]]
21 changes: 0 additions & 21 deletions api/endpoints/table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,3 @@ async def get_table_download(input: TableDownloadInput) -> Any:
)

return


# The below function doesn't seem to be used any more!

# @router.post("/multilang/", response_model=TableViewOutput)
# async def get_multilang(input: MultiLangInput) -> Any:
# """
# Endpoint for the multilingual table view. Accepts Parallel languages
# :return: List of segments and parallels for the table view.
# """
# query_result = execute_query(
# table_view_queries.QUERY_MULTILINGUAL,
# bind_vars={
# "file_name": input.file_name,
# "multi_lingual": input.multi_lingual,
# "page": input.page,
# "score": input.score,
# "folio": input.folio,
# },
# )
# return query_result.result
Loading

0 comments on commit 8aec732

Please sign in to comment.