def build_docs(): """ Builds up a complete chunk-match structure, with a depth of 2 in both directions recursively. """ max_granularity = 2 max_adjacency = 2 def iterate_build(document, current_granularity, current_adjacency): if current_granularity < max_granularity: for i in range(DOCUMENTS_PER_LEVEL): chunk = add_chunk(document) iterate_build(chunk, chunk.granularity, chunk.adjacency) if current_adjacency < max_adjacency: for i in range(DOCUMENTS_PER_LEVEL): match = add_match(document) iterate_build(match, match.granularity, match.adjacency) docs = [] for base_id in range(DOCUMENTS_PER_LEVEL): document = Document() document.granularity = 0 document.adjacency = 0 docs.append(document) iterate_build(document, 0, 0) return DocumentArray(docs)
def add_match(doc): match = Document() match.granularity = doc.granularity match.adjacency = doc.adjacency + 1 doc.matches.append(match) return match
def add_chunk(doc): chunk = Document() chunk.granularity = doc.granularity + 1 chunk.adjacency = doc.adjacency doc.chunks.append(chunk) return chunk