21
21
import rdflib_jsonld .parser
22
22
register ('json-ld' , Parser , 'rdflib_jsonld.parser' , 'JsonLDParser' )
23
23
24
-
25
24
def printrdf (workflow , wf , ctx , sr ):
26
- g = Graph ().parse (data = json .dumps (wf ),
27
- format = 'json-ld' , location = workflow , context = ctx )
25
+ g = Graph ().parse (data = json .dumps (wf ), format = 'json-ld' , location = workflow , context = ctx )
28
26
print (g .serialize (format = sr ))
29
27
30
-
31
28
def main (args = None ):
32
29
if args is None :
33
30
args = sys .argv [1 :]
@@ -38,41 +35,27 @@ def main(args=None):
38
35
default = "turtle" )
39
36
40
37
exgroup = parser .add_mutually_exclusive_group ()
41
- exgroup .add_argument ("--print-jsonld-context" ,
42
- action = "store_true" , help = "Print JSON-LD context for schema" )
43
- exgroup .add_argument (
44
- "--print-doc" , action = "store_true" , help = "Print HTML documentation from schema" )
45
- exgroup .add_argument (
46
- "--print-rdfs" , action = "store_true" , help = "Print RDF schema" )
47
- exgroup .add_argument (
48
- "--print-avro" , action = "store_true" , help = "Print Avro schema" )
49
-
50
- exgroup .add_argument ("--print-rdf" , action = "store_true" ,
51
- help = "Print corresponding RDF graph for document" )
52
- exgroup .add_argument (
53
- "--print-pre" , action = "store_true" , help = "Print document after preprocessing" )
54
- exgroup .add_argument (
55
- "--print-index" , action = "store_true" , help = "Print node index" )
56
- exgroup .add_argument (
57
- "--print-metadata" , action = "store_true" , help = "Print document metadata" )
58
- exgroup .add_argument (
59
- "--version" , action = "store_true" , help = "Print version" )
38
+ exgroup .add_argument ("--print-jsonld-context" , action = "store_true" , help = "Print JSON-LD context for schema" )
39
+ exgroup .add_argument ("--print-doc" , action = "store_true" , help = "Print HTML documentation from schema" )
40
+ exgroup .add_argument ("--print-rdfs" , action = "store_true" , help = "Print RDF schema" )
41
+ exgroup .add_argument ("--print-avro" , action = "store_true" , help = "Print Avro schema" )
42
+
43
+ exgroup .add_argument ("--print-rdf" , action = "store_true" , help = "Print corresponding RDF graph for document" )
44
+ exgroup .add_argument ("--print-pre" , action = "store_true" , help = "Print document after preprocessing" )
45
+ exgroup .add_argument ("--print-index" , action = "store_true" , help = "Print node index" )
46
+ exgroup .add_argument ("--print-metadata" , action = "store_true" , help = "Print document metadata" )
47
+ exgroup .add_argument ("--version" , action = "store_true" , help = "Print version" )
60
48
61
49
exgroup = parser .add_mutually_exclusive_group ()
62
- exgroup .add_argument (
63
- "--strict" , action = "store_true" , help = "Strict validation (unrecognized or out of place fields are error)" ,
50
+ exgroup .add_argument ("--strict" , action = "store_true" , help = "Strict validation (unrecognized or out of place fields are error)" ,
64
51
default = True , dest = "strict" )
65
- exgroup .add_argument (
66
- "--non-strict" , action = "store_false" , help = "Lenient validation (ignore unrecognized fields)" ,
52
+ exgroup .add_argument ("--non-strict" , action = "store_false" , help = "Lenient validation (ignore unrecognized fields)" ,
67
53
default = True , dest = "strict" )
68
54
69
55
exgroup = parser .add_mutually_exclusive_group ()
70
- exgroup .add_argument (
71
- "--verbose" , action = "store_true" , help = "Default logging" )
72
- exgroup .add_argument (
73
- "--quiet" , action = "store_true" , help = "Only print warnings and errors." )
74
- exgroup .add_argument (
75
- "--debug" , action = "store_true" , help = "Print even more logging" )
56
+ exgroup .add_argument ("--verbose" , action = "store_true" , help = "Default logging" )
57
+ exgroup .add_argument ("--quiet" , action = "store_true" , help = "Only print warnings and errors." )
58
+ exgroup .add_argument ("--debug" , action = "store_true" , help = "Print even more logging" )
76
59
77
60
parser .add_argument ("schema" , type = str )
78
61
parser .add_argument ("document" , type = str , nargs = "?" , default = None )
@@ -93,17 +76,15 @@ def main(args=None):
93
76
_logger .info ("%s %s" , sys .argv [0 ], pkg [0 ].version )
94
77
95
78
# Get the metaschema to validate the schema
96
- metaschema_names , metaschema_doc , metaschema_loader = schema .get_metaschema (
97
- )
79
+ metaschema_names , metaschema_doc , metaschema_loader = schema .get_metaschema ()
98
80
99
81
# Load schema document and resolve refs
100
82
101
83
schema_uri = args .schema
102
84
if not urlparse .urlparse (schema_uri )[0 ]:
103
85
schema_uri = "file://" + os .path .abspath (schema_uri )
104
86
schema_raw_doc = metaschema_loader .fetch (schema_uri )
105
- schema_doc , schema_metadata = metaschema_loader .resolve_all (
106
- schema_raw_doc , schema_uri )
87
+ schema_doc , schema_metadata = metaschema_loader .resolve_all (schema_raw_doc , schema_uri )
107
88
108
89
# Optionally print the schema after ref resolution
109
90
if not args .document and args .print_pre :
@@ -118,19 +99,16 @@ def main(args=None):
118
99
try :
119
100
metaschema_loader .validate_links (schema_doc )
120
101
except (validate .ValidationException ) as e :
121
- _logger .error ("Schema `%s` failed link checking:\n %s" ,
122
- args .schema , e , exc_info = (e if args .debug else False ))
102
+ _logger .error ("Schema `%s` failed link checking:\n %s" , args .schema , e , exc_info = (e if args .debug else False ))
123
103
_logger .debug ("Index is %s" , metaschema_loader .idx .keys ())
124
104
_logger .debug ("Vocabulary is %s" , metaschema_loader .vocab .keys ())
125
105
return 1
126
106
127
107
# Validate the schema document against the metaschema
128
108
try :
129
- schema .validate_doc (
130
- metaschema_names , schema_doc , metaschema_loader , args .strict )
109
+ schema .validate_doc (metaschema_names , schema_doc , metaschema_loader , args .strict )
131
110
except validate .ValidationException as e :
132
- _logger .error ("While validating schema `%s`:\n %s" %
133
- (args .schema , str (e )))
111
+ _logger .error ("While validating schema `%s`:\n %s" % (args .schema , str (e )))
134
112
return 1
135
113
136
114
# Get the json-ld context and RDFS representation from the schema
@@ -139,20 +117,16 @@ def main(args=None):
139
117
metactx = schema_raw_doc .get ("$namespaces" , {})
140
118
if "$base" in schema_raw_doc :
141
119
metactx ["@base" ] = schema_raw_doc ["$base" ]
142
- (schema_ctx , rdfs ) = jsonld_context .salad_to_jsonld_context (
143
- schema_doc , metactx )
120
+ (schema_ctx , rdfs ) = jsonld_context .salad_to_jsonld_context (schema_doc , metactx )
144
121
145
122
# Create the loader that will be used to load the target document.
146
123
document_loader = Loader (schema_ctx )
147
124
148
- # Make the Avro validation that will be used to validate the target
149
- # document
150
- (avsc_names , avsc_obj ) = schema .make_avro_schema (
151
- schema_doc , document_loader )
125
+ # Make the Avro validation that will be used to validate the target document
126
+ (avsc_names , avsc_obj ) = schema .make_avro_schema (schema_doc , document_loader )
152
127
153
128
if isinstance (avsc_names , Exception ):
154
- _logger .error ("Schema `%s` error:\n %s" , args .schema ,
155
- avsc_names , exc_info = (avsc_names if args .debug else False ))
129
+ _logger .error ("Schema `%s` error:\n %s" , args .schema , avsc_names , exc_info = (avsc_names if args .debug else False ))
156
130
if args .print_avro :
157
131
print json .dumps (avsc_obj , indent = 4 )
158
132
return 1
@@ -194,8 +168,7 @@ def main(args=None):
194
168
doc = "file://" + os .path .abspath (uri )
195
169
document , doc_metadata = document_loader .resolve_ref (uri )
196
170
except (validate .ValidationException , RuntimeError ) as e :
197
- _logger .error ("Document `%s` failed validation:\n %s" ,
198
- args .document , e , exc_info = (e if args .debug else False ))
171
+ _logger .error ("Document `%s` failed validation:\n %s" , args .document , e , exc_info = (e if args .debug else False ))
199
172
return 1
200
173
201
174
# Optionally print the document after ref resolution
@@ -211,18 +184,15 @@ def main(args=None):
211
184
try :
212
185
document_loader .validate_links (document )
213
186
except (validate .ValidationException ) as e :
214
- _logger .error ("Document `%s` failed link checking:\n %s" ,
215
- args .document , e , exc_info = (e if args .debug else False ))
216
- _logger .debug ("Index is %s" , json .dumps (
217
- document_loader .idx .keys (), indent = 4 ))
187
+ _logger .error ("Document `%s` failed link checking:\n %s" , args .document , e , exc_info = (e if args .debug else False ))
188
+ _logger .debug ("Index is %s" , json .dumps (document_loader .idx .keys (), indent = 4 ))
218
189
return 1
219
190
220
191
# Validate the schema document against the metaschema
221
192
try :
222
193
schema .validate_doc (avsc_names , document , document_loader , args .strict )
223
194
except validate .ValidationException as e :
224
- _logger .error ("While validating document `%s`:\n %s" %
225
- (args .document , str (e )))
195
+ _logger .error ("While validating document `%s`:\n %s" % (args .document , str (e )))
226
196
return 1
227
197
228
198
# Optionally convert the document to RDF
0 commit comments