API Server¶
The API server is written in Python using the Flask framework.
{arguments} [error opening dir]
Server directory structure¶
server.main¶
The API server for CBGM. The main functions.
- apparatus_json(passage_or_id)¶
The contents of the apparatus table.
- application_json()¶
Endpoint. Serve information about the application.
- attestation_json(passage_or_id)¶
Answer with a list of the attestations of all manuscripts at one specified passage.
- attesting_csv(passage_or_id, labez)¶
Serve all relatives of all mss. attesting labez at passage.
- cliques_json(passage_or_id)¶
Endpoint. Serve all cliques found in a passage.
- Parameters
passage_or_id (string) – The passage id.
- init_app(app)¶
Initialize the flask app.
- leitzeile_json(passage_or_id)¶
Endpoint. Serve the leitzeile for the verse containing passage_or_id.
- manuscript_full_json(passage_or_id, hs_hsnr_id)¶
Endpoint. Serve information about a manuscript.
- Parameters
hs_hsnr_id (string) – The hs, hsnr or id of the manuscript.
- manuscript_json(hs_hsnr_id)¶
Endpoint. Serve information about a manuscript.
- Parameters
hs_hsnr_id (string) – The hs, hsnr or id of the manuscript.
- passage_json(passage_or_id=None)¶
Endpoint. Serve information about a passage.
Return information about a passage or navigate to it.
- Parameters
passage_or_id (string) – The passage id.
siglum (string) – The siglum of the book to navigate to.
chapter (string) – The chapter to navigate to.
verse (string) – The verse to navigate to.
word (string) – The word (range) to navigate to.
button (string) – The button pressed.
- ranges_json()¶
Endpoint. Serve a list of ranges.
Serves a list of the configured ranges that are contained inside a book in the NT.
- readings_json(passage_or_id)¶
Endpoint. Serve all readings found in a passage.
- Parameters
passage_or_id (string) – The passage id.
- relatives_csv(passage_or_id, hs_hsnr_id)¶
Output a table of the nearest relatives of a manuscript.
Output a table of the nearest relatives/ancestors/descendants of a manuscript and what they attest.
- suggest_json()¶
Endpoint. The suggestion drop-downs in the navigator.
Serves a list of books, chapters, verses, or words that the user can enter in the navigation gadget. It suggests only entities that are actually in the database.
server.textflow¶
The API server for CBGM. The textflow and stemmata diagrams.
- init_app(_app)¶
Initialize the flask app.
- remove_z_leaves(graph)¶
Removes leaves (recursively) if they read z.
- stemma(passage_or_id)¶
Serve a local stemma in dot format.
A local stemma is a DAG (directed acyclic graph). The layout of the DAG is precomputed on the server using GraphViz. GraphViz adds a precomputed position to each node and a precomputed bezier path to each edge.
N.B. I also considered client-side layout of DAGs, but found only 2 viable libraries:
dagre. Javascript clone of GraphViz. Unmaintained. Buggy. Does not work well with require.js.
viz.js. GraphViz cross-compiled to Javascript with Emscripten. Huge. Promising but still early days.
Both libraries have their drawbacks so the easiest way out was to precompute the layout on the server.
- stemma_dot(passage_or_id)¶
Return a local stemma diagram in .dot format.
- stemma_png(passage_or_id)¶
Return a local stemma diagram in .png format.
- textflow(passage_or_id)¶
Output a stemma of manuscripts.
- textflow_dot(passage_or_id)¶
Return a textflow diagram in .dot format.
- textflow_png(passage_or_id)¶
Return a textflow diagram in .png format.
server.comparison¶
The comparison function of the API server for CBGM.
- comparison_detail()¶
Output comparison of 2 witnesses, chapter detail.
Outputs a detail of the differences between 2 manuscripts in one chapter.
- comparison_detail_csv()¶
Endpoint. Serve a CSV table. (see also
comparison_detail()
)
- comparison_summary()¶
Output comparison of 2 witnesses, chapter summary.
Outputs a summary of the differences between 2 manuscripts, one summary row per chapters.
- comparison_summary_csv()¶
Endpoint. Serve a CSV table. (see also
comparison_summary()
)
- init_app(_app)¶
Initialize the flask app.
server.set_cover¶
The API server for CBGM. The optimal substemma and set cover module.
See: CBGM_Pres.pdf p. 490ff.
- class Combination(iterator, index)¶
Represents a combination of manuscripts.
- explained()¶
Calculate how many variants are explained by this combination.
- score()¶
Calculate the score for the given combination.
- to_csv()¶
Output the combination in CSV format.
- to_json()¶
Output the combination in JSON format.
- build_explain_matrix(conn, val, ms_id)¶
Build the explain matrix.
A matrix of 1 x n_passages containing the bitmask of all those readings that would explain the reading in the manuscript under scrutiny.
Bit 1 means: the reading stems from an unknown source. Bit 2..64 are the bitmask of all cliques.
- get_ancestors(conn, rg_id, ms_id)¶
Get all ancestors of ms.
- init(db)¶
Do some preparative calculations and cache the results.
- init_app(app)¶
Init the Flask app.
- optimal_substemma_csv()¶
Do an exhaustive search for the combination among a given set of ancestors that best explains a given manuscript.
- optimal_substemma_detail_csv()¶
Report details about one combination of ancestors.
- optimal_substemma_json()¶
Normalize parameters only and add some general info.
- powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)¶
- set_cover_json(hs_hsnr_id)¶
Approximate the minimum set cover for a manuscript.
server.editor¶
The API server for CBGM. Stemma editing module.
- init_app(_app)¶
Initialize the flask app.
- notes_json(range_id)¶
Endpoint. Get a list of all editor notes.
- notes_txt(passage_or_id)¶
Read or write the editor notes for a passage
- stemma_edit(passage_or_id)¶
Edit a local stemma.
Called from local-stemma.js (split, merge, move) and textflow.js (move-manuscripts).
server.login¶
An application server for CBGM. User management module.
- class AnonymousUserMixin¶
This is the default object for representing an anonymous user.
- auth()¶
Check if user is authorized to see what follows.
- declare_user_model_on(db)¶
Declare the user model on flask_sqlalchemy.
- edit_auth()¶
Check if user is authorized to edit.
- init_app(app)¶
Initialize the flask app.
- make_safe_url(url)¶
Turns an unsafe absolute URL into a safe relative URL by removing the scheme and the hostname
- Example: make_safe_url(‘http://hostname/path1/path2?q1=v1&q2=v2#fragment’)
returns: ‘/path1/path2?q1=v1&q2=v2#fragment
Copied from flask_user/views.py because it was defective.
- private_auth()¶
Check if user is authorized to see what follows.
- user_can_read(app)¶
Return True if user has read access.
- user_can_read_private(app)¶
Return True if user has read access.
- user_can_write(app)¶
Return True if user has write access.
server.helpers¶
An application server for CBGM. Helper classes.
- class Bag¶
Class to stick values in.
- EXCLUDE_REGEX_MAP = {'A': 'A', 'F': 'F[1-9Π][0-9]*', 'MT': 'MT'}¶
Regexes for the include/exclude toolbar buttons.
- class Manuscript(conn, manuscript_id_or_hs_or_hsnr)¶
Represent one manuscript.
- class Passage(conn, passage_or_id)¶
Represents one passage.
- range_id(range_=None)¶
Return the id of the range containing this passage.
- class Word(w=0)¶
Represents one word address.
- csvify(fields, rows)¶
Send a HTTP response in CSV format.
- get_excluded_ms_ids(conn, include)¶
Get the ms_ids of manuscripts to exclude.
Helps to implement the buttons “A”, “MT”, and “F” in the toolbar.
- nx_to_dot(graph, width=960.0, fontsize=10.0, nodesep=0.1)¶
Convert an nx graph into a dot file.
We’d like to sort the nodes in the graph, but nx internally uses dictionaries “all the way down”. Thus the only chance to sort nodes and edges is while writing the file. This function is a lightweight re-implementation of nx.nx_pydot.to_pydot ().
- nx_to_dot_subgraphs(graph, field, width=960.0, fontsize=10.0)¶
Convert an nx graph into a dot file.
We’d like to sort the nodes in the graph, but nx internally uses dictionaries “all the way down”. Thus the only chance to sort nodes and edges is while writing the file. This function is a lightweight re-implementation of nx.nx_pydot.to_pydot ().