HTML browsing and curation (indra.assemblers.html.assembler)

Format a set of INDRA Statements into an HTML-formatted report which also supports curation.

class indra.assemblers.html.assembler.HtmlAssembler(statements=None, summary_metadata=None, ev_totals=None, source_counts=None, title='INDRA Results', db_rest_url=None)[source]

Generates an HTML-formatted report from INDRA Statements.

The HTML report format includes statements formatted in English (by the EnglishAssembler), text and metadata for the Evidence object associated with each Statement, and a Javascript-based curation interface linked to the INDRA database (access permitting). The interface allows for curation of statements at the evidence level by letting the user specify type of error and (optionally) provide a short description of of the error.

Parameters:
  • statements (Optional[list[indra.statements.Statement]]) – A list of INDRA Statements to be added to the assembler. Statements can also be added using the add_statements method after the assembler has been instantiated.
  • summary_metadata (Optional[dict]) – Dictionary of statement corpus metadata such as that provided by the INDRA REST API. Default is None. Each value should be a concise summary of O(1), not of order the length of the list, such as the evidence totals. The keys should be informative human-readable strings.
  • ev_totals (Optional[dict]) – A dictionary of the total evidence available for each statement indexed by hash. Default: None
  • source_counts (Optional[dict]) – A dictionary of the itemized evidence counts, by source, available for each statement, indexed by hash. Default: None.
  • title (str) – The title to be printed at the top of the page.
  • db_rest_url (Optional[str]) – The URL to a DB REST API to use for links out to further evidence. If given, this URL will be prepended to links that load additional evidence for a given Statement. One way to obtain this value is from the configuration entry indra.config.get_config(‘INDRA_DB_REST_URL’). If None, the URLs are constructed as relative links. Default: None
statements

A list of INDRA Statements to assemble.

Type:list[indra.statements.Statement]
model

The HTML report formatted as a single string.

Type:str
metadata

Dictionary of statement list metadata such as that provided by the INDRA REST API.

Type:dict
ev_totals

A dictionary of the total evidence available for each statement indexed by hash.

Type:dict
db_rest_url

The URL to a DB REST API.

Type:str
add_statements(statements)[source]

Add a list of Statements to the assembler.

Parameters:statements (list[indra.statements.Statement]) – A list of INDRA Statements to be added to the assembler.
append_warning(msg)[source]

Append a warning message to the model to expose issues.

make_model(template=None, **template_kwargs)[source]

Return the assembled HTML content as a string.

Returns:The assembled HTML as a string.
Return type:str
save_model(fname)[source]

Save the assembled HTML into a file.

Parameters:fname (str) – The path to the file to save the HTML into.
class indra.assemblers.html.assembler.IndraHTMLLoader(root_paths=None)[source]

A home-grown template loader to load the INDRA templates.

Based on the example found here: http://jinja.pocoo.org/docs/2.10/api/#loaders

Parameters:root_paths (dict) – A dict of strings indicating possible roots for template directories, keyed by basename. To be more specific, an entry {‘indra’: ‘/path/to/module’} would mean that you expect to have ‘indra/template.html’ mapped to ‘/path/to/module/templates/template.html’. The default is {‘indra’: HERE}.
get_source(environment, template)[source]

Get the template source, filename and reload helper for a template. It’s passed the environment and template name and has to return a tuple in the form (source, filename, uptodate) or raise a TemplateNotFound error if it can’t locate the template.

The source part of the returned tuple must be the source of the template as unicode string or a ASCII bytestring. The filename should be the name of the file on the filesystem if it was loaded from there, otherwise None. The filename is used by python for the tracebacks if no loader extension is used.

The last item in the tuple is the uptodate function. If auto reloading is enabled it’s always called to check if the template changed. No arguments are passed so the function must store the old state somewhere (for example in a closure). If it returns False the template will be reloaded.

indra.assemblers.html.assembler.tag_text(text, tag_info_list)[source]

Apply start/end tags to spans of the given text.

Parameters:
  • text (str) – Text to be tagged
  • tag_info_list (list of tuples) – Each tuple refers to a span of the given text. Fields are (start_ix, end_ix, substring, start_tag, close_tag), where substring, start_tag, and close_tag are strings. If any of the given spans of text overlap, the longest span is used.
Returns:

String where the specified substrings have been surrounded by the given start and close tags.

Return type:

str