How to use the nanopub.csv2np.csv2np.Nanopub function in nanopub

To help you get started, we’ve selected a few nanopub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umd-mith / ema / nanopub / csv2np / csv2np.py View on Github external
return self.g.serialize(format='trig')


def write_np(s, npid, formt):
    filename = filename = "np{0}.{1}".format(npid, formt)
    with open(os.path.join(out_dir, filename), 'wb') as f:
        f.write(s)

with open(csv_path) as csvfile:
    creader = csv.reader(csvfile)
    for i, analysis in enumerate(creader):
        if i == 0:
            csv_headers = analysis
        else:
            npid = analysis[csv_headers.index("id")]
            n = Nanopub(analysis, npid)
            if args.format == "trix":
                s = n.trix()
            elif args.format == "trig":
                s = n.trig()
            elif args.format == "nq":
                s = n.nquads()
            elif args.format == "jsonld":
                s = n.jsonld()
            else:
                args.format = "trig"
                s = n.trig()

            write_np(s, npid, args.format)

register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer')

nanopub

Python client for Nanopublications

Apache-2.0
Latest version published 10 months ago

Package Health Score

58 / 100
Full package analysis