-
-
Notifications
You must be signed in to change notification settings - Fork 3
Emit CID aliases from parser #50
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 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -405,6 +405,7 @@ def _extract_places(node: JSONValue) -> list[Place]: | |
| metadata_node = _find_place_metadata(ancestors) | ||
| address = _extract_address(metadata_node) | ||
| cid = _find_cid(metadata_node) | ||
| cid_aliases = _find_cid_aliases(metadata_node) | ||
| google_id = _find_google_id(metadata_node) | ||
| name = _find_place_name(ancestors, address=address, place_record=place_record) | ||
| note = _find_place_note(place_record, name=name, address=address) | ||
|
|
@@ -422,18 +423,24 @@ def _extract_places(node: JSONValue) -> list[Place]: | |
| lng=lng, | ||
| ), | ||
| cid=cid, | ||
| cid_aliases=cid_aliases, | ||
| google_id=google_id, | ||
| is_favorite=is_favorite, | ||
| added_by=_find_place_added_by(place_record), | ||
| ) | ||
| dedupe_key = ( | ||
| google_id | ||
| or (f"{cid}:{lat:.6f}:{lng:.6f}" if cid is not None else None) | ||
| or f"{place.name}:{lat:.6f}:{lng:.6f}" | ||
| ) | ||
| if dedupe_key in seen: | ||
| dedupe_keys: set[str] = set() | ||
| if google_id: | ||
| dedupe_keys.add(f"gid:{google_id}") | ||
| if cid is not None: | ||
| dedupe_keys.update({ | ||
| f"cid:{cid_value}:{lat:.6f}:{lng:.6f}" | ||
| for cid_value in [cid, *cid_aliases] | ||
| }) | ||
| if not dedupe_keys: | ||
| dedupe_keys = {f"name:{place.name}:{lat:.6f}:{lng:.6f}"} | ||
| if seen.intersection(dedupe_keys): | ||
| continue | ||
|
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.
When an alias-only duplicate appears before the full place row, this intersection check skips the later canonical row instead of replacing/merging it, so the output keeps the S2-cell alias as Useful? React with 👍 / 👎. |
||
| seen.add(dedupe_key) | ||
| seen.update(dedupe_keys) | ||
| places.append(place) | ||
|
|
||
| return places | ||
|
|
@@ -597,6 +604,19 @@ def _find_cid(node: list[JSONValue] | None) -> str | None: | |
| return None | ||
|
|
||
|
|
||
| def _find_cid_aliases(node: list[JSONValue] | None) -> list[str]: | ||
| if node is None: | ||
| return [] | ||
| structured_value = _safe_index(node, 6) | ||
| structured_cid = _find_cid_in_structured_slot(structured_value) | ||
| if structured_cid is None: | ||
| return [] | ||
| return _find_cid_aliases_in_structured_slot( | ||
| structured_value, | ||
| selected_cid=structured_cid, | ||
| ) | ||
|
|
||
|
|
||
| def _find_google_id(node: list[JSONValue] | None) -> str | None: | ||
| if node is None: | ||
| return None | ||
|
|
@@ -660,6 +680,27 @@ def _find_cid_in_structured_slot(value: JSONValue | None) -> str | None: | |
| return _normalize_cid_token(numeric_texts[0]) | ||
|
|
||
|
|
||
| def _find_cid_aliases_in_structured_slot( | ||
| value: JSONValue | None, | ||
| *, | ||
| selected_cid: str, | ||
| ) -> list[str]: | ||
| if not isinstance(value, list): | ||
| return [] | ||
| owner = _parse_list_owner(value) | ||
| if owner is not None and (owner.photo_url is not None or owner.profile_id is not None): | ||
| return [] | ||
| aliases: list[str] = [] | ||
| for item in value: | ||
| text = _clean_text(item) | ||
| if text is None or _LONG_INTEGER_PATTERN.fullmatch(text) is None: | ||
| continue | ||
| alias = _normalize_cid_token(text) | ||
| if alias is not None and alias != selected_cid and alias not in aliases: | ||
| aliases.append(alias) | ||
| return aliases | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _find_cid_in_fallback_value(value: JSONValue | None) -> str | None: | ||
| if isinstance(value, int | str): | ||
| return _normalize_fallback_cid_token(value) | ||
|
|
||
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.
When two different saved places share the same exact coordinates/S2 cell, such as two venues in one building, adding every
cid_aliasesvalue to the dedupe key makes the later place collide on the shared positive S2-cell alias and be skipped even when its true CID differs. Because the alias can be the positive S2-cell token rather than a unique place CID, this regresses the previouscid+lat/lngbehavior that preserved distinct CIDs at the same location.Useful? React with 👍 / 👎.