@@ -112,13 +112,13 @@ from hermes.model import SoftwareMetadata
112112# {
113113# "@context":
114114# {
115- # "baz ": "https://schema.org/Thing "
115+ # "name ": "https://schema.org/name "
116116# }
117117# }
118118
119119data = SoftwareMetadata(extra_vocabs={"foo": "https://bar.net/schema.jsonld"})
120120
121- data["foo:baz "] = ...
121+ data["foo:name "] = ...
122122```
123123
124124##### Adding data
@@ -131,8 +131,8 @@ i.e., metadata that describes software:
131131data["name"] = "My Research Software" # A simple "Text"-type value
132132# → Simplified model representation : { "name": [ "My Research Software" ] }
133133# Cf. "Accessing data" below
134- data["author"] = {"name": "Foo "} # An object value that uses terms available in the defined context
135- # → Simplified model representation : { "name": [ "My Research Software" ], "author": [ { "name": "Foo " } ] }
134+ data["author"] = {"name": "Shakespeare "} # An object value that uses terms available in the defined context
135+ # → Simplified model representation : { "name": [ "My Research Software" ], "author": [ { "name": "Shakespeare " } ] }
136136# Cf. "Accessing data" below
137137```
138138
@@ -153,14 +153,14 @@ will treat it as an array, i.e., a list-like object:
153153``` {code-block} python
154154:caption: Internal data values are arrays
155155data["name"] = "My Research Software" # → [ "My Research Software" ]
156- data["author"] = {"name": "Foo "} # → [ { "name": [ "Foo " ] } ]
156+ data["author"] = {"name": "Shakespeare "} # → [ { "name": [ "Shakespeare " ] } ]
157157```
158158
159159Therefore, you access data in the same way you would access data from a Python ` list ` :
160160
1611611 . You access single values using indices, e.g., ` data["name"][0] ` .
1621622 . You can use a list-like API to interact with data objects, e.g.,
163- ` data["name"].append("Bar ") ` , ` data["name"].extend(["Bar ", "Baz "]) ` , ` for name in data["name"]: ... ` , etc.
163+ ` data["name"].append("Hamilton ") ` , ` data["name"].extend(["Hamilton ", "Knuth "]) ` , ` for name in data["name"]: ... ` , etc.
164164
165165##### Interacting with data
166166
@@ -176,32 +176,32 @@ data = SoftwareMetadata()
176176# Let's create author metadata for our software!
177177# Below each line of code, the value of `data["author"]` is given.
178178
179- data["author"] = {"name": "Foo "}
180- # → [{'name': ['Foo ']}]
179+ data["author"] = {"name": "Shakespeare "}
180+ # → [{'name': ['Shakespeare ']}]
181181
182- data["author"].append({"name": "Bar "})
183- # [{'name': ['Foo ']}, {'name': ['Bar ']}]
182+ data["author"].append({"name": "Hamilton "})
183+ # [{'name': ['Shakespeare ']}, {'name': ['Hamilton ']}]
184184
185- data["author"][0]["email"] = "foo @baz.net"
186- # [{'name': ['Foo '], 'email': ['foo @baz.net']}, {'name': ['Bar ']}]
185+ data["author"][0]["email"] = "Shakespeare @baz.net"
186+ # [{'name': ['Shakespeare '], 'email': ['shakespeare @baz.net']}, {'name': ['Hamilton ']}]
187187
188- data["author"][1]["email"].append("bar @baz.net")
189- # [{'name': ['Foo '], 'email': ['foo @baz.net']}, {'name': ['Bar '], 'email': ['bar @baz.net']}]
188+ data["author"][1]["email"].append("Hamilton @baz.net")
189+ # [{'name': ['Shakespeare '], 'email': ['shakespeare @baz.net']}, {'name': ['Hamilton '], 'email': ['hamilton @baz.net']}]
190190
191- data["author"][1]["email"].extend(["bar @spam.org", "bar @eggs.com"])
191+ data["author"][1]["email"].extend(["hamilton @spam.org", "hamilton @eggs.com"])
192192# [
193- # {'name': ['Foo '], 'email': ['foo @baz.net']},
194- # {'name': ['Bar '], 'email': ['bar @baz.net', 'bar @spam.org', 'bar @eggs.com']}
193+ # {'name': ['Shakespeare '], 'email': ['shakespeare @baz.net']},
194+ # {'name': ['Hamilton '], 'email': ['hamilton @baz.net', 'hamilton @spam.org', 'hamilton @eggs.com']}
195195# ]
196196```
197197
198198The example continues to show how to iterate through data.
199199
200200``` {code-block} python
201201:caption: for-loop, containment check
202- for i, author in enumerate(data["author"]):
203- if author["name"][0] in ["Foo ", "Bar "]:
204- print(f"Author {i + 1 } has expected name.")
202+ for i, author in enumerate(data["author"], start=1 ):
203+ if author["name"][0] in ["Shakespeare ", "Hamilton "]:
204+ print(f"Author {i} has expected name.")
205205 else:
206206 raise ValueError("Unexpected author name found!", author["name"][0])
207207
@@ -224,7 +224,7 @@ for email in data["author"][0]["email"]:
224224
225225``` {code-block} python
226226:caption: Value check and list comprehension
227- if ["bar " in email for email in data["author"][1]["email"]]:
227+ if all(["hamilton " in email for email in data["author"][1]["email"]]) :
228228 print("Author has only emails with their name in it.")
229229
230230# Mock output
@@ -248,7 +248,7 @@ Python data:
248248:emphasize-lines: 5,13
249249try:
250250 assert (
251- {'name': ['Foo '], 'email': ['foo @baz.net']}
251+ {'name': ['Shakespeare '], 'email': ['shakespeare @baz.net']}
252252 in
253253 data["author"]
254254 )
@@ -261,19 +261,19 @@ except AssertionError:
261261# $> The author could not be found.
262262# $> AssertionError:
263263# assert
264- # {'email': ['foo @baz.net'], 'name': ['Foo ']}
264+ # {'email': ['shakespeare @baz.net'], 'name': ['Shakespeare ']}
265265# in
266266# _LDList(
267267# {'@list': [
268268# {
269- # 'http://schema.org/name': [{'@value': 'Foo '}],
270- # 'http://schema.org/email': [{'@value': 'foo @baz.net'}]
269+ # 'http://schema.org/name': [{'@value': 'Shakespeare '}],
270+ # 'http://schema.org/email': [{'@value': 'shakespeare @baz.net'}]
271271# },
272272# {
273- # 'http://schema.org/name': [{'@value': 'Bar '}],
273+ # 'http://schema.org/name': [{'@value': 'Hamilton '}],
274274# 'http://schema.org/email': [
275275# {'@list': [
276- # {'@value': 'bar @baz.net'}, {'@value': 'bar @spam.org'}, {'@value': 'bar @eggs.com'}
276+ # {'@value': 'hamilton @baz.net'}, {'@value': 'hamilton @spam.org'}, {'@value': 'hamilton @eggs.com'}
277277# ]}
278278# ]
279279# }]
@@ -294,7 +294,7 @@ This function can be used in assertions to assert full data integrity:
294294:emphasize-lines: 5,13
295295try:
296296 assert (
297- {'name': ['Foo '], 'email': ['foo @baz.net']}
297+ {'name': ['Shakespeare '], 'email': ['Shakespeare @baz.net']}
298298 in
299299 data["author"].to_python()
300300 )
0 commit comments