opl package

Module contents

class opl.Confluence(server, username, password)

Bases: object

Create a new client to interact with Confluence

Parameters
  • server (str) – URI of the Confluence server

  • username (str) – Username to authenticate with

  • password (str) – Password to authenticate with

page(page_id)

Create a handle for a specific page

Parameters

page_id (str) – the ID of the page

Return type

_Page

class opl.IncQueryProject(server, username, password, org=None, project=None, ref=None, compartment=None, patterns={})

Bases: object

Create a new client to query a specific IncQuery project. May either provide the full compartment IRI or an org, project ID and ref to automatically select the latest commit.

Parameters
  • server (str) – URI of the IncQuery server

  • username (str) – Username to authenticate with

  • password (str) – Password to authenticate with

  • org (Optional[str]) – MMS org of the project to select

  • project (Optional[str]) – MMS project ID of the project to select

  • ref (Optional[str]) – Which ref to select from the project; defaults to ‘master’. Loads the latest commit from that ref

  • compartment (Optional[str]) – Instead of specifying org, project/ref, use the specified compartment IRI

  • patterns (Dict[str, str]) – Default patterns to use for implicit query executions

execute(name, patterns={}, bindings={}, w_url_provider=None)

Execute a query and return the results as a list of dicts

Parameters
  • name (str) – Name of which pattern to execute

  • bindings (Dict[str, Any]) – A dict of bindings to pass into query execution

  • patterns (Dict[str, str]) – A dict of patterns to include during query execution (overwrites defaults provided to constructor)

Return type

List[Dict[str, Any]]

extend_row(row, query_field)

Extend a row by applying the given query_field

Parameters
  • row (Dict[str, Any]) – A dict item obtained from the list of execute results

  • query_field (QueryField) – A QueryField descriptor that specifies how to perform the extension

Return type

List[Dict[str, Any]]

class opl.QueryField(join: Callable[[Dict[str, str]], Dict[str, str]], query: str, select: Callable[[Dict[str, str]], str], bindings: Dict[str, str] = {}, patterns: Dict[str, str] = {})

Bases: tuple

Descriptor for a query field to be used for extending a query result row

bindings: Dict[str, str]

Alias for field number 3

join: Callable[[Dict[str, str]], Dict[str, str]]

Alias for field number 0

patterns: Dict[str, str]

Alias for field number 4

query: str

Alias for field number 1

select: Callable[[Dict[str, str]], str]

Alias for field number 2

class opl.QueryResultsTable(rows, labels=None, rewriters={})

Bases: object

Create the means to render the query results as a table

Parameters
  • rows (List[Dict[str, Any]]) – The list of rows returned from executing a query

  • labels (Optional[Dict[str, str]]) – A dict that maps field IDs to text labels

property labels
property rewriters
property rows
to_confluence_xhtml(span_id, macro_id=None, rewriters={})

Construct an XHTML table to render the table in Confluence

Parameters
  • span_id (str) – the ID to give the annotated span

  • macro_id (Optional[str]) – optional UUIDv4 to give the Confluence macro

  • rewriters (Dict[str, Callable[[Any], str]]) – dict of callback functions for rewriting cell values under the given columns

to_html(rewriters={})

Construct an HTML table to render the table

Parameters

rewriters (Dict[str, Callable[[Any], str]]) – dict of callback functions for rewriting cell values under the given columns

Return type

str

class opl.Sparql(endpoint)

Bases: object

Wrapper class to simplify submitting and fetching SPARQL queries

Parameters

endpoint (str) – full URL to the SPARQL endpoint

construct(query)

Submit a SPARQL CONSTRUCT query and return the resulting graph as a Turtle document string

Parameters

query (str) – the SPARQL CONSTRUCT query string to submit. Prefixes are prepended automatically

Return type

str

fetch(query)

Submit a SPARQL SELECT query and return the query result rows as a list of dicts

Parameters

query (str) – the SPARQL SELECT query string to submit. Prefixes are prepended automatically

Return type

List[Dict[str, Any]]

static load(template, variables={}, injections={})

Static method to apply mixins, variable substitions, and injections to a query template string.

Parameters
  • template (str) – the SPARQL query template string

  • variables (Dict[str, str]) – dict of variables and their values

  • injections (Dict[str, str]) – dict of injections to apply across query template

Return type

str

Returns

the output query string

class opl.confluence._Page(k_wiki, si_page)

Created by using the .page() method on a Confluence instance

get_content()

Retrieve the XHTML content of the page

Return type

str

update_content(content)

Update the XHTML content of the page

property version

Example IncQueryProject usage

import opl

opl.IncQueryProject(
    server='https://incquery.org.xyz',
    username=os.environ.get('INCQUERY_USERNAME'),
    password=os.environ.get('INCQUERY_PASSWORD'),
    org='example',
    project='demo',
    patterns={
        # mixin from opl basic queries
        **opl.patterns.basic,

        # simple, 'auto-named' pattern
        'propertyValue': '''
            (property: Property, value: java String) {
                Property.defaultValue(property, propValue);
                LiteralString.value(propValue, value);
            }
        ''',

        # more advanced, full pattern
        'predicateTarget': '''
            private incremental pattern predicateTarget(element: Class, predicateName: java String, target: Class) {
                Class.ownedAttribute(element, predicate);
                Property.name(predicate, predicateName);
                Property.type(predicate, target);
            }
        ''',
    },
)