Kanzi 0.6.15: robust unification (DOI/ISBN + normalised hash)
- src/kindle_zotero_importer/zotero_index.py already has DOI/ISBN, now import_plan.py passes doi/isbn/issn/publication_title to final_plan - src/kindle_zotero_importer/final_plan.py: _normalise() + _hash_norm() (NFKC lower, de-hyphenate, strip punct, SHA256:16) and store doi/isbn/issn/publication_title/norm_hash per annotation for cross-library grouping - plugin/manager.html: anonData now sends doi/isbn/issn/publication_title/norm_hash alongside citation_key/hash/colour for private aggregation - vis ~/annotation/app.py: store new columns, migrate old DB, /common groups by COALESCE(doi,isbn,citation_key)+norm_hash, dashboard shows Recent with DOI/norm and Top + Common tables - Bump to 0.6.15
This commit is contained in:
parent
72ae2d1448
commit
d5f128e82e
6 changed files with 47 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ Import Kindle `My Clippings.txt` highlights into Zotero as native annotations, d
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.14`, or `0.6.13-beta` for preview).
|
1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.15`, or `0.6.14-beta` for preview).
|
||||||
2. In Zotero: `Tools` → `Plugins` → `gear` → `Install Plugin From File…` → pick the `.xpi` → restart Zotero.
|
2. In Zotero: `Tools` → `Plugins` → `gear` → `Install Plugin From File…` → pick the `.xpi` → restart Zotero.
|
||||||
3. `Tools` → `Kanzi…` to open the manager.
|
3. `Tools` → `Kanzi…` to open the manager.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,12 @@
|
||||||
}
|
}
|
||||||
const anonData = (data.finalPlan?.annotations || []).map(a => ({
|
const anonData = (data.finalPlan?.annotations || []).map(a => ({
|
||||||
citation_key: a.citation_key,
|
citation_key: a.citation_key,
|
||||||
|
doi: a.doi || null,
|
||||||
|
isbn: a.isbn || null,
|
||||||
|
issn: a.issn || null,
|
||||||
|
publication_title: a.publication_title || null,
|
||||||
clipping_id_hash: a.clipping_id ? a.clipping_id.slice(0,8) : null,
|
clipping_id_hash: a.clipping_id ? a.clipping_id.slice(0,8) : null,
|
||||||
|
norm_hash: a.norm_hash || null,
|
||||||
color: a.annotation?.color,
|
color: a.annotation?.color,
|
||||||
has_comment: !!(a.annotation?.comment),
|
has_comment: !!(a.annotation?.comment),
|
||||||
comment: a.annotation?.comment || "",
|
comment: a.annotation?.comment || "",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Kanzi",
|
"name": "Kanzi",
|
||||||
"version": "0.6.14",
|
"version": "0.6.15",
|
||||||
"description": "Kindle annotations to Zotero — My Clippings.txt → native annotations.",
|
"description": "Kindle annotations to Zotero — My Clippings.txt → native annotations.",
|
||||||
"homepage_url": "https://github.com/UtkuBilenDemir/kindle-zotero_importer",
|
"homepage_url": "https://github.com/UtkuBilenDemir/kindle-zotero_importer",
|
||||||
"author": "Utku Bilen Demir",
|
"author": "Utku Bilen Demir",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,28 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import hashlib
|
||||||
|
import re
|
||||||
|
import unicodedata
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def _normalise(text: str) -> str:
|
||||||
|
if not text:
|
||||||
|
return ""
|
||||||
|
# NFKC, lower, strip, de-hyphenate, collapse whitespace/punct
|
||||||
|
t = unicodedata.normalize("NFKC", text).lower()
|
||||||
|
t = re.sub(r"-\s*\n\s*", "", t) # de-hyphenate line breaks
|
||||||
|
t = re.sub(r"[\u2010-\u2015\u2018\u2019\u201c\u201d]", "'", t)
|
||||||
|
t = re.sub(r"[^a-z0-9]+", " ", t)
|
||||||
|
t = re.sub(r"\s+", " ", t).strip()
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
def _hash_norm(text: str) -> str:
|
||||||
|
return hashlib.sha256(_normalise(text).encode("utf-8")).hexdigest()[:16]
|
||||||
|
|
||||||
|
|
||||||
FINAL_FORMAT = "kindle-zotero-importer.zotero-writer-plan.v1"
|
FINAL_FORMAT = "kindle-zotero-importer.zotero-writer-plan.v1"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,6 +41,8 @@ def build_final_writer_plan(positioned_plan: dict[str, Any]) -> dict[str, Any]:
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
clipping = item["clipping"]
|
clipping = item["clipping"]
|
||||||
|
# robust identifiers for cross-library unification
|
||||||
|
norm_hash = _hash_norm(annotation.get("text") or clipping.get("text") or "")
|
||||||
annotations.append(
|
annotations.append(
|
||||||
{
|
{
|
||||||
"clipping_id": clipping["id"],
|
"clipping_id": clipping["id"],
|
||||||
|
|
@ -34,6 +55,11 @@ def build_final_writer_plan(positioned_plan: dict[str, Any]) -> dict[str, Any]:
|
||||||
"parent_item_id": item["zotero"]["parent_item_id"],
|
"parent_item_id": item["zotero"]["parent_item_id"],
|
||||||
"parent_key": item["zotero"]["parent_key"],
|
"parent_key": item["zotero"]["parent_key"],
|
||||||
"citation_key": item["zotero"].get("citation_key"),
|
"citation_key": item["zotero"].get("citation_key"),
|
||||||
|
"doi": item["zotero"].get("doi"),
|
||||||
|
"isbn": item["zotero"].get("isbn"),
|
||||||
|
"issn": item["zotero"].get("issn"),
|
||||||
|
"publication_title": item["zotero"].get("publication_title"),
|
||||||
|
"norm_hash": norm_hash,
|
||||||
"annotation": {
|
"annotation": {
|
||||||
"type": annotation["type"],
|
"type": annotation["type"],
|
||||||
"text": annotation.get("text") or "",
|
"text": annotation.get("text") or "",
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,11 @@ def _plan_clipping(
|
||||||
"parent_key": zotero_item["key"],
|
"parent_key": zotero_item["key"],
|
||||||
"parent_title": zotero_item.get("title"),
|
"parent_title": zotero_item.get("title"),
|
||||||
"citation_key": zotero_item["fields"].get("citationKey"),
|
"citation_key": zotero_item["fields"].get("citationKey"),
|
||||||
|
"doi": zotero_item["fields"].get("DOI"),
|
||||||
|
"isbn": zotero_item["fields"].get("ISBN"),
|
||||||
|
"issn": zotero_item["fields"].get("ISSN") if "ISSN" in zotero_item["fields"] else None,
|
||||||
|
"url": zotero_item["fields"].get("url"),
|
||||||
|
"publication_title": zotero_item["fields"].get("publicationTitle"),
|
||||||
"attachment": attachment,
|
"attachment": attachment,
|
||||||
"attachment_choices": zotero_item.get("attachments", []),
|
"attachment_choices": zotero_item.get("attachments", []),
|
||||||
"expected_attachment_type": _expected_attachment_type(
|
"expected_attachment_type": _expected_attachment_type(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,15 @@
|
||||||
"addons": {
|
"addons": {
|
||||||
"kindlezoteroimporter@utkubilen.de": {
|
"kindlezoteroimporter@utkubilen.de": {
|
||||||
"updates": [
|
"updates": [
|
||||||
|
{
|
||||||
|
"version": "0.6.15",
|
||||||
|
"update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.15/kindle-zotero-importer.xpi",
|
||||||
|
"applications": {
|
||||||
|
"zotero": {
|
||||||
|
"strict_min_version": "6.999"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "0.6.14",
|
"version": "0.6.14",
|
||||||
"update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.14/kindle-zotero-importer.xpi",
|
"update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.14/kindle-zotero-importer.xpi",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue