py_ez_wikidata API Documentation
ezwd_cmd
Created on 2026-06-26
ezwd command line interface
@author: wf
EzWdCmd
Bases: BaseCmd
command line interface for easy Wikidata access: search Wikidata, inspect a named property mapping and create/update a Wikidata item from a record using that mapping.
Source code in ez_wikidata/ezwd_cmd.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 63 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 101 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 | |
__init__()
constructor
Source code in ez_wikidata/ezwd_cmd.py
29 30 31 32 33 | |
add_arguments(parser)
add the ezwd specific arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser(ArgumentParser)
|
the parser to add arguments to |
required |
Source code in ez_wikidata/ezwd_cmd.py
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 63 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 | |
create(name, record_path, lang, write, baseurl=None, strict=False)
create (or dry-run) a Wikidata item from the given record using the named property mapping
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str)
|
the mapping name (e.g. scholar) |
required | |
record_path(str)
|
path to the YAML/JSON record file |
required | |
lang(str)
|
the language to use |
required | |
write(bool)
|
if True actually write to Wikidata |
required | |
baseurl(str)
|
the wikibase baseurl to write to (defaults to production Wikidata) |
required | |
strict(bool)
|
if True set exit code 1 when the result has problems |
required |
Source code in ez_wikidata/ezwd_cmd.py
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 | |
handle_args(args)
handle the parsed arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args(Namespace)
|
the parsed arguments |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the arguments were handled |
Source code in ez_wikidata/ezwd_cmd.py
97 98 99 100 101 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 | |
list_mapping(name)
list the columns of the named property mapping
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str)
|
the mapping name (e.g. scholar) |
required |
Source code in ez_wikidata/ezwd_cmd.py
141 142 143 144 145 146 147 148 149 150 151 | |
load_record(record_path)
load a record from a YAML or JSON file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record_path(str)
|
path to the record file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the loaded record |
Source code in ez_wikidata/ezwd_cmd.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
search(search_for, lang, limit)
search Wikidata and print candidate q-id / label / description rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_for(str)
|
the text to search for |
required | |
lang(str)
|
the language to use |
required | |
limit(int)
|
the maximum number of results |
required |
Source code in ez_wikidata/ezwd_cmd.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
main(argv=None)
main entry point for the ezwd command line tool
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argv(list)
|
the command line arguments (defaults to sys.argv) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
the exit code |
Source code in ez_wikidata/ezwd_cmd.py
212 213 214 215 216 217 218 219 220 221 222 223 224 | |
trulytabular
Created on 2022-04-14
@author: wf
TrulyTabular
Bases: object
truly tabular SPARQL/RDF analysis
checks "how tabular" a query based on a list of properties of an itemclass is
Source code in ez_wikidata/trulytabular.py
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 63 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 101 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 227 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 298 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 368 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 451 452 453 454 455 456 457 | |
__init__(itemQid, propertyLabels=[], propertyIds=[], search_predicate='wdt:P31', where=None, endpointConf=None, lang='en', debug=False)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itemQid(str)
|
wikidata id of the type to analyze |
required | |
propertyLabels(list)
|
a list of labels of properties to be considered |
required | |
propertyIds(list)
|
a list of ids of properties to be considered |
required | |
search_predicate(str)
|
the search predicate to use e.g. instanceof / subclass of |
required | |
where(str)
|
extra where clause for instance selection (if any) |
required | |
endpoint(str)
|
the url of the SPARQL endpoint to be used |
required |
Source code in ez_wikidata/trulytabular.py
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
__str__()
Returns:
| Name | Type | Description |
|---|---|---|
str |
my text representation |
Source code in ez_wikidata/trulytabular.py
81 82 83 84 85 86 | |
addStatsColWithPercent(m, col, value, total)
add a statistics Column Args: m(dict): col(str): name of the column value: value total: total value
Source code in ez_wikidata/trulytabular.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
asText(long=True)
returns my content as a text representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
long(bool)
|
True if a long format including url is wished |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
a text representation of my content |
Source code in ez_wikidata/trulytabular.py
112 113 114 115 116 117 118 119 120 121 122 123 | |
count()
get my count
Source code in ez_wikidata/trulytabular.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
genPropertyStatistics()
generate the property Statistics
Returns:
| Name | Type | Description |
|---|---|---|
generator |
a generator of statistic dict rows |
Source code in ez_wikidata/trulytabular.py
436 437 438 439 440 441 442 443 444 445 446 | |
genWdPropertyStatistic(wdProperty, itemCount, withQuery=True)
generate a property Statistics Row for the given wikidata Property
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wdProperty(WikidataProperty)
|
the property to get the statistics for |
required | |
itemCount(int)
|
the total number of items to check |
required | |
withQuery(bool)
|
if true include the sparql query |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
a statistics row |
Source code in ez_wikidata/trulytabular.py
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 | |
generateSparqlQuery(genMap, listSeparator='⇹', naive=True, lang='en')
generate a SPARQL Query
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genMap(dict)
|
a dictionary of generation items aggregates/ignores/labels |
required | |
listSeparator(str)
|
the symbole to use as a list separator for GROUP_CONCAT |
required | |
naive(bool)
|
if True - generate a naive straight forward SPARQL query if False generate a proper truly tabular aggregate query |
required | |
lang(str)
|
the language to generate for |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the generated SPARQL Query |
Source code in ez_wikidata/trulytabular.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 227 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 | |
getPropertyStatistics()
get the property Statistics
Source code in ez_wikidata/trulytabular.py
448 449 450 451 452 453 454 455 456 457 | |
getQueryManager(lang='sparql', name='trulytabular', debug=False)
classmethod
get the query manager for the given language and fileName
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang(str)
|
the language of the queries to extract |
required | |
name(str)
|
the name of the manager containing the query specifications |
required | |
debug(bool)
|
if True set debugging on |
required |
Source code in ez_wikidata/trulytabular.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
mostFrequentPropertiesQuery(whereClause=None, minCount=0)
get the most frequently used properties
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
whereClause(str)
|
an extra WhereClause to use |
required |
Source code in ez_wikidata/trulytabular.py
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 304 305 306 307 308 309 310 311 312 313 314 315 | |
noneTabular(wdProperty)
get the none tabular result for the given Wikidata property
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wdProperty(WikidataProperty)
|
the Wikidata property |
required |
Source code in ez_wikidata/trulytabular.py
366 367 368 369 370 371 372 373 374 375 376 377 | |
noneTabularQuery(wdProperty, asFrequency=True)
get the none tabular entries for the given property
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wdProperty(WikidataProperty)
|
the property to analyze |
required | |
asFrequency(bool)
|
if true do a frequency analysis |
required |
Source code in ez_wikidata/trulytabular.py
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 | |
version
Created on 2024-03-01
@author: wf
Version
dataclass
Bases: object
Version handling for easy wikidata access
Source code in ez_wikidata/version.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
wbquery
Created on 2022-04-30
@author: wf
WikibaseQuery
Bases: object
a Query for Wikibase
Source code in ez_wikidata/wbquery.py
14 15 16 17 18 19 20 21 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 63 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 101 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 227 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 | |
__init__(entity, wpm=None, debug=False)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity(str)
|
the entity this query represents |
required | |
debug(bool)
|
if True switch on debugging |
required |
Source code in ez_wikidata/wbquery.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
addPropertyFromDescriptionRow(row)
add a property from the given row
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row(dict)
|
the row to add |
required |
Source code in ez_wikidata/wbquery.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
asSparql(filterClause=None, orderClause=None, pk=None, lang='en')
get the sparqlQuery for this query optionally applying a filterClause
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filterClause(str)
|
a filter to be applied (if any) |
required | |
orderClause(str)
|
an orderClause to be applied (if any) |
required | |
pk(str)
|
primaryKey (if any) |
required | |
lang(str)
|
the language to be used for labels |
required |
Source code in ez_wikidata/wbquery.py
166 167 168 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
getColumnTypeAndVarname(propName)
get a signature tuple consisting of columnName, propertType and SPARQL variable Name for the given property Name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
propName(str)
|
the name of the property |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
if property name is not known |
Returns:
| Type | Description |
|---|---|
(str, str, str)
|
column,propType,varName tupel |
Source code in ez_wikidata/wbquery.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
getValuesClause(values, propVarname='short_name', propType='text', lang=None, ignoreEmpty=True, wbPrefix='http://www.wikidata.org/entity/')
create a SPARQL Values clause
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values(list)
|
the list of values to create values for |
required | |
propVarname(str)
|
the property variable name to assign the values for |
required | |
propType
|
str
|
|
'text'
|
lang
|
str
|
language of labels to query |
None
|
ignoreEmpty(bool)
|
ignore empty values if True |
required | |
wbPrefix(str)
|
a wikibase/wikidata prefix to be removed for items values |
required |
Returns: str: the SPARQL values clause
Source code in ez_wikidata/wbquery.py
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
get_item_mapping()
Get the mapping that describes the wikidata entity item
Source code in ez_wikidata/wbquery.py
50 51 52 53 54 | |
get_property_mappings()
Get the property mappings as PropertyMapping list
Returns:
| Type | Description |
|---|---|
List[PropertyMapping]
|
List[PropertyMapping]: list of PropertyMappings |
Source code in ez_wikidata/wbquery.py
40 41 42 43 44 45 46 47 48 | |
inFilter(values, propName='short_name', lang='en')
create a SPARQL IN filter clause
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values(list)
|
the list of values to filter for |
required | |
propName(str)
|
the property name to filter with |
required | |
lang(str)
|
the language to apply |
required |
Source code in ez_wikidata/wbquery.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
ofEntityMap(entity, entityMap)
classmethod
create a WikibaseQuery for the given entity and entityMap
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity(str)
|
the entity name |
required | |
entityMap(dict)
|
the entity property descriptions |
required |
Returns: WikibaseQuery
Source code in ez_wikidata/wbquery.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
ofMapRows(entityMapRows, debug=False)
classmethod
create a dict of wikibaseQueries from the given entityMap list of dicts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entityMapRows(list)
|
a list of dict with row descriptions |
required | |
debug(bool)
|
if True switch on debugging |
required |
Source code in ez_wikidata/wbquery.py
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 | |
wdproperty
Created on 2024-03-02
@author: wf
PropertyMapping
Represents a single column Wikidata property mapping.
Attributes:
| Name | Type | Description |
|---|---|---|
column |
Optional[str]
|
The column name in the data source; if None, the value is directly used. |
propertyName |
str
|
The human-readable name of the property. |
propertyId |
str
|
The Wikidata property ID (e.g., "P31"). |
propertyType |
str
|
The type of the property as a string; converted to an enum in post-init. |
qualifierOf |
Optional[str]
|
Specifies if the property is a qualifier of another property. |
valueLookupType |
Optional[Any]
|
The type (instance of/P31) of the property value for lookup if the value is not already a QID. |
value |
Optional[Any]
|
The default value to set for the property. |
varname |
Optional[str]
|
An optional variable name for internal use. |
property_type_enum |
WdDatatype
|
The enum representation of the property type, initialized based on propertyType. |
The post_init method ensures the propertyType is correctly interpreted and stored as both a string and an enum.
Source code in ez_wikidata/wdproperty.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
__post_init__()
Convert propertyType from string to WdDatatype enum if necessary
Source code in ez_wikidata/wdproperty.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
from_record(wpm, record)
classmethod
initialize PropertyMapping from the given record Args: wpm(WikidataPropertyManager): to be used for type lookup record(Dict): property mapping information
Returns:
| Type | Description |
|---|---|
PropertyMapping
|
PropertyMapping |
Source code in ez_wikidata/wdproperty.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
getDefaultItemPropertyMapping()
classmethod
get the defaultItemPropertyMapping
Source code in ez_wikidata/wdproperty.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
get_item_mapping(property_mappings)
classmethod
get the property mapping that is used for the default "item" primary key if no property is defined use the default "item" mapping
Source code in ez_wikidata/wdproperty.py
647 648 649 650 651 652 653 654 655 656 657 658 659 | |
get_legacy_mapping()
classmethod
Returns the Mapping from old prop map keys to the new once
Source code in ez_wikidata/wdproperty.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
get_qualifier_lookup(properties)
classmethod
Get a lookup for a property and all its qualifier
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
properties
|
List[PropertyMapping]
|
property mappings to generate the lookup from |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, List[PropertyMapping]]
|
dict as property qualifier lookup |
Source code in ez_wikidata/wdproperty.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
is_item_itself()
Check if the property_type is an item
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the property mapping links to the existing item |
Source code in ez_wikidata/wdproperty.py
611 612 613 614 615 616 617 618 619 | |
is_qualifier()
Returns true if the property mapping describes a qualifier
Source code in ez_wikidata/wdproperty.py
588 589 590 591 592 593 | |
to_record()
convert property mapping to its dict representation
Source code in ez_wikidata/wdproperty.py
578 579 580 581 582 583 584 585 586 | |
PropertyMappings
A collection of Wikidata property mappings, with metadata.
Source code in ez_wikidata/wdproperty.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
of_name(name)
classmethod
load the bundled PropertyMappings resource of the given name (e.g. "scholar" -> resources/scholar_props.yaml), mirroring the existing sb_props.yaml convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name(str)
|
the use-case name (resource is |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PropertyMappings |
PropertyMappings
|
the loaded mapping set |
Source code in ez_wikidata/wdproperty.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
Variable
Variable e.g. name handling
Source code in ez_wikidata/wdproperty.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
validVarName(varStr)
classmethod
convert the given potential variable name string to a valid variable name
see https://stackoverflow.com/a/3305731/1497139
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
varStr(str)
|
the string to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
a valid variable name |
Source code in ez_wikidata/wdproperty.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
WdDatatype
Bases: Enum
Supported Wikidata datatypes, sorted by frequency and including special cases.
Source code in ez_wikidata/wdproperty.py
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 63 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
from_wb_type_name(wb_type_name)
classmethod
convert a wikibase type name to a WdDatatype
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wb_type_name(str)
|
the string name of the wikibase type (with or without wikibase ontology prefix) |
required |
Source code in ez_wikidata/wdproperty.py
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 | |
get_by_wikibase(property_type)
classmethod
Get WdDatatype by the corresponding wikibase datatype Args: property_type: wikibase name of the type
Returns:
| Type | Description |
|---|---|
Union[WdDatatype, None]
|
WdDatatype |
Source code in ez_wikidata/wdproperty.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
WikidataProperty
Represents a Wikidata Property.
Source code in ez_wikidata/wdproperty.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 | |
__post_init__()
creates and modify calculated fields
Source code in ez_wikidata/wdproperty.py
169 170 171 172 173 174 175 176 177 178 179 180 181 | |
getPredicate()
get me as a Predicate
Source code in ez_wikidata/wdproperty.py
183 184 185 186 187 188 189 | |
WikidataPropertyManager
handle Wikidata Properties
Source code in ez_wikidata/wdproperty.py
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 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 298 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 368 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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
__init__(endpoint_url='https://qlever.dev/api/wikidata', langs=['en', 'zh', 'hi', 'de', 'fr', 'ar', 'es', 'bn', 'ru'], with_load=True, profile=True, debug=False)
initialize the lookups
Source code in ez_wikidata/wdproperty.py
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_instance(endpoint_url='https://qlever.dev/api/wikidata')
classmethod
initialize the wikidata property manager
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint_url(str)
|
the SPARQL endpoint to query if there is no cache available |
required | |
lang(str)
|
the languages to query propery labels and descriptions for |
required |
Source code in ez_wikidata/wdproperty.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
get_mappings_for_records(prop_mapping_records)
convert given list of property mapping records to list of PropertyMappings Args: prop_mapping_records: records to convert
Returns:
| Type | Description |
|---|---|
List[PropertyMapping]
|
property mappings |
Source code in ez_wikidata/wdproperty.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
get_properties_by_ids(ids, lang='en')
Get properties by their IDs for a specific language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
List[str]
|
List of property IDs to search for. |
required |
lang(str)
|
the language |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Optional[WikidataProperty]]
|
A dictionary of {property ID: WikidataProperty or None} for found and not found properties. |
Source code in ez_wikidata/wdproperty.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
get_properties_by_labels(labels, lang='en')
Get properties by their labels for a specific language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
List[str]
|
List of property labels to search for. |
required |
lang
|
str
|
the language to match with |
'en'
|
Returns: A dictionary of {label: WikidataProperty} for found properties.
Source code in ez_wikidata/wdproperty.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
get_property_by_id(property_id)
lookup a WikidataProperty for the given property_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_id(str)
|
a property ID e.g. "P6375" |
required |
Source code in ez_wikidata/wdproperty.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
get_query_for_langs(langs=None)
Get the SPARQL query for the given list of langs.
Source code in ez_wikidata/wdproperty.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
init_props()
initialize my property structures
Source code in ez_wikidata/wdproperty.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
load()
load the properties
Source code in ez_wikidata/wdproperty.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
load_from_sparql()
get my list of dicts from sparql
Source code in ez_wikidata/wdproperty.py
230 231 232 233 234 235 236 237 238 239 | |
load_from_sql()
load from SQL
Source code in ez_wikidata/wdproperty.py
262 263 264 265 266 267 268 269 270 271 | |
prepare_store()
prepare storing by adding id and pid and avoiding duplicates
Source code in ez_wikidata/wdproperty.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
store()
store my list of dicts
Source code in ez_wikidata/wdproperty.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
with_user_agent(sparql)
set the Wikimedia-policy User-Agent on the given SPARQL accessor
Source code in ez_wikidata/wdproperty.py
31 32 33 34 | |
wdsearch
Created on 2022-07-24
@author: wf
WikidataSearch
Bases: object
Wikidata Search API wrapper
Interactive (per-keyclick) search: it must fail fast and is deliberately NOT rate limited - throttling/blocking belongs on the batch SPARQL path, not on search-as-you-type.
Source code in ez_wikidata/wdsearch.py
17 18 19 20 21 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 63 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 101 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 | |
__init__(language='en', timeout=2.0)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language(str)
|
the language to use e.g. en/fr |
required | |
timeout(float)
|
maximum time to wait for result - kept short so interactive search fails fast rather than blocking the UI |
required |
Source code in ez_wikidata/wdsearch.py
26 27 28 29 30 31 32 33 34 35 36 37 | |
getProperties()
get the Wikidata Properties
Source code in ez_wikidata/wdsearch.py
130 131 132 133 134 135 136 137 138 | |
get_user_agent()
classmethod
Construct a Wikimedia-policy-compliant User-Agent string identifying this project with a contact URL. see https://meta.wikimedia.org/wiki/User-Agent_policy
Source code in ez_wikidata/wdsearch.py
39 40 41 42 43 44 45 46 47 | |
make_wikidata_request(apisearch)
Make a fail-fast HTTP request to the Wikidata API with a policy User-Agent
Source code in ez_wikidata/wdsearch.py
84 85 86 87 88 89 90 | |
search(searchFor, limit=9)
Search for Wikidata entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
searchFor(str)
|
the string to search for |
required | |
limit(int)
|
the maximum amount of results to search for |
required |
Returns:
| Type | Description |
|---|---|
List[dict]
|
List[dict]: list of search result dictionaries, or error pseudo-result on failure |
Source code in ez_wikidata/wdsearch.py
92 93 94 95 96 97 98 99 100 101 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 | |
searchOptions(searchFor, limit=9)
Search and return a list of qid, itemLabel, description tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
searchFor
|
str
|
the string to search for. |
required |
limit
|
int
|
the maximum amount of results to return. |
9
|
Returns:
| Type | Description |
|---|---|
List[Tuple[str, str, str]]
|
List[Tuple[str, str, str]]: |
List[Tuple[str, str, str]]
|
A list of tuples containing |
List[Tuple[str, str, str]]
|
qid, itemLabel, and description. |
Source code in ez_wikidata/wdsearch.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
wikidata
Created on 2022-04-18
@author: wf
UrlReference
Bases: Reference
Reference consisting of reference URL (P854) retrieved (P813)
Source code in ez_wikidata/wikidata.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 | |
__init__(url, date=None)
constructor Args: url: reference URL date: retrieved at
Source code in ez_wikidata/wikidata.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 | |
Wikidata
wikidata access
see http://learningwikibase.com/data-import/
Source code in ez_wikidata/wikidata.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 227 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 298 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 368 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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
query_sparql
property
lazily created rate-limited SPARQL accessor for read queries against the configured endpoint (avoids HTTP 429/403 from Wikidata)
wbi
property
writable
WikibaseIntegrator
__init__(baseurl=None, wpm=None, debug=False, endpointConf=None)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseurl(str)
|
the baseurl of the wikibase to use |
required | |
debug(bool)
|
if True output debug information |
required | |
wpm(WikidataPropertymanager)
|
|
required | |
endpointConf(Endpoint)
|
the SPARQL endpoint to use for read queries (defaults to the Wikidata Query Service) |
required |
Source code in ez_wikidata/wikidata.py
93 94 95 96 97 98 99 100 101 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 | |
addDict(row, mapDict, itemId=None, lang='en', write=False, ignoreErrors=False)
add the given row mapping with the given map Dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row(dict)
|
the data row to add |
required | |
mapDict(dict)
|
the mapping dictionary to use |
required | |
itemId
|
Union[str, None]
|
wikidata id of the item the data should be added to. If None a new item is created unless item id is provided in the record |
None
|
lang(str)
|
the language for lookups |
required | |
write(bool)
|
if True do actually write |
required | |
ignoreErrors(bool)
|
if True ignore errors |
required |
Returns:
| Name | Type | Description |
|---|---|---|
WikiDataResult |
WikidataResult
|
the result of the operation |
Source code in ez_wikidata/wikidata.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
add_record(record, property_mappings, item_id=None, lang='en', write=False, ignore_errors=False, summary=None, reference=None)
add the given row mapping with the given map Dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record(dict)
|
the data row to add |
required | |
property_mappings(list)
|
the mapping dictionary to use |
required | |
item_id
|
Union[str, None]
|
wikidata id of the item the data should be added to. If None a new item is created unless item id is provided in the record |
None
|
lang(str)
|
the language for lookups |
required | |
write(bool)
|
if True do actually write |
required | |
ignore_errors(bool)
|
if True ignore errors |
required | |
summary
|
str
|
summary of the item edits |
None
|
reference
|
Reference
|
reference to add to all claims |
None
|
Returns:
| Type | Description |
|---|---|
(qId, errors)
|
the wikidata item create (if any) and a dict of errors |
Source code in ez_wikidata/wikidata.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
check_result(result, property_mappings, record)
check the given result against the record and the mappings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result(WikidataResult)
|
the result to check |
required | |
property_mappings(list)
|
the mappings that were applied |
required | |
record(dict)
|
the record that was mapped |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List[str]
|
one problem message per mapped record value without a claim |
List[str]
|
and per error of the result |
Source code in ez_wikidata/wikidata.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
convert_to_claim(value, pm)
Convert the given value to a corresponding wikidata statement Args: value: value of the statement pm: information about the property statement ot generate
Raises:
| Type | Description |
|---|---|
Exception
|
if property datatype is unknown or not supported |
Returns:
| Type | Description |
|---|---|
Union[BaseDataType, None]
|
BaseDataType |
Source code in ez_wikidata/wikidata.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
explain_result(result, lang='en')
explain the given result in human readable form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result(WikidataResult)
|
the result to explain |
required | |
lang(str)
|
the language to use for label and description |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
one line for the label, the description and each claim |
Source code in ez_wikidata/wikidata.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
getCredentials()
get my credentials https://test.wikidata.org/wiki/Property:P370
from the wd npm command line tool
Throws
Exception: if no credentials are available for the baseurl
Returns:
| Type | Description |
|---|---|
(str, str)
|
(username, password) of the account assigned to the baseurl |
Source code in ez_wikidata/wikidata.py
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 | |
getItemByName(itemName, itemType, lang='en')
get an item by Name ToDo: Needs to be reworked as always WDQS is used as endpoint even if a different one is defined Args: itemName(str): the item to look for itemType(str): the type of the item lang(str): the language of the itemName
Source code in ez_wikidata/wikidata.py
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 | |
get_datatype_of_property(property_id)
Get the datatype of the given property Args: property_id: id of the property e.g. P31 or 31
Returns:
| Type | Description |
|---|---|
Union[str, None]
|
datatype of the property of None if no datatype is defined |
Source code in ez_wikidata/wikidata.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
get_date_claim(date, prop_nr)
staticmethod
Get the data statement for the given date and property id Args: date: date value prop_nr: id of the property
Returns:
| Type | Description |
|---|---|
Claim
|
statement of the given property number with the given value |
Source code in ez_wikidata/wikidata.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
get_item_label(item_id, lang=None)
Get the label for the given item id Args: item_id: id of the item lang: label language to return. Default is "en"
Returns:
| Name | Type | Description |
|---|---|---|
str |
Union[str, None]
|
label of the item |
None |
Union[str, None]
|
If the label can not be determined or the item_id is None or can not be found |
Source code in ez_wikidata/wikidata.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
get_or_create_item(item_id)
Get or create the requested wikidata item Args: item_id: item to retrieve if None create a new item
Source code in ez_wikidata/wikidata.py
711 712 713 714 715 716 717 718 719 720 721 | |
get_prop_value(record, pm, lang)
Retrieve the property value from the record and prepare the value if necessary Args: record: record containing the property data pm: property mapping lang: language to use
Returns:
| Type | Description |
|---|---|
Any
|
value of the property from the record |
Source code in ez_wikidata/wikidata.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
get_record(item_id, property_mappings, include_label=True, include_description=True, label_for_qids=False)
Get the properties form the given item Args: item_id: id of the item to get the data from property_mappings: list of property values to extract include_label: include_description: label_for_qids: If True fetch the label for a linked Qid Returns: dict with the property values
Source code in ez_wikidata/wikidata.py
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 368 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 | |
get_wddatatype_of_property(property_id)
Get the datatype of the given property Args: property_id: id of the property e.g. P31 or 31
Returns:
| Type | Description |
|---|---|
WdDatatype
|
WdDatatype of the property of None if no datatype is defined |
Source code in ez_wikidata/wikidata.py
890 891 892 893 894 895 896 897 898 899 900 | |
get_wikidata_item(qid_or_label, item_type_qid=None)
Get WikidataItem for given label or Qid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qid_or_label
|
str
|
label or Qid of a item |
required |
Returns:
| Type | Description |
|---|---|
Optional[WikidataItem]
|
WikidataItem |
Source code in ez_wikidata/wikidata.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
is_wikidata_item_id(value)
staticmethod
Returns true if the given value is a wikidata item id
Source code in ez_wikidata/wikidata.py
819 820 821 822 823 824 | |
is_wikidata_property_id(value)
staticmethod
Returns true if the given value is a wikidata property id
Source code in ez_wikidata/wikidata.py
826 827 828 829 830 831 | |
loginWithCredentials(user=None, pwd=None)
login using the given credentials or credentials retrieved via self.getCredentials
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user(str)
|
the username |
required | |
pwd(str)
|
the password |
required |
Source code in ez_wikidata/wikidata.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
logout()
log the user out again
Source code in ez_wikidata/wikidata.py
239 240 241 242 243 244 245 | |
mount_retry(session)
staticmethod
mount an urllib3 Retry on the given session honouring Retry-After on 429 / 5xx responses - WikibaseIntegrator reads via POST
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
the requests session to configure |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Session |
Session
|
the configured session |
Source code in ez_wikidata/wikidata.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
normalize_records(record, prop_map)
Normalize given record by converting Qids to WikidataItem objects (lookup label) and find out Qid if label given based on the given prop_map
Source code in ez_wikidata/wikidata.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | |
sanitize_label(label, limit=None, postfix=None)
staticmethod
sanitize given label by ensuring it is not too long Args: label: label to sanitize limit: max length of the label
Returns:
| Type | Description |
|---|---|
str
|
sanitized label |
Source code in ez_wikidata/wikidata.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
WikidataItem
dataclass
Source code in ez_wikidata/wikidata.py
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | |
__eq__(other)
WikidataItems are equal if the qid is equal
Source code in ez_wikidata/wikidata.py
961 962 963 964 965 966 967 968 | |
__post_init__()
handle the construction
Source code in ez_wikidata/wikidata.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
asText(long=True, wrapAt=0)
returns my content as a text representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
long(bool)
|
True if a long format including url is wished |
required | |
wrapAt(int)
|
wrap long lines at the given width (if >0) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
a text representation of my content |
Source code in ez_wikidata/wikidata.py
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
getItemsByLabel(sparql, itemLabel, lang='en', debug=False)
classmethod
get a Wikidata items by the given label
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql(SPARQL)
|
the SPARQL endpoint to use |
required | |
itemLabel(str)
|
the label of the items |
required | |
lang(str)
|
the language of the label |
required | |
debug(bool)
|
if True show debugging information |
required |
Returns:
| Type | Description |
|---|---|
list
|
a list of potential items |
Source code in ez_wikidata/wikidata.py
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | |
getLabelAndDescription(sparql, itemId, lang='en', debug=False)
classmethod
get the label for the given item and language
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itemId(str)
|
the wikidata Q/P id |
required | |
lang(str)
|
the language of the label |
required | |
debug(bool)
|
if True output debug information |
required |
Returns:
| Type | Description |
|---|---|
(str, str)
|
the label and description as a tuple |
Source code in ez_wikidata/wikidata.py
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
WikidataResult
dataclass
a class for handling a wikidata result
Source code in ez_wikidata/wikidata.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
pretty_item_json
property
Returns a pretty-printed JSON string of the item.