-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabylon_library_example.py
59 lines (49 loc) · 2.25 KB
/
babylon_library_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2025, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
# https://github.com/smartlegionlab/
# --------------------------------------------------------
from smart_babylon_library import timing_decorator, BabylonLibrary, BabylonLibraryIterator
@timing_decorator
def babylon_library_example():
library = BabylonLibrary()
print("=== Using BabylonLibrary ===")
# Example 1: Get text by address
address = "Room1:Wall1:Shelf1:Volume1:Book1:Page1"
text = library.get_text(address)
print(f"Text at address {address}:\n{text}\n")
# Example 2: Get text by address with coordinates
address_with_coords = "Room1:Wall1:Shelf1:Volume1:Book1:Page1:10:20"
partial_text = library.get_text(address_with_coords)
print(f"Text at address {address_with_coords}:\n{partial_text}\n")
# Example 3: Search for text
target_text = "ok"
found_address, found_coords = library.search_for_text_with_pattern(target_text, max_attempts=1000)
if found_address:
print(f"Text '{target_text}' found at address {found_address}:\n{library.get_text(found_address)}\n")
else:
print(f"Text '{target_text}' not found in 1000 attempts.\n")
# Example 4: Iterate using the iterator
print("=== Using BabylonLibraryIterator ===")
print("Iterating through the library:")
iterator = BabylonLibraryIterator(library)
for _ in range(5):
address, text = next(iterator)
print(f"Address: {address}\nText: {text[:50]}...\n")
# Example: Parallel search
target_text = "ok"
found_address, found_coords = library.search_for_text_with_pattern_parallel(target_text, max_attempts=1000,
num_threads=4)
if found_address:
print(f"Text '{target_text}' found at address {found_address}:\n{library.get_text(found_address)}\n")
else:
print(f"Text '{target_text}' not found in 1000 attempts.\n")
def main():
print("*** Start ***")
babylon_library_example()
print("*** End ***")
if __name__ == "__main__":
main()