Skip to content

Commit fcb356d

Browse files
committed
Merge branch 'mqnifestkelvin-feature_xml_3' into test_xml3
2 parents 78735ed + df17fd0 commit fcb356d

14 files changed

+649
-5
lines changed

examples/document.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
from modelspec.utils import save_to_xml_file
56

67
# Example showing how to create a model of a document and use it to create/serialize instances
78

@@ -70,10 +71,12 @@ class Document(Base):
7071
doc.to_json_file("document.json")
7172
doc.to_yaml_file("document.yaml")
7273
doc.to_bson_file("document.bson")
74+
doc.to_xml_file("document.xml")
7375

7476
print(" >> Full document details in YAML format:\n")
7577

7678
print(doc.to_yaml())
79+
print(doc.to_xml())
7780

7881
doc_md = doc.generate_documentation(format="markdown")
7982

@@ -106,3 +109,5 @@ class Document(Base):
106109

107110
with open("document.specification.bson", "wb") as d:
108111
d.write(bson.encode(doc_dict))
112+
113+
save_to_xml_file(doc_dict, "document.specification.xml")

examples/document.specification.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" ?>
2+
<modelspec>
3+
<Document>
4+
<definition>A model for documents.</definition>
5+
<allowed_parameters>
6+
<id>
7+
<type>str</type>
8+
<description>The unique id of the document</description>
9+
</id>
10+
<title>
11+
<type>str</type>
12+
<description>The document title</description>
13+
</title>
14+
<ISBN>
15+
<type>int</type>
16+
<description>International Standard Book Number</description>
17+
</ISBN>
18+
</allowed_parameters>
19+
<allowed_children>
20+
<sections>
21+
<type>Section</type>
22+
<description>The sections of the document</description>
23+
</sections>
24+
</allowed_children>
25+
</Document>
26+
<Section>
27+
<definition>A model of a section of the :class:`Document`. Will contain one :class:`Paragraph` or more, i.e the :class:`Paragraph`(s) in the section, probably related to the :code:`title` of the `Document &lt;#document&gt;`_.</definition>
28+
<allowed_parameters>
29+
<id>
30+
<type>str</type>
31+
<description>The id of the section</description>
32+
</id>
33+
</allowed_parameters>
34+
<allowed_children>
35+
<paragraphs>
36+
<type>Paragraph</type>
37+
<description>The paragraphs</description>
38+
</paragraphs>
39+
</allowed_children>
40+
</Section>
41+
<Paragraph>
42+
<definition>A model of a paragraph.</definition>
43+
<allowed_parameters>
44+
<contents>
45+
<type>str</type>
46+
<description>Paragraph contents, which make up the :class:`Section`s.</description>
47+
</contents>
48+
</allowed_parameters>
49+
</Paragraph>
50+
</modelspec>

