MCPcopy
hub / github.com/fluentpython/example-code-2e / InvertedIndex

Class InvertedIndex

21-async/mojifinder/charindex.py:49–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48
49class InvertedIndex:
50 entries: Index
51
52 def __init__(self, start: int = 32, stop: int = STOP_CODE):
53 entries: Index = defaultdict(set)
54 for char in (chr(i) for i in range(start, stop)):
55 name = unicodedata.name(char, '')
56 if name:
57 for word in tokenize(name):
58 entries[word].add(char)
59 self.entries = entries
60
61 def search(self, query: str) -> set[Char]:
62 if words := list(tokenize(query)):
63 found = self.entries[words[0]]
64 return found.intersection(*(self.entries[w] for w in words[1:]))
65 else:
66 return set()
67
68
69def format_results(chars: set[Char]) -> Iterator[str]:

Callers 4

mainFunction · 0.90
mainFunction · 0.90
initFunction · 0.90
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected