def to_rdf( data, dataset, base=None, context_data=None, version=None, generalized_rdf=False, allow_lists_of_lists=None, ): # TODO: docstring w. args and return value context = Context(base=base, version=version) if context_data: context.load(context_data) parser = Parser( generalized_rdf=generalized_rdf, allow_lists_of_lists=allow_lists_of_lists ) return parser.parse(data, context, dataset)
action='store_true', help='Make the output more human readable') parser.add_argument('-p', '--profile', nargs='*', action='store', help='RDF Profiles to use, defaults to euro_dcat_ap') parser.add_argument('-m', '--compat-mode', action='store_true', help='Enable compatibility mode') args = parser.parse_args() contents = args.file.read() if args.mode == 'produce': serializer = RDFSerializer(profiles=args.profile, compatibility_mode=args.compat_mode) dataset = json.loads(contents) out = serializer.serialize_dataset(dataset, _format=args.format) print out else: parser = RDFParser(profiles=args.profile, compatibility_mode=args.compat_mode) parser.parse(contents, _format=args.format) ckan_datasets = [d for d in parser.datasets()] indent = 4 if args.pretty else None print json.dumps(ckan_datasets, indent=indent)