MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / resolve_doc_name_from_key

Function resolve_doc_name_from_key

openkb/converter.py:113–133  ·  view source on GitHub ↗

Collision-resistant wiki name for a synthetic identity ``path_key``. Same rules as :func:`resolve_doc_name` minus the legacy-by-stem backfill (a filesystem-migration concern that must not fire for sources with no real path, e.g. cloud imports). A source already registered under ``pa

(stem: str, path_key: str, registry: HashRegistry)

Source from the content-addressed store, hash-verified

111
112
113def resolve_doc_name_from_key(stem: str, path_key: str, registry: HashRegistry) -> str:
114 """Collision-resistant wiki name for a synthetic identity ``path_key``.
115
116 Same rules as :func:`resolve_doc_name` minus the legacy-by-stem
117 backfill (a filesystem-migration concern that must not fire for sources
118 with no real path, e.g. cloud imports). A source already registered
119 under ``path_key`` keeps its stored ``doc_name``; otherwise the
120 sanitized ``stem`` is used, with a deterministic
121 ``-{sha256(path_key)[:8]}`` suffix when another document owns it.
122 """
123 known = registry.get_by_path(path_key)
124 if known is not None:
125 stored = known.get("doc_name") or Path(known.get("name", "")).stem
126 if stored:
127 return stored
128
129 candidate = _sanitize_stem(stem)
130 if _name_taken(candidate, registry):
131 digest = hashlib.sha256(path_key.encode("utf-8")).hexdigest()[:_SUFFIX_LEN]
132 return f"{candidate}-{digest}"
133 return candidate
134
135
136def get_pdf_page_count(path: Path) -> int:

Calls 4

_sanitize_stemFunction · 0.85
_name_takenFunction · 0.85
get_by_pathMethod · 0.80
getMethod · 0.45