Exemplo n.º 1
0
def main():
    from argparse import ArgumentParser
    from json import dump
    from os import getcwd, path
    from sys import stdin, stdout
    from urllib import pathname2url
    from webvtt import parse
    from pyld.jsonld import JsonLdProcessor

    aparser = ArgumentParser(description="webvtt2rdf converter")
    aparser.add_argument("-i", "--input", type=file, default=stdin)
    aparser.add_argument("-f", "--flatten", action="store_true")
    aparser.add_argument("-v", "--video", type=str,
                         default="http://example.org/video.mp4")
    aparser.add_argument("-F", "--format", choices=["json-ld", "nquads"],
                         default="nquads")
    args = aparser.parse_args()

    if args.input is stdin:
        base = "stdin:"
    else:
        base = "file://" + pathname2url(path.join(getcwd(), args.input.name))
        
    jsonld = webvtt2jsonld(parse(args.input),
                           base,
                           args.video,
                           flatten=args.flatten,
    )
    if args.format == "json-ld":
        dump(jsonld, stdout, indent=4); print "\n"
    else:
        proc = JsonLdProcessor()
        print proc.to_nquads(proc.to_rdf(jsonld, None))