customer_database_search
A simple CUI application to visualize and query a customer database using the textual
package.
Customer
dataclass
¶
Source code in examples/customer_database_search.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
age: int
property
¶
Return the current age of the customer.
This is a computed property based on birthdate
and the current year (2022).
CustomerDatabase
dataclass
¶
Source code in examples/customer_database_search.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
find_customer_key(query)
¶
Find the keys of the customers that match a natural language query best (sorted by closeness to the match).
We support semantic queries instead of SQL, so we can search for things like "the customer that was born in 1990".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
Natural language query |
required |
Returns:
Type | Description |
---|---|
list[str]
|
The index of the best matching customer in the database. |
Source code in examples/customer_database_search.py
42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
load()
¶
Load the customer database from a file.
Source code in examples/customer_database_search.py
56 57 58 |
|
store()
¶
Store the customer database to a file.
Source code in examples/customer_database_search.py
60 61 62 |
|
CustomerDatabaseApp
¶
Bases: App
A simple textual application to visualize and query a customer database.
We show all the customers in a table and allow the user to query the database using natural language in a search box at the bottom of the screen.
Source code in examples/customer_database_search.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
search(query)
¶
Search the customer database using a natural language query.
Source code in examples/customer_database_search.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
MockCustomerDatabase
dataclass
¶
Bases: CustomerDatabase
Source code in examples/customer_database_search.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
create_mock_customers(num_customers=1)
staticmethod
¶
Create mock customers with believable data (our customers are world citizens).
Source code in examples/customer_database_search.py
74 75 76 77 78 79 |
|