validate_hierarchy#
- scikitplot.corpus.validate_hierarchy(documents, *, max_depth=64, require_parent_present=True)[source]#
Check referential integrity, cycles and depth of the hierarchy.
- Parameters:
- documentsiterable of CorpusDocument
The collection to validate. Treated as a closed world: a
parent_doc_idnaming a document outside this collection counts as dangling unlessrequire_parent_presentisFalse.- max_depthint, optional
Maximum permitted ancestor chain length.
- require_parent_presentbool, optional
When
False, aparent_doc_idabsent fromdocumentsis tolerated. Use for validating a partial page of a larger corpus, where the parent legitimately lives elsewhere.
- Returns:
- HierarchyReport
Violations found, as structured records rather than exceptions, so a caller can report all of them rather than only the first.
- Parameters:
- Return type:
Notes
Three violation classes are detected, each with its own code:
HIERARCHY_DANGLING_PARENTparent_doc_idnames a document not present.HIERARCHY_CYCLEFollowing parents revisits a document.
HIERARCHY_TOO_DEEPThe ancestor chain exceeds
max_depth.HIERARCHY_SELF_PARENTA document is its own parent – reported distinctly from a general cycle because it is almost always a copy-paste error rather than a structural one.
Examples
>>> from scikitplot.corpus import CorpusDocument >>> a = CorpusDocument.create(input_path="f.txt", chunk_index=0, text="a") >>> validate_hierarchy([a]).ok True