-
Notifications
You must be signed in to change notification settings - Fork 0
Hotfix/skip details #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6330388
5bae64a
ab3d6ed
247b462
ab9fc5d
ac38492
4c93c47
7d61fbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,10 @@ | |
| os.getenv("READ_CTFG_FROM_CACHE", "False").upper() | ||
| ) | ||
|
|
||
| POST_DETAILS_TO_CTFG: bool = "TRUE".startswith( | ||
| os.getenv("POST_DETAILS_TO_CTFG", "False").upper() | ||
|
Comment on lines
+16
to
+17
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main change: this cuts down on unnecessary records |
||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class airtable: | ||
|
|
@@ -33,9 +37,12 @@ class airtable: | |
|
|
||
| wbi = WikibaseIntegrator() | ||
|
|
||
| WIKIDATA_MAX_RESULTS_PER_SEARCH: int = int( | ||
| os.getenv("WIKIDATA_MAX_RESULTS_PER_SEARCH", 50) | ||
| ) | ||
| def getEnvInt(name: str, default: int) -> int: | ||
| raw = os.getenv("WIKIDATA_MAX_RESULTS_PER_SEARCH") | ||
| return int(raw) if raw else default | ||
|
Comment on lines
+40
to
+42
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. safer int retrieval |
||
|
|
||
| WIKIDATA_MAX_LISTINGS_TO_SEARCH: int = getEnvInt("WIKIDATA_MAX_LISTINGS_TO_SEARCH", 5) | ||
|
|
||
| WIKIDATA_MAX_RESULTS_PER_SEARCH: int = getEnvInt("WIKIDATA_MAX_RESULTS_PER_SEARCH", 5) | ||
|
|
||
| LANGUAGE_CODE = "en" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,10 @@ def from_wiki_match(m: dict, keep_unknowns: bool = False): | |
| # pprint(claims) | ||
|
|
||
| statements = [ | ||
| WikidataStatement.from_wiki_statement(s) for p in claims.values() for s in p | ||
| WikidataStatement.from_wiki_statement(s) | ||
| for p in claims.values() | ||
| for s in p | ||
| if config.POST_DETAILS_TO_CTFG | ||
| ] | ||
| result = WikidataItem(**mappable, statements=statements) | ||
| result.save() | ||
|
|
@@ -271,17 +274,17 @@ def partition_matched(items: list[Listing]) -> tuple[list[Listing], list[Listing | |
|
|
||
|
|
||
| def upsert_matches(wiki_matches: dict[Listing, list[dict[str, Any]]]): | ||
| log("Updating CTFG with matching wikibase IDs...") | ||
| with_wiki_items = { | ||
| x: [WikidataItem.from_wiki_match(m) for m in matches] | ||
| for x, matches in wiki_matches.items() | ||
| if matches | ||
| } | ||
| wiki_items = list(set([x for y in with_wiki_items.values() for x in y])) | ||
| log(f"Updating CTFG with {len(wiki_items)} matching wikibase IDs...") | ||
|
|
||
| log("Example item") | ||
| # pprint(wiki_items[0].to_record()) | ||
| # WikidataItem.recursive_save(wiki_items) | ||
| if wiki_items: | ||
| log("Example item") | ||
| pprint(wiki_items[0].to_record()) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better logging (know how many before start and only show example if available) |
||
|
|
||
| for x, matches in with_wiki_items.items(): | ||
| x.wikidata_suggestions = matches | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,9 @@ def get_matches( | |
| ) -> dict[ctfg.Listing, list[dict[str, Any]]]: | ||
| matchable_items = [x for x in items if x.name] | ||
| attempting_items = ( | ||
| sample(matchable_items, max_attempts) if max_attempts else matchable_items | ||
| sample(matchable_items, max_attempts) | ||
| if max_attempts and max_attempts < len(matchable_items) | ||
| else matchable_items | ||
|
Comment on lines
+21
to
+23
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. safer sampling |
||
| ) | ||
| log( | ||
| f"Searching for wikibase matches for {len(attempting_items)} {'random' if max_attempts else 'matchable'} items..." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.