コード例 #1
0
def dot(graph, simple=True, debug=False, landscape=False, strict=False):
    """Format graph as a dot file."""
    import sys

    from rdflib.tools.rdf2dot import rdf2dot

    if strict:
        raise SHACLValidationError('--strict not supported for json-ld-graph')

    g = _conjunctive_graph(graph)

    g.bind('prov', 'http://www.w3.org/ns/prov#')
    g.bind('foaf', 'http://xmlns.com/foaf/0.1/')
    g.bind('wfdesc', 'http://purl.org/wf4ever/wfdesc#')
    g.bind('wf', 'http://www.w3.org/2005/01/wf/flow#')
    g.bind('wfprov', 'http://purl.org/wf4ever/wfprov#')
    g.bind('schema', 'http://schema.org/')

    if debug:
        rdf2dot(g, sys.stdout)
        return

    sys.stdout.write('digraph { \n node [ fontname="DejaVu Sans" ] ; \n ')
    if landscape:
        sys.stdout.write('rankdir="LR" \n')
    if simple:
        _rdf2dot_simple(g, sys.stdout)
        return
    _rdf2dot_reduced(g, sys.stdout)
コード例 #2
0
def ascii(graph, strict=False):
    """Format graph as an ASCII art."""
    from ..ascii import DAG
    from ..echo import echo_via_pager

    if strict:
        raise SHACLValidationError('--strict not supported for json-ld-graph')

    echo_via_pager(str(DAG(graph)))
コード例 #3
0
def rdf(graph, strict=False):
    """Output the graph as RDF."""
    xml = _conjunctive_graph(graph).serialize(format="application/rdf+xml")
    if strict:
        r, _, t = validate_graph(xml, format="xml")

        if not r:
            raise SHACLValidationError("{}\nCouldn't get log: Invalid Knowledge Graph data".format(t))

    click.echo(xml)
コード例 #4
0
def nt(graph, strict=False):
    """Format graph as n-tuples."""
    nt = _conjunctive_graph(graph).serialize(format="nt")
    if strict:
        r, _, t = validate_graph(nt, format="nt")

        if not r:
            raise SHACLValidationError("{}\nCouldn't get log: Invalid Knowledge Graph data".format(t))

    click.echo(nt)
コード例 #5
0
def jsonld(graph, strict=False):
    """Format graph as JSON-LD file."""
    ld = _jsonld(graph, "expand")

    if strict:
        r, _, t = validate_graph(ld, format="json-ld")

        if not r:
            raise SHACLValidationError("{}\nCouldn't get log: Invalid Knowledge Graph data".format(t))
    click.echo(ld)
コード例 #6
0
def makefile(graph, strict=False):
    """Format graph as Makefile."""
    from renku.core.models.provenance.activities import ProcessRun, WorkflowRun

    if strict:
        raise SHACLValidationError("--strict not supported for json-ld-graph")

    for activity in graph.activities.values():
        if not isinstance(activity, ProcessRun):
            continue
        elif isinstance(activity, WorkflowRun):
            steps = activity.subprocesses.values()
        else:
            steps = [activity]

        for step in steps:
            plan = step.association.plan
            inputs = [i.consumes.path for i in plan.inputs]
            outputs = [o.produces.path for o in plan.outputs]
            click.echo(" ".join(outputs) + ": " + " ".join(inputs))
            click.echo("\t@" + " ".join(plan.to_argv()) + " " + " ".join(plan.to_stream_repr()))
コード例 #7
0
def makefile(graph, strict=False):
    """Format graph as Makefile."""
    from renku.core.models.provenance.activities import ProcessRun, WorkflowRun

    if strict:
        raise SHACLValidationError('--strict not supported for json-ld-graph')

    for activity in graph.activities.values():
        if not isinstance(activity, ProcessRun):
            continue
        elif isinstance(activity, WorkflowRun):
            steps = activity.subprocesses.values()
        else:
            steps = [activity]

        for step in steps:
            click.echo(' '.join(step.outputs) + ': ' + ' '.join(step.inputs))
            tool = step.process
            click.echo(
                '\t@' + ' '.join(tool.to_argv()) + ' ' + ' '.join(
                    tool.STD_STREAMS_REPR[key] + ' ' + str(path)
                    for key, path in tool._std_streams().items()
                )
            )
コード例 #8
0
def jsonld_graph(graph, strict=False):
    """Format graph as JSON-LD graph file."""
    if strict:
        raise SHACLValidationError('--strict not supported for json-ld-graph')
    click.echo(_jsonld(graph, 'flatten'))