Skip to content

Commit b4f86e0

Browse files
committed
Merge branch 'feature_xml_3' of github.com:mqnifestkelvin/modelspec into mqnifestkelvin-feature_xml_3
2 parents 78735ed + aaf8bdf commit b4f86e0

22 files changed

+561
-79
lines changed

examples/document.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A model for documents.
3030
<table>
3131
<tr>
3232
<td><b>sections</b></td>
33-
<td><a href="#section">Section</a></td>
33+
<td><a href="#list">List</a></td>
3434
<td><i>The sections of the document</i></td>
3535
</tr>
3636

@@ -55,7 +55,7 @@ A model of a section of the <a href="#document">Document</a>. Will contain one <
5555
<table>
5656
<tr>
5757
<td><b>paragraphs</b></td>
58-
<td><a href="#paragraph">Paragraph</a></td>
58+
<td><a href="#list">List</a></td>
5959
<td><i>The paragraphs</i></td>
6060
</tr>
6161

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.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Allowed field Data Type Description
1515

1616
**Allowed children**
1717

18-
=============== ====================== ============================
19-
Allowed child Data Type Description
20-
=============== ====================== ============================
21-
**sections** `Section <#section>`__ The sections of the document
22-
=============== ====================== ============================
18+
=============== ================ ============================
19+
Allowed child Data Type Description
20+
=============== ================ ============================
21+
**sections** `List <#list>`__ The sections of the document
22+
=============== ================ ============================
2323

2424
=======
2525
Section
@@ -36,11 +36,11 @@ Allowed field Data Type Description
3636

3737
**Allowed children**
3838

39-
=============== ========================== ==============
40-
Allowed child Data Type Description
41-
=============== ========================== ==============
42-
**paragraphs** `Paragraph <#paragraph>`__ The paragraphs
43-
=============== ========================== ==============
39+
=============== ================ ==============
40+
Allowed child Data Type Description
41+
=============== ================ ==============
42+
**paragraphs** `List <#list>`__ The paragraphs
43+
=============== ================ ==============
4444

4545
=========
4646
Paragraph

examples/document.specification.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"allowed_children": {
1919
"sections": {
20-
"type": "Section",
20+
"type": "List",
2121
"description": "The sections of the document"
2222
}
2323
}
@@ -32,7 +32,7 @@
3232
},
3333
"allowed_children": {
3434
"paragraphs": {
35-
"type": "Paragraph",
35+
"type": "List",
3636
"description": "The paragraphs"
3737
}
3838
}

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+
<root>
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>List</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>List</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+
</root>

examples/document.specification.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Document:
1212
description: International Standard Book Number
1313
allowed_children:
1414
sections:
15-
type: Section
15+
type: List
1616
description: The sections of the document
1717
Section:
1818
definition: A model of a section of the :class:`Document`. Will contain one :class:`Paragraph`
@@ -24,7 +24,7 @@ Section:
2424
description: The id of the section
2525
allowed_children:
2626
paragraphs:
27-
type: Paragraph
27+
type: List
2828
description: The paragraphs
2929
Paragraph:
3030
definition: A model of a paragraph.

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>

examples/neuroml2/NeuroML2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Some description...
3737

3838
<tr>
3939
<td><b>networks</b></td>
40-
<td><a href="#network">Network</a></td>
40+
<td><a href="#list">List</a></td>
4141
<td><i>The networks present</i></td>
4242
</tr>
4343

@@ -181,7 +181,7 @@ Some description...
181181
<table>
182182
<tr>
183183
<td><b>populations</b></td>
184-
<td><a href="#population">Population</a></td>
184+
<td><a href="#list">List</a></td>
185185
<td><i>the pops in the net</i></td>
186186
</tr>
187187

examples/neuroml2/NeuroML2.rst

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,11 @@ Allowed field Data Type Description
1414

1515
**Allowed children**
1616

17-
======================= ============================================ ====================
18-
Allowed child Data Type Description
19-
======================= ============================================ ====================
20-
**izhikevich2007Cells** `Izhikevich2007Cell <#izhikevich2007cell>`__
21-
**pulseGenerators** `PulseGenerator <#pulsegenerator>`__
22-
**networks** `Network <#network>`__ The networks present
23-
======================= ============================================ ====================
24-
25-
==================
26-
Izhikevich2007Cell
27-
==================
28-
Some description...
29-
30-
**Allowed parameters**
31-
32-
=============== =========== =====================
33-
Allowed field Data Type Description
34-
=============== =========== =====================
35-
**id** str The id of the cell...
36-
**C** str
37-
**v0** str
38-
**k** str
39-
**vr** str
40-
**vt** str
41-
**vpeak** str
42-
**a** str
43-
**b** str
44-
**c** str
45-
**d** str
46-
=============== =========== =====================
47-
48-
==============
49-
PulseGenerator
50-
==============
51-
Some description...
52-
53-
**Allowed parameters**
54-
55-
=============== =========== ============================
56-
Allowed field Data Type Description
57-
=============== =========== ============================
58-
**id** str The id of the pulseGenerator
59-
**delay** str the delay
60-
**duration** str the duration
61-
**amplitude** str the amplitude
62-
=============== =========== ============================
17+
=============== ================ ====================
18+
Allowed child Data Type Description
19+
=============== ================ ====================
20+
**networks** `List <#list>`__ The networks present
21+
=============== ================ ====================
6322

6423
=======
6524
Network
@@ -76,12 +35,11 @@ Allowed field Data Type Description
7635

7736
**Allowed children**
7837

79-
================== ================================== ===================
80-
Allowed child Data Type Description
81-
================== ================================== ===================
82-
**populations** `Population <#population>`__ the pops in the net
83-
**explicitInputs** `ExplicitInput <#explicitinput>`__
84-
================== ================================== ===================
38+
=============== ================ ===================
39+
Allowed child Data Type Description
40+
=============== ================ ===================
41+
**populations** `List <#list>`__ the pops in the net
42+
=============== ================ ===================
8543

8644
==========
8745
Population

examples/neuroml2/NeuroML2.specification.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"description": ""
2222
},
2323
"networks": {
24-
"type": "Network",
24+
"type": "List",
2525
"description": "The networks present"
2626
}
2727
}
@@ -106,7 +106,7 @@
106106
},
107107
"allowed_children": {
108108
"populations": {
109-
"type": "Population",
109+
"type": "List",
110110
"description": "the pops in the net"
111111
},
112112
"explicitInputs": {

0 commit comments

Comments
 (0)