Skip to content

Commit b505eb2

Browse files
committed
ref: change shapefile to a single file
1 parent 3f52cb9 commit b505eb2

File tree

11 files changed

+274
-506
lines changed

11 files changed

+274
-506
lines changed

reproschema/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def get_logger(name=None):
1515
"""Return a logger to use
1616
"""
17-
return logging.getLogger("pydra_ml" + (".%s" % name if name else ""))
17+
return logging.getLogger("reproschema" + (".%s" % name if name else ""))
1818

1919

2020
def set_logger_level(lgr, level):
@@ -34,7 +34,7 @@ def set_logger_level(lgr, level):
3434

3535
lgr = get_logger()
3636
# Basic settings for output, for now just basic
37-
set_logger_level(lgr, os.environ.get("PYDRAML_LOG_LEVEL", logging.INFO))
37+
set_logger_level(lgr, os.environ.get("REPROSCHEMA_LOG_LEVEL", logging.INFO))
3838
FORMAT = "%(asctime)-15s [%(levelname)8s] %(message)s"
3939
logging.basicConfig(format=FORMAT)
4040

reproschema/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def main(log_level):
3939

4040

4141
@main.command()
42-
@click.option("--shapedir", default=None, type=click.Path(exists=True, dir_okay=True))
42+
@click.option("--shapefile", default=None, type=click.Path(exists=True, dir_okay=False))
4343
@click.argument("path", nargs=1, type=str)
44-
def validate(shapedir, path):
44+
def validate(shapefile, path):
4545
if not (path.startswith("http") or os.path.exists(path)):
4646
raise ValueError(f"{path} must be a URL or an existing file or directory")
4747
from .validate import validate
4848

49-
validate(shapedir, path)
49+
validate(shapefile, path)
5050

5151

5252
@main.command()

reproschema/jsonldutils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,6 @@ def load_file(path_or_url, started=False, http_kwargs={}):
3333
return data
3434

3535