examples/document.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" ?>
2+
<modelspec>
3+
<MyBook>
4+
<title>My life in Python</title>
5+
<sections>
6+
<Abstract>
7+
<paragraphs>
8+
<contents>Blah blah blah</contents>
9+
</paragraphs>
10+
<paragraphs>
11+
<contents>Blah2</contents>
12+
</paragraphs>
13+
</Abstract>
14+
<Chapter_1>
15+
<paragraphs>
16+
<contents>More...</contents>
17+
</paragraphs>
18+
</Chapter_1>
19+
</sections>
20+
</MyBook>
21+
</modelspec>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0" ?>
2+
<modelspec>
3+
<NeuroML>
4+
<definition>Some description...</definition>
5+
<allowed_parameters>
6+
<id>
7+
<type>str</type>
8+
<description>The id of the NeuroML 2 document</description>
9+
</id>
10+
<version>
11+
<type>str</type>
12+
<description>NeuroML version used</description>
13+
</version>
14+
</allowed_parameters>
15+
<allowed_children>
16+
<izhikevich2007Cells>
17+
<type>Izhikevich2007Cell</type>
18+
<description/>
19+
</izhikevich2007Cells>
20+
<pulseGenerators>
21+
<type>PulseGenerator</type>
22+
<description/>
23+
</pulseGenerators>
24+
<networks>
25+
<type>Network</type>
26+
<description>The networks present</description>
27+
</networks>
28+
</allowed_children>
29+
</NeuroML>
30+
<Izhikevich2007Cell>
31+
<definition>Some description...</definition>
32+
<allowed_parameters>
33+
<id>
34+
<type>str</type>
35+
<description>The id of the cell...</description>
36+
</id>
37+
<C>
38+
<type>str</type>
39+
<description/>
40+
</C>
41+
<v0>
42+
<type>str</type>
43+
<description/>
44+
</v0>
45+
<k>
46+
<type>str</type>
47+
<description/>
48+
</k>
49+
<vr>
50+
<type>str</type>
51+
<description/>
52+
</vr>
53+
<vt>
54+
<type>str</type>
55+
<description/>
56+
</vt>
57+
<vpeak>
58+
<type>str</type>
59+
<description/>
60+
</vpeak>
61+
<a>
62+
<type>str</type>
63+
<description/>
64+
</a>
65+
<b>
66+
<type>str</type>
67+
<description/>
68+
</b>
69+
<c>
70+
<type>str</type>
71+
<description/>
72+
</c>
73+
<d>
74+
<type>str</type>
75+
<description/>
76+
</d>
77+
</allowed_parameters>
78+
</Izhikevich2007Cell>
79+
<PulseGenerator>
80+
<definition>Some description...</definition>
81+
<allowed_parameters>
82+
<id>
83+
<type>str</type>
84+
<description>The id of the pulseGenerator</description>
85+
</id>
86+
<delay>
87+
<type>str</type>
88+
<description>the delay</description>
89+
</delay>
90+
<duration>
91+
<type>str</type>
92+
<description>the duration</description>
93+
</duration>
94+
<amplitude>
95+
<type>str</type>
96+
<description>the amplitude</description>
97+
</amplitude>
98+
</allowed_parameters>
99+
</PulseGenerator>
100+
<Network>
101+
<definition>Some description...</definition>
102+
<allowed_parameters>
103+
<id>
104+
<type>str</type>
105+
<description>The id of the network</description>
106+
</id>
107+
</allowed_parameters>
108+
<allowed_children>
109+
<populations>
110+
<type>Population</type>
111+
<description>the pops in the net</description>
112+
</populations>
113+
<explicitInputs>
114+
<type>ExplicitInput</type>
115+
<description/>
116+
</explicitInputs>
117+
</allowed_children>
118+
</Network>
119+
<Population>
120+
<definition>Some description...</definition>
121+
<allowed_parameters>
122+
<id>
123+
<type>str</type>
124+
<description>The id of the population</description>
125+
</id>
126+
<component>
127+
<type>str</type>
128+
<description>the component to use in the population</description>
129+
</component>
130+
<size>
131+
<type>int</type>
132+
<description>the size of the population</description>
133+
</size>
134+
</allowed_parameters>
135+
</Population>
136+
<ExplicitInput>
137+
<definition>Some description...</definition>
138+
<allowed_parameters>
139+
<target>
140+
<type>str</type>
141+
<description>the target of the input</description>
142+
</target>
143+
<input>
144+
<type>str</type>
145+
<description>the input, e.g. pulseGenerator</description>
146+
</input>
147+
</allowed_parameters>
148+
</ExplicitInput>
149+
</modelspec>

examples/neuroml2/TestNeuroML.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" ?>
2+
<modelspec>
3+
<TestNeuroML>
4+
<version>NeuroML_v2.3</version>
5+
<izhikevich2007Cells>
6+
<izh2007RS0>
7+
<C>100pF</C>
8+
<v0>-60mV</v0>
9+
<k>0.7nS_per_mV</k>
10+
<vr>-60mV</vr>
11+
<vt>-40mV</vt>
12+
<vpeak>35mV</vpeak>
13+
<a>0.03per_ms</a>
14+
<b>-2nS</b>
15+
<c>-50.0mV</c>
16+
<d>100pA</d>
17+
</izh2007RS0>
18+
</izhikevich2007Cells>
19+
<pulseGenerators>
20+
<pulseGen_0>
21+
<delay>100ms</delay>
22+
<duration>800ms</duration>
23+
<amplitude>0.07 nA</amplitude>
24+
</pulseGen_0>
25+
</pulseGenerators>
26+
<networks>
27+
<IzNet>
28+
<populations>
29+
<IzhPop0>
30+
<component>izh2007RS0</component>
31+
<size>1</size>
32+
</IzhPop0>
33+
</populations>
34+
<explicitInputs>
35+
<target>IzhPop0[0]</target>
36+
<input>pulseGen_0</input>
37+
</explicitInputs>
38+
</IzNet>
39+
</networks>
40+
</TestNeuroML>
41+
</modelspec>

examples/neuroml2/neuroml2_spec.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
from modelspec.utils import save_to_xml_file
56

67
# Example showing ...
78

@@ -148,11 +149,12 @@ class NeuroML(Base):
148149
nml_doc.to_json_file("%s.json" % nml_doc.id)
149150
nml_doc.to_yaml_file("%s.yaml" % nml_doc.id)
150151
nml_doc.to_bson_file("%s.bson" % nml_doc.id)
151-
# nml_doc.to_xml_file("%s.xml"%nml_doc.id)
152+
nml_doc.to_xml_file("%s.xml" % nml_doc.id)
152153

153154
print(" >> Full document details in YAML format:\n")
154155

155156
print(nml_doc.to_yaml())
157+
print(nml_doc.to_xml())
156158

157159
print("Generating documentation...")
158160

@@ -181,3 +183,5 @@ class NeuroML(Base):
181183
yy = yaml.dump(doc_dict, indent=4, sort_keys=False)
182184
print(yy)
183185
d.write(yy)
186+
187+
save_to_xml_file(doc_dict, "NeuroML2.specification.xml")

0 commit comments

Comments
 (0)