Exemplo n.º 1
0
def tograph(table, context, *args, **kwargs):
    """
    Return an RDFLib Graph of the table using the context.
    """
    obj = list(_dicts(table))
    data = add_context(obj, context)
    return graph_from_ld(data)
Exemplo n.º 2
0
def to_lineoriented_json(table, source):
    """
    Function to enabling PETL support for exporting line-oriented JSON.
    """
    source = write_source_from_arg(source)
    encoder = DateEncoder()
    with source.open("wb") as f:
        for d in _dicts(table):
            for chunk in encoder.iterencode(d):
                f.write(chunk)
            f.write("\n")
Exemplo n.º 3
0
def to_lineoriented_json(table, source):
    """
    Function to enabling PETL support for exporting line-oriented JSON.
    """
    source = write_source_from_arg(source)
    encoder = DateEncoder()
    with source.open("wb") as f:
        for d in _dicts(table):
            for chunk in encoder.iterencode(d):
                f.write(chunk)
            f.write("\n")
Exemplo n.º 4
0
def tojsonld(table, context, source=None, prefix=None, suffix=None, *args, **kwargs):
    """
    Add the JSON-LD context to the table.

    From petl:
    Note that this is currently not streaming, all data is loaded into memory
    before being written to the file.
    """
    obj = list(_dicts(table))
    data = add_context(obj, context)
    #return json.dumps(data, indent=2)
    _writejson(source, data, prefix, suffix, *args, **kwargs)
Exemplo n.º 5
0
Arquivo: json.py Projeto: sv1jsb/petl
def tojson(table, source=None, prefix=None, suffix=None, *args, **kwargs):
    """
    Write a table in JSON format, with rows output as JSON objects. E.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 2],
        ...           ['c', 2]]
        >>> etl.tojson(table1, 'example.json', sort_keys=True)
        >>> # check what it did
        ... print(open('example.json').read())
        [{"bar": 1, "foo": "a"}, {"bar": 2, "foo": "b"}, {"bar": 2, "foo": "c"}]

    Note that this is currently not streaming, all data is loaded into memory
    before being written to the file.

    """

    obj = list(_dicts(table))
    _writejson(source, obj, prefix, suffix, *args, **kwargs)
Exemplo n.º 6
0
def tojson(table, source=None, prefix=None, suffix=None, *args, **kwargs):
    """
    Write a table in JSON format, with rows output as JSON objects. E.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 2],
        ...           ['c', 2]]
        >>> etl.tojson(table1, 'example.file3.json', sort_keys=True)
        >>> # check what it did
        ... print(open('example.file3.json').read())
        [{"bar": 1, "foo": "a"}, {"bar": 2, "foo": "b"}, {"bar": 2, "foo": "c"}]

    Note that this is currently not streaming, all data is loaded into memory
    before being written to the file.

    """

    obj = list(_dicts(table))
    _writejson(source, obj, prefix, suffix, *args, **kwargs)