36-
def file2shape(filename, shape_dir, started, http_kwargs={}):
37-
data = load_file(filename, started, http_kwargs)
38-
no_type = True
39-
shape_file_path = []
40-
for val in data:
41-
if "@type" not in val:
42-
continue
43-
for schema_type in val["@type"]:
44-
for key in ["Protocol", "Activity", "Field", "ResponseOption"]:
45-
if schema_type.endswith(f"/{key}"):
46-
shape_file_path.append(os.path.join(shape_dir, f"{key}Shape.ttl"))
47-
no_type = False
48-
if no_type:
49-
raise ValueError(f"{filename} missing @type")
50-
if len(shape_file_path) > 1:
51-
raise ValueError(
52-
f"Multiple reproschema types in {filename}. Not " f"supported yet"
53-
)
54-
return data, shape_file_path.pop()
55-
56-
5736
def validate_data(data, shape_file_path):
5837
"""Validate an expanded jsonld document against a shape.
5938
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
@prefix nidm: <http://purl.org/nidash/nidm#> .
2+
@prefix prov: <http://www.w3.org/ns/prov#> .
3+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
5+
@prefix reproschema: <http://schema.repronim.org/> .
6+
@prefix schema: <http://schema.org/> .
7+
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
8+
9+
reproschema:Activity a nidm:Assessment,
10+
rdfs:Class,
11+
prov:Entity,
12+
prov:Plan ;
13+
rdfs:label "Activity" ;
14+
rdfs:comment "An assessment in a protocol." ;
15+
rdfs:subClassOf schema:CreativeWork .
16+
17+
reproschema:AdditionalProperty a rdfs:Class ;
18+
rdfs:label "Additional properties" ;
19+
rdfs:comment "An object to describe the various properties added to assessments and fields." .
20+
21+
reproschema:AllowExport a rdfs:Class ;
22+
rdfs:label "Allow export" ;
23+
rdfs:comment "Indicates (by boolean) if data can be exported or not." .
24+
25+
reproschema:AutoAdvance a rdfs:Class ;
26+
rdfs:label "Auto advance" ;
27+
rdfs:comment "Indicates (by boolean) if assessments in a protocol can auto advance or not." .
28+
29+
reproschema:Choice a rdfs:Class ;
30+
rdfs:label "Response choice" ;
31+
rdfs:comment "An array to list the available options in responseOptions of the Field item." .
32+
33+
reproschema:DisableBack a rdfs:Class ;
34+
rdfs:label "Disable redo" ;
35+
rdfs:comment "Indicates (by boolean) if we can go back to a completed assessment in a protocol." .
36+
37+
reproschema:DontKnow a rdfs:Class ;
38+
rdfs:label "Do not know" ;
39+
rdfs:comment "An element to describe the choice when response is not known." .
40+
41+
reproschema:Field a nidm:DataElement,
42+
rdfs:Class,
43+
prov:Entity ;
44+
rdfs:label "Field" ;
45+
rdfs:comment "An item in an assessment." ;
46+
rdfs:subClassOf schema:CreativeWork .
47+
48+
reproschema:Protocol a rdfs:Class,
49+
prov:Entity,
50+
prov:Plan ;
51+
rdfs:label "Protocol" ;
52+
rdfs:comment "A representation of a study which comprises one or more assessments." ;
53+
rdfs:subClassOf schema:CreativeWork .
54+
55+
reproschema:ResponseOption a rdfs:Class ;
56+
rdfs:label "Response option" ;
57+
rdfs:comment "An element (object or by URL)to describe the properties of response of the Field item." .
58+
59+
reproschema:Scoring a rdfs:Class ;
60+
rdfs:label "Scoring logic" ;
61+
rdfs:comment "An object indicating score in an activity or protocol and the score Field item " .
62+
63+
reproschema:Skipped a rdfs:Class ;
64+
rdfs:label "Skipped" ;
65+
rdfs:comment "An element to describe the choice when the item is skipped." .
66+
67+
reproschema:TimedOut a rdfs:Class ;
68+
rdfs:label "Response timed out" ;
69+
rdfs:comment "A boolean element to describe if the response did not occur within the prescribed time." .
70+
71+
schema:about schema:domainIncludes reproschema:Activity,
72+
reproschema:Field,
73+
reproschema:Protocol .
74+
75+
schema:associatedMedia schema:domainIncludes reproschema:Field .
76+
77+
schema:citation schema:domainIncludes reproschema:Activity .
78+
79+
schema:description schema:domainIncludes reproschema:Activity,
80+
reproschema:Field,
81+
reproschema:Protocol .
82+
83+
schema:image schema:domainIncludes reproschema:Choice .
84+
85+
schema:isPartOf schema:domainIncludes reproschema:Field ;
86+
schema:rangeIncludes reproschema:Activity .
87+
88+
schema:maxValue schema:domainIncludes reproschema:ResponseOption .
89+
90+
schema:minValue schema:domainIncludes reproschema:ResponseOption .
91+
92+
schema:name schema:domainIncludes reproschema:Choice .
93+
94+
schema:question schema:domainIncludes reproschema:Field .
95+
96+
schema:readonlyValue schema:domainIncludes reproschema:Field .
97+
98+
schema:schemaVersion schema:domainIncludes reproschema:Activity,
99+
reproschema:Field,
100+
reproschema:Protocol .
101+
102+
schema:unitCode schema:domainIncludes reproschema:ResponseOption .
103+
104+
schema:value schema:domainIncludes reproschema:Choice ;
105+
schema:rangeIncludes reproschema:DontKnow,
106+
reproschema:Skipped .
107+
108+
schema:valueRequired schema:domainIncludes reproschema:AdditionalProperty .
109+
110+
schema:version schema:domainIncludes reproschema:Activity,
111+
reproschema:Field,
112+
reproschema:Protocol .
113+
114+
reproschema:addProperties a rdf:Property ;
115+
rdfs:label "addProperties" ;
116+
schema:domainIncludes reproschema:Activity,
117+
reproschema:Protocol ;
118+
schema:rangeIncludes reproschema:AdditionalProperty ;
119+
rdfs:comment "An array of objects to describe the various properties added to assessments and fields." .
120+
121+
reproschema:allow a rdf:Property ;
122+
rdfs:label "allow" ;
123+
schema:domainIncludes reproschema:Protocol ;
124+
schema:rangeIncludes schema:Thing ;
125+
rdfs:comment "An array of items indicating properties allowed on an activity or protocol " .
126+
127+
reproschema:choices a rdf:Property ;
128+
rdfs:label "choices" ;
129+
schema:domainIncludes reproschema:ResponseOption ;
130+
schema:rangeIncludes schema:URL,
131+
reproschema:Choice ;
132+
schema:sameAs schema:itemListElement ;
133+
rdfs:comment "An array to list the available options in responseOptions of the Field item." .
134+
135+
reproschema:datumType a rdf:Property ;
136+
rdfs:label "datumType" ;
137+
schema:domainIncludes reproschema:ResponseOption ;
138+
schema:rangeIncludes schema:Text,
139+
schema:URL ;
140+
rdfs:comment "Indicates what type of datum the response is (e.g. range,count,scalar etc.) for the Field item." .
141+
142+
reproschema:inputType a rdf:Property ;
143+
rdfs:label "inputType" ;
144+
schema:domainIncludes reproschema:Field ;
145+
schema:rangeIncludes schema:Text ;
146+
rdfs:comment "An element to describe the input type of a Field item." .
147+
148+
reproschema:isAbout a rdf:Property ;
149+
rdfs:label "isAbout" ;
150+
schema:domainIncludes reproschema:AdditionalProperty ;
151+
schema:rangeIncludes reproschema:Activity,
152+
reproschema:Field ;
153+
rdfs:comment "An element to define (by URL) the corresponding nodes." .
154+
155+
reproschema:isVis a rdf:Property ;
156+
rdfs:label "visibility" ;
157+
schema:domainIncludes reproschema:AdditionalProperty ;
158+
schema:rangeIncludes schema:Boolean,
159+
schema:Text ;
160+
rdfs:comment "An element to describe (by boolean or conditional statement) visibility conditions of items in an assessment." .
161+
162+
reproschema:jsExpression a rdf:Property ;
163+
rdfs:label "JavaScript Expression" ;
164+
schema:domainIncludes reproschema:Scoring ;
165+
schema:rangeIncludes schema:Boolean,
166+
schema:Text ;
167+
rdfs:comment "A JavaScript expression to compute a score from other variables." .
168+
169+
reproschema:landingPage a rdf:Property ;
170+
rdfs:label "Landing page content" ;
171+
schema:domainIncludes reproschema:Protocol ;
172+
schema:rangeIncludes schema:Text,
173+
schema:URL ;
174+
rdfs:comment "An element (by URL) to point to the protocol readme or landing page." .
175+
176+
reproschema:multipleChoice a rdf:Property ;
177+
rdfs:label "Multiple choice response expectation" ;
178+
schema:domainIncludes reproschema:ResponseOption ;
179+
schema:rangeIncludes schema:Boolean ;
180+
rdfs:comment "Indicates (by bool) if response for the Field item has one or more answer." .
181+
182+
reproschema:order a rdf:Property ;
183+
rdfs:label "Order" ;
184+
schema:domainIncludes reproschema:Activity,
185+
reproschema:Protocol ;
186+
schema:rangeIncludes schema:URL,
187+
reproschema:Activity,
188+
reproschema:Field ;
189+
rdfs:comment "An ordered list to describe the order in which the items of an assessment or protocol appear in the user interface." .
190+
191+
reproschema:preamble a rdf:Property ;
192+
rdfs:label "Preamble" ;
193+
schema:domainIncludes reproschema:Activity,
194+
reproschema:Field ;
195+
schema:rangeIncludes schema:Text,
196+
rdf:langString ;
197+
rdfs:comment "The preamble for an assessment" .
198+
199+
reproschema:responseOptions a rdf:Property ;
200+
rdfs:label "Response options" ;
201+
schema:domainIncludes reproschema:Field ;
202+
schema:rangeIncludes schema:URL,
203+
reproschema:ResponseOption ;
204+
rdfs:comment "An element (object or by URL)to describe the properties of response of the Field item." .
205+
206+
reproschema:scoringLogic a rdf:Property ;
207+
rdfs:label "Scoring logic objects" ;
208+
schema:domainIncludes reproschema:Activity,
209+
reproschema:Protocol ;
210+
schema:rangeIncludes reproschema:Scoring ;
211+
rdfs:comment "An array of objects indicating score in an activity or protocol and maps it to the score Field item " .
212+
213+
reproschema:shuffle a rdf:Property ;
214+
rdfs:label "Shuffle" ;
215+
schema:domainIncludes reproschema:Activity,
216+
reproschema:Protocol ;
217+
schema:rangeIncludes schema:boolean ;
218+
rdfs:comment "An element (bool) to determine if the list of items is shuffled or in order." .
219+
220+
reproschema:statusOptions a rdf:Property ;
221+
rdfs:label "Status options" ;
222+
schema:rangeIncludes schema:Text ;
223+
rdfs:comment "Provides information on whether or not a field item wants to be accompanied by the additional status option(s) defined in “statusOptions”" .
224+
225+
reproschema:valueType a rdf:Property ;
226+
rdfs:label "The type of the response" ;
227+
schema:domainIncludes reproschema:ResponseOption ;
228+
schema:rangeIncludes schema:Text,
229+
rdf:langString ;
230+
rdfs:comment "The type of the response of an item. For example, string, integer, etc." .
231+
232+
reproschema:variableName a rdf:Property ;
233+
rdfs:label "variableName" ;
234+
schema:domainIncludes reproschema:AdditionalProperty,
235+
reproschema:Scoring ;
236+
schema:rangeIncludes schema:Text ;
237+
rdfs:comment "The name used to represent an item." .
238+
239+
skos:prefLabel a rdf:Property ;
240+
rdfs:label "prefLabel" ;
241+
schema:domainIncludes reproschema:Activity,
242+
reproschema:AdditionalProperty,
243+
reproschema:Field,
244+
reproschema:Protocol ;
245+
schema:rangeIncludes schema:Text ;
246+
rdfs:comment "Indicates the label of an Activity or Field to be used as display name.",
247+
"Indicates the label of the Field.",
248+
"The preferred name of the assessment." .

reproschema/tests/test_validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
def test_validate():
77
os.chdir(os.path.dirname(__file__))
8-
assert validate_dir("data", os.path.abspath("validation"))
8+
assert validate_dir("data", os.path.abspath("reproschema-shacl.ttl"))
99

1010

1111
def test_type_error():
1212
os.chdir(os.path.dirname(__file__))
1313
with pytest.raises(ValueError):
14-
validate_dir("contexts", os.path.abspath("validation"))
14+
validate_dir("contexts", os.path.abspath("reproschema-shacl.ttl"))
1515

1616

1717
def test_url():
1818
url = "https://raw.githubusercontent.com/ReproNim/reproschema-py/master/reproschema/tests/data/activities/activity1.jsonld"
19-
assert validate(os.path.abspath("validation"), url)
19+
assert validate(os.path.abspath("reproschema-shacl.ttl"), url)

0 commit comments

Comments
 (0)