Data Access
Getters
Functions to retrieve configuration data and questionnaire values for MaRDMO.
Provides fast, app-config-backed accessors for Wikibase vocabulary (items,
properties), ontology registries (MathModDB, MathAlgoDB), RDMO question
definitions, and project answer values. Most getters are thin wrappers
around :attr:~MaRDMO.apps.MaRDMOConfig attributes or
:func:~functools.lru_cache-decorated file readers.
Provides:
get_mathmoddb— return a :class:~.helpers.PropertyRegistryfor MathModDBget_mathalgodb— return a :class:~.helpers.PropertyRegistryfor MathAlgoDBget_publication_mapping— return a :class:~.helpers.PropertyRegistryfor shared publication rolesget_options— return the RDMO options dict from the app configget_items— return the Wikibase items dict from the app configget_properties— return the Wikibase properties dict from the app configget_questions— return the questions sub-dict for a given catalog sectionget_url— return a configured URL for a Wikibase providerget_item_url— return the base item-browse URL for a Wikibase providerget_data— load and cache JSON data from a package-relative fileget_sparql_query— load and cache a SPARQL query fileget_sparql_query_optional— load and cache a SPARQL query file, orNoneif absentget_id— retrieve attribute field(s) from all questionnaire values at a URIget_answers— read questionnaire values for one attribute and merge into a dictget_user_entries— fetch raw ID/name/description values for a domain attribute
get_answers(project, val, config)
Read questionnaire values for one attribute and merge them into val.
Iterates over all :class:~rdmo.projects.models.Value objects for the
attribute described by config, determines the appropriate path in val
via a :data:~.constants.flag_dict handler, and calls
:func:~.helpers.nested_set to write the entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
RDMO project instance. |
required | |
val
|
Top-level answers dict that is mutated in place. |
required | |
config
|
Dict describing how to map a questionnaire attribute to val:
|
required |
Returns:
| Type | Description |
|---|---|
|
The mutated val dict. |
Source code in MaRDMO/getters.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
get_data(file_name)
cached
Load and return JSON data from a file relative to the MaRDMO package root.
Result is cached indefinitely after the first read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
Path relative to the package directory (e.g. |
required |
Returns:
| Type | Description |
|---|---|
|
Parsed JSON value (typically a dict or list). |
Source code in MaRDMO/getters.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_id(project, uri, keys)
Retrieve one or more attribute fields from all questionnaire values at uri.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
RDMO project instance. |
required | |
uri
|
Full RDMO attribute URI to filter on. |
required | |
keys
|
List of :class: |
required |
Returns:
| Type | Description |
|---|---|
|
List of scalar values (single-key case) or list of lists (multi-key |
|
|
case), one entry per matching questionnaire value. |
Source code in MaRDMO/getters.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
get_item_url(source)
Return the base URL for browsing Wikibase items on a provider's wiki.
Wikidata URI is taken from the internal :data:~MaRDMO.constants.WIKIDATA
constant. All other sources are read from settings.MARDMO_PROVIDER.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Provider key — |
required |
Returns:
| Type | Description |
|---|---|
|
URL string ending in |
Source code in MaRDMO/getters.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_items()
Return the Wikibase items dict from the app config.
Returns:
| Type | Description |
|---|---|
|
Dict mapping item label strings to Wikibase QID strings. |
Source code in MaRDMO/getters.py
80 81 82 83 84 85 86 | |
get_mathalgodb()
Return a :class:~.helpers.PropertyRegistry for the MathAlgoDB ontology.
Returns:
| Type | Description |
|---|---|
|
class: |
|
|
attr: |
Source code in MaRDMO/getters.py
50 51 52 53 54 55 56 57 58 59 | |
get_mathmoddb()
Return a :class:~.helpers.PropertyRegistry for the MathModDB ontology.
Returns:
| Type | Description |
|---|---|
|
class: |
|
|
attr: |
Source code in MaRDMO/getters.py
39 40 41 42 43 44 45 46 47 48 | |
get_options()
Return the RDMO options dict from the app config.
Returns:
| Type | Description |
|---|---|
|
Dict mapping RDMO option URIs to display strings. |
Source code in MaRDMO/getters.py
72 73 74 75 76 77 78 | |
get_properties()
Return the Wikibase properties dict from the app config.
Returns:
| Type | Description |
|---|---|
|
Dict mapping property label strings to Wikibase property ID strings. |
Source code in MaRDMO/getters.py
88 89 90 91 92 93 94 | |
get_publication_mapping()
Return a :class:~.helpers.PropertyRegistry for the shared publication role options.
Returns:
| Type | Description |
|---|---|
|
class: |
|
|
attr: |
Source code in MaRDMO/getters.py
61 62 63 64 65 66 67 68 69 70 | |
get_questions(question_set)
Return the questions sub-dict for a given catalog question set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question_set
|
Key identifying the question set (catalog section name). |
required |
Returns:
| Type | Description |
|---|---|
|
Dict mapping question names to their RDMO attribute URI fragments and |
|
|
related metadata. |
Source code in MaRDMO/getters.py
96 97 98 99 100 101 102 103 104 105 106 | |
get_sparql_query(file_name)
cached
Load and return the contents of a SPARQL query file.
Result is cached indefinitely after the first read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
Path relative to the package directory (e.g.
|
required |
Returns:
| Type | Description |
|---|---|
|
Query string (may contain |
Source code in MaRDMO/getters.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_sparql_query_optional(file_name)
cached
Load a SPARQL query file, returning None if the file does not exist.
Result is cached indefinitely after the first read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
Path relative to the package directory. |
required |
Returns:
| Type | Description |
|---|---|
|
Query string on success; |
Source code in MaRDMO/getters.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
get_url(source, url_type)
Return a URL for a Wikibase provider.
Wikidata URLs are taken from the internal :data:~MaRDMO.constants.WIKIDATA
constant. All other sources are read from settings.MARDMO_PROVIDER.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Provider key — |
required | |
url_type
|
URL type key — one of |
required |
Returns:
| Type | Description |
|---|---|
|
URL string for the requested source and type. |
Source code in MaRDMO/getters.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
get_user_entries(project, query_attribute, values)
Fetch raw ID, Name, and Description questionnaire values for a domain attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
RDMO project instance. |
required | |
query_attribute
|
Attribute path fragment (e.g. |
required | |
values
|
Dict to populate; mutated in place. |
required |
Returns:
| Type | Description |
|---|---|
|
The values dict with keys |
|
|
each holding a :class: |
|
|
class: |
Source code in MaRDMO/getters.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
Queries
Functions that query external data sources (Wikibase API, SPARQL endpoints, Crossref, etc.).
Provides helpers for:
query_item/query_api– Wikibasewbsearchentitieslookupsquery_sparql/query_sparql_pool– SPARQL SELECT requestsquery_sources/query_sources_with_user_additions– combined MaRDI + Wikidata search with optional user-defined entriesquery_api_per_class– class-filtered full-text search on the MaRDI portal
query_api(api_url, search_term, timeout=5)
Search a Wikibase API endpoint for items whose label matches search_term.
Uses the wbsearchentities action with limit=10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url
|
Full URL of the Wikibase API endpoint. |
required | |
search_term
|
Label string to search for. |
required | |
timeout
|
Request timeout in seconds (default 5). |
5
|
Returns:
| Type | Description |
|---|---|
|
List of raw Wikibase search-result dicts; empty list on any error. |
Source code in MaRDMO/queries.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
query_api_per_class(search_term, item_class)
Search the MaRDI portal for items belonging to one or more Wikibase classes.
Performs a MediaWiki full-text search filtered by
haswbstatement:<instance-of>=QID (combined with | for multiple
classes), then fetches English labels and descriptions for the matching
QIDs via wbgetentities. The "instance of" property ID is read from
the configured properties.json so it works across portals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_term
|
str
|
Free-text search string (appended with |
required |
item_class
|
QID string or list of QID strings; e.g. |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of |
list[dict]
|
dicts; empty list on any network error or no hits. |
Source code in MaRDMO/queries.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
query_item(label, description, api=get_url('mardi', 'api'))
Search a Wikibase API for an item matching label and description exactly.
Skips the request if description is empty or the placeholder string
"No Description Provided!".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Label (or alias) to search for (case-insensitive). |
required | |
description
|
Exact description the matched item must have. |
required | |
api
|
Wikibase |
get_url('mardi', 'api')
|
Returns:
| Type | Description |
|---|---|
|
The Wikibase QID string of the first match, or |
Source code in MaRDMO/queries.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
query_sources(search, item_class=[], sources=None, not_found=True)
Query one or more knowledge-graph sources for items matching search.
Queries the requested sources in parallel, merges the results, and sorts
them by relevance to search using :func:~.helpers.rank_by_search_term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search
|
Free-text search string. |
required | |
item_class
|
QID string or list of QID strings used for class-filtered
search on MaRDI (e.g. |
[]
|
|
sources
|
List of source keys to query; defaults to
|
None
|
|
not_found
|
If |
True
|
Returns:
| Type | Description |
|---|---|
|
List of |
Source code in MaRDMO/queries.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
query_sources_with_user_additions(search, project, setup)
Fetch KG options, prepend matching user-defined entries, and optionally allow creation.
Combines external source results (via :func:query_sources) with entries
the user has already added to the questionnaire (cached by project/attribute).
Optionally inserts a creation option for new entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search
|
Free-text search string entered by the user. |
required | |
project
|
RDMO project instance used to look up existing user entries. |
required | |
setup
|
Configuration dict with keys:
|
required |
Returns:
| Type | Description |
|---|---|
|
List of |
Source code in MaRDMO/queries.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
query_sparql(query, sparql_endpoint)
Execute a SPARQL SELECT query against sparql_endpoint and return bindings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
SPARQL SELECT query string (UTF-8 encoded on the wire). |
required | |
sparql_endpoint
|
URL of the SPARQL endpoint (e.g. the MaRDI or Wikidata endpoint). |
required |
Returns:
| Type | Description |
|---|---|
|
List of result-binding dicts from |
|
|
any network error, HTTP error, or missing endpoint. |
Source code in MaRDMO/queries.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
query_sparql_pool(query_input)
Execute multiple SPARQL queries in parallel and return a keyed result dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_input
|
Dict mapping a source key to a |
required |
Returns:
| Type | Description |
|---|---|
|
Dict with the same keys as query_input, each mapping to the list of |
|
|
SPARQL result bindings returned by :func: |
Source code in MaRDMO/queries.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
query_user_entries(project, setup)
Build a label→ID dict from entries the user has already added to the questionnaire.
Reads ID, Name, and Description values from the RDMO database for each
attribute listed in setup["query_attributes"], aligns them by
set_index/set_prefix, and returns only entries whose source is not
in setup["sources"] (i.e. not already covered by KG results).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
RDMO project instance. |
required | |
setup
|
Configuration dict (see :func: |
required |
Returns:
| Type | Description |
|---|---|
|
Dict mapping display strings ( |
|
|
|
Source code in MaRDMO/queries.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |