Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
calculator
project code.
Chilka is a corpus serving library with a basic sensible interface and a pluggable backend to accomodate different databases.
Chilka implements the following interface:
- `add()`: Add a file to the corpus.
- `remove()`: Remove a file from the corpus.
- `list()`: List files from the corpus.
- `readSents()`: Read sentences of a particular file based on conditions.
- `readBlob()`: Get entire file as a text blob.
The plugin implementation lets you implement and enforce your own schema.
The plugin_args
argument lets you pass custom arguments to your plugin.
CorpusClient
Bases: CorpusClientAPI
Concrete class implementing the corpus API.
Methods:
Name | Description |
---|---|
add |
Add a file to the corpus |
remove |
Remove a file from the corpus |
readSents |
Read a file stored in the corpus as sentences |
readBlob |
Read a file stored in the corpus as text blob |
list |
List the files in the corpus |
Source code in chilka.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
__init__(db_name, connection_string, db_plugin=None, plugin_args={})
Init method to accept database details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_name
|
str
|
The name of the database/corpus |
required |
connection_string
|
str
|
The address & port of the database server |
required |
db_plugin
|
str
|
The name of the database plugin |
None
|
Returns: A corpus client object
Source code in chilka.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
add(filepath, plugin_args={})
Adds a file to the file list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path of the file to add to the corpus |
required |
Returns: list: The list of IDs of objects added
Source code in chilka.py
165 166 167 168 169 170 171 172 173 174 175 176 |
|
list(plugin_args={})
List the files in the corpus
returns: list (str): A list containing filenames in the corpus
Source code in chilka.py
224 225 226 227 228 229 230 231 232 233 234 235 |
|
readBlob(filename, plugin_args={})
Reads a file as a text blob
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file to be read |
required |
returns: str: File content as a single string
Source code in chilka.py
212 213 214 215 216 217 218 219 220 221 |
|
readSents(filename, range_filter=None, kw_filter=None, plugin_args={})
Returns a file as an iterator of {n:<>,sent:<>} dictionaries
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file/collection to be read |
required |
range_filter
|
tuple
|
(optional)Range of lines to read |
None
|
kw_filter
|
str
|
(optional)Search term to return sentences containing it |
None
|
returns: iterator: An iterator of dictionaries containing sentences from the file with serial number starting from 1
Source code in chilka.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
remove(filename, plugin_args={})
Removes a file from the corpus
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file to be removed from the corpus |
required |
Returns: bool: True if the collection was removed successfully, false if it does not exist
Source code in chilka.py
180 181 182 183 184 185 186 187 188 189 190 191 |
|
CorpusClientAPI
Abstract base class defining the corpus API.
Methods:
Name | Description |
---|---|
add |
Add a file to the corpus |
remove |
Remove a file from the corpus |
readSents |
Read a file stored in the corpus as sentences |
readBlob |
Read a file stored in the corpus as text blob |
list |
List the files in the corpus |
Source code in chilka.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
|
__init__(db_name, connection_string, db_plugin=None, plugin_args={})
abstractmethod
Init method to accept database details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_name
|
str
|
The name of the database/corpus |
required |
connection_string
|
str
|
The address & port of the database server |
required |
db_plugin
|
str
|
The name of the database plugin |
None
|
Returns: A corpus client object
Source code in chilka.py
54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
add(filepath, plugin_args={})
abstractmethod
Adds a file to the file list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path of the file to add to the corpus |
required |
Returns: list: The list of IDs of objects added
Source code in chilka.py
68 69 70 71 72 73 74 75 76 77 78 79 |
|
list(plugin_args={})
abstractmethod
List the files in the corpus
returns: list (str): A list containing filenames in the corpus
Source code in chilka.py
121 122 123 124 125 126 127 128 129 130 131 |
|
readBlob(filename, plugin_args={})
abstractmethod
Reads a file as a text blob
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file to be read |
required |
returns: str: File content as a single string
Source code in chilka.py
109 110 111 112 113 114 115 116 117 118 119 |
|
readSents(filename, range_filter=None, kw_filter=None, plugin_args={})
abstractmethod
Returns a file as an iterator of {n:<>,sent:<>} dictionaries
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file to be read |
required |
range_filter
|
tuple
|
(optional)Range of lines to read |
None
|
kw_filter
|
str
|
(optional)Search term to return sentences containing it |
None
|
returns: iterator: An iterator of dictionaries containing sentences from the file with serial number starting from 1
Source code in chilka.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
remove(filename, plugin_args={})
abstractmethod
Removes a file from the corpus
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The name of the file to be removed from the corpus |
required |
Returns: bool: True if the collection was removed successfully, false if it does not exist
Source code in chilka.py
81 82 83 84 85 86 87 88 89 90 91 92 |
|