def _run_case(json_fpath=None, expected_graph=None): with open(json_fpath) as f: json_data = json.load(f) graph = to_rdf(json_data) assert isomorphic(graph, expected_graph), "unexpected graph from <%s>" % json_fpath # TODO: comp. to json, with resp. without profile.. # .. and compare with automade profile from serializer for at least "full" source_profile = Profile(json_data['profile']) lang = json_data.get('lang') base = json_data.get('base') result_tree = to_tree(graph, source_profile, lang, base) # TODO: where to handle the unordered nature of multiple props as JSON? _sort_lists(json_data) _sort_lists(result_tree) expected = _to_json(json_data) result = _to_json(result_tree) assert expected == result, "Expected:\n%s\ngot:\n %s" % (expected, result)
from rdflib.graph import ConjunctiveGraph from oort.util.deps import json from oort.gluon import Profile from oort.gluon.parser import to_rdf from oort.gluon.serializer import to_tree if __name__ == '__main__': from sys import argv, stdin args = argv[1:] fname = args.pop(0) if args else "" profile_fname = args.pop(0) if args else None lang = args.pop(0) if args else None if not fname or fname.endswith('.json'): infile = open(fname) if fname else stdin tree = json.loads( "".join(l for l in infile if not l.strip().startswith('//'))) graph = to_rdf(tree) print graph.serialize(format="n3") else: graph = ConjunctiveGraph() from rdfextras.tools.pathutils import guess_format graph.parse(fname, format=guess_format(fname)) profile = Profile(json.load(open(profile_fname)) ) if profile_fname else None tree = to_tree(graph, profile, lang) print json.dumps(tree, indent=4, separators=(',',': '), sort_keys=True, check_circular=False)
from oort.util.deps import json from oort.gluon import Profile from oort.gluon.parser import to_rdf from oort.gluon.serializer import to_tree if __name__ == '__main__': from sys import argv, stdin args = argv[1:] fname = args.pop(0) if args else "" profile_fname = args.pop(0) if args else None lang = args.pop(0) if args else None if not fname or fname.endswith('.json'): infile = open(fname) if fname else stdin tree = json.loads("".join(l for l in infile if not l.strip().startswith('//'))) graph = to_rdf(tree) print graph.serialize(format="n3") else: graph = ConjunctiveGraph() from rdfextras.tools.pathutils import guess_format graph.parse(fname, format=guess_format(fname)) profile = Profile(json.load( open(profile_fname))) if profile_fname else None tree = to_tree(graph, profile, lang) print json.dumps(tree, indent=4, separators=(',', ': '), sort_keys=True, check_circular=False)