Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
AIRTABLE_BASE_ID: ${{ vars.AIRTABLE_BASE_ID }}
WIKIDATA_BOT_PW: ${{ secrets.WIKIDATA_BOT_PW }}
WIKIDATA_BOT_USERNAME: ${{ secrets.WIKIDATA_BOT_USERNAME }}
WIKIDATA_MAX_LISTINGS_TO_SEARCH: ${{ vars.WIKIDATA_MAX_LISTINGS_TO_SEARCH }}
WIKIDATA_MAX_RESULTS_PER_SEARCH: ${{ vars.WIKIDATA_MAX_RESULTS_PER_SEARCH }}
1 change: 1 addition & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ jobs:
AIRTABLE_BASE_ID: ${{ vars.AIRTABLE_BASE_ID }}
WIKIDATA_BOT_PW: ${{ secrets.WIKIDATA_BOT_PW }}
WIKIDATA_BOT_USERNAME: ${{ secrets.WIKIDATA_BOT_USERNAME }}
WIKIDATA_MAX_LISTINGS_TO_SEARCH: ${{ vars.WIKIDATA_MAX_LISTINGS_TO_SEARCH }}
WIKIDATA_MAX_RESULTS_PER_SEARCH: ${{ vars.WIKIDATA_MAX_RESULTS_PER_SEARCH }}
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
readme = "README.md"
requires-python = "<4.0,>=3.13"
dependencies = [
"wikibaseintegrator @ git+https://github.com/LeMyst/WikibaseIntegrator.git@301067883ddce0bca31fdd54973c3d6c8cbbcb7d",
"wikibaseintegrator @ git+https://github.com/combinatorist/WikibaseIntegrator.git@feature/search_entities-exact-max_results",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Using a fork!

"pyairtable (>=3.1.1,<4.0.0)",
"more_itertools"
]
Expand Down
13 changes: 10 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change: this cuts down on unnecessary records

)


@dataclass
class airtable:
Expand All @@ -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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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"
13 changes: 8 additions & 5 deletions src/ctfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand Down
4 changes: 3 additions & 1 deletion src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
(unmatched_items, matched_items) = ctfg.partition_matched(items)

wiki_matches = wiki.get_matches(
unmatched_items, max_attempts=5, max_results=config.WIKIDATA_MAX_RESULTS_PER_SEARCH
unmatched_items,
max_attempts=config.WIKIDATA_MAX_LISTINGS_TO_SEARCH,
max_results=config.WIKIDATA_MAX_RESULTS_PER_SEARCH,
)
# wiki_match_histogram = wiki.summarize_matches(wiki_matches)

Expand Down
4 changes: 3 additions & 1 deletion src/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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..."
Expand Down