scibite-toolkit 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ The toolkit is dual licensed, if you are a customer it is covered under your existing conditions, if not currently a customer the toolkit is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
@@ -0,0 +1,241 @@
1
+ Metadata-Version: 2.1
2
+ Name: scibite_toolkit
3
+ Version: 1.0.0
4
+ Summary: scibite-toolkit - python library for calling SciBite applications: TERMite, TExpress, SciBite Search, CENtree and Workbench. The library also enables processing of the JSON results from such requests
5
+ Home-page: https://github.com/elsevier-health/scibite-toolkit
6
+ Author: SciBite
7
+ Author-email: help@scibite.com
8
+ License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Requires-Dist: bs4
14
+ Requires-Dist: pandas
15
+ Requires-Dist: openpyxl
16
+ Requires-Dist: requests
17
+ Requires-Dist: sphinx
18
+ Requires-Dist: sphinx-js
19
+ Requires-Dist: rst2pdf
20
+
21
+ ### Project Description
22
+
23
+ scibite-toolkit - python library for making calls to [SciBite](https://www.scibite.com/)'s TERMite, CENtree, Workbench and SciBite Search.
24
+ The library also enables post-processing of the JSON returned from such requests.
25
+
26
+ ## Install
27
+
28
+ ```
29
+ $ pip3 install scibite_toolkit
30
+ ```
31
+ Versions listed on [PyPi](https://pypi.org/project/scibite-toolkit/)!
32
+
33
+ ## Example call to TERMite
34
+ In this example call to TERMite, we will annotate one zip file from MEDLINE and then process the output to a dataframe with the built in functions of the toolkit.
35
+
36
+
37
+
38
+ We will use the first zip file from PubMed's Annual Baseline files.
39
+
40
+
41
+
42
+ Two example scripts will be shown - one that authenticates with a SciBite hosted instance of TERMite and one that hosts with a local instance of TERMite (hosted by customer).
43
+
44
+
45
+
46
+ *Please note the following:
47
+
48
+ you can test with any file.
49
+ If you would like to test with just text (and not a file), please use "t.set_text('your text') and don't use the t.set_binary_content command.
50
+
51
+ ### Example 1 - SciBite Hosted instance of TERMite
52
+ ```python
53
+ import pandas as pd
54
+ from scibite_toolkit import termite
55
+
56
+ # Initialize your TERMite Request
57
+ t = termite.TermiteRequestBuilder()
58
+
59
+ # Specify your TERMite API Endpoint and login URL
60
+ t.set_url('url_endpoint')
61
+ t.set_saas_login_url('login_url')
62
+
63
+ # Authenticate with the instance
64
+ username = 'username
65
+ password = 'password'
66
+ t.set_auth_saas(username, password)
67
+
68
+ # Set your runtime options
69
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
70
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
71
+ t.set_output_format('json') # the output format of the response from TERMite
72
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
73
+ t.set_subsume(True) # set subsume run time option (RTO) to true
74
+
75
+ # Execute the request and convert response to dataframe for easy analysis
76
+ termite_response = t.execute()
77
+ resp_df = termite.get_termite_dataframe(termite_response)
78
+ print(resp_df.head(3))
79
+ ```
80
+ ### Example 2 - Local Instance of TERMite (Hosted by Customer)
81
+
82
+ ```python
83
+ import pandas as pd
84
+ from scibite_toolkit import termite
85
+
86
+ # Initialize your TERMite Request
87
+ t = termite.TermiteRequestBuilder()
88
+
89
+ # Specify your TERMite API Endpoint and login URL
90
+ t.set_url('url_endpoint')
91
+
92
+ # Authenticate with the instance
93
+ username = 'username'
94
+ password = 'password^'
95
+ t.set_basic_auth(username, password)
96
+
97
+ # Set your runtime options
98
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
99
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
100
+ t.set_output_format('json') # the output format of the response from TERMite
101
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
102
+ t.set_subsume(True) # set subsume run time option (RTO) to true
103
+
104
+ # Execute the request and convert response to dataframe for easy analysis
105
+ termite_response = t.execute()
106
+ resp_df = termite.get_termite_dataframe(termite_response)
107
+ print(resp_df.head(3))
108
+ ```
109
+ ## Example call to TExpress
110
+ In this example call to TExpress, we will annotate one zip file from Medline and then process the output to a dataframe with the built in functions of the toolkit.
111
+
112
+
113
+
114
+ We will use the first zip file from PubMed's Annual Baseline files.
115
+
116
+
117
+
118
+ Two example scripts will be shown - one that authenticates with a SciBite hosted instance of TExpress and one that authenticates with a local instance of TExpress (hosted by the customer).
119
+
120
+
121
+
122
+ Please note the following:
123
+
124
+ you can test with any file.
125
+ If you would like to test with just text (and not a file), please use "t.set_text('your text') and don't use the t.set_binary_content command.
126
+
127
+ ### Example 1 - SciBite Hosted Instance of TExpress
128
+ ```python
129
+ import pandas as pd
130
+ from scibite_toolkit import texpress
131
+
132
+ # Initialize your TERMite Request
133
+ t = texpress.TexpressRequestBuilder()
134
+
135
+ # Specify your TERMite API Endpoint and login URL
136
+ t.set_url('url_endpoint')
137
+ t.set_saas_login_url('login_url')
138
+
139
+ # Authenticate with the instance
140
+ username = 'username'
141
+ password = 'password'
142
+ t.set_auth_saas(username, password)
143
+
144
+ # Set your runtime options
145
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
146
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
147
+ t.set_output_format('json') # the output format of the response from TERMite
148
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
149
+ t.set_subsume(True) # set subsume run time option (RTO) to true
150
+ t.set_pattern(':(INDICATION):{0,5}:(INDICATION)') # pattern to tell TExpress what to look for within data
151
+
152
+ # Execute the request and convert response to dataframe for easy analysis
153
+ texpress_resp = t.execute()
154
+ resp_df = texpress.get_texpress_dataframe(texpress_resp)
155
+ print(resp_df.head(3))
156
+ ```
157
+ ### Example 2 - Local Instance of TExpress (Hosted by Customer)
158
+ ```python
159
+ import pandas as pd
160
+ from scibite_toolkit import texpress
161
+
162
+ # Initialize your TERMite Request
163
+ t = texpress.TexpressRequestBuilder()
164
+
165
+ # Specify your TERMite API Endpoint
166
+ t.set_url('url_endpoint')
167
+
168
+ # Authenticate with the instance
169
+ username = 'username'
170
+ password = 'password'
171
+ t.set_basic_auth(username, password)
172
+
173
+ # Set your runtime options
174
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
175
+ t.set_input_format('pdf') # the input format of the data sent to TERMite
176
+ t.set_output_format('medline.xml') # the output format of the response from TERMite
177
+ t.set_binary_content('/path/to/file') # the file path of the file you want to annotate
178
+ t.set_subsume(True) # set subsume run time option (RTO) to true
179
+ t.set_pattern(':(INDICATION):{0,5}:(INDICATION)') # pattern to tell TExpress what to look for within data
180
+
181
+ # Execute the request and convert response to dataframe for easy analysis
182
+ texpress_resp = t.execute()
183
+ resp_df = texpress.get_texpress_dataframe(texpress_resp)
184
+ print(resp_df.head(3))
185
+ ```
186
+ ## Example call to SciBite Search
187
+
188
+ ```python
189
+ from scibite_toolkit import scibite_search
190
+
191
+ # First authenticate - The examples provided are assuming our SaaS-hosted instances, adapt accordingly
192
+ ss_home = 'https://yourdomain-search.saas.scibite.com/'
193
+ sbs_auth_url = "https://yourdomain.saas.scibite.com/"
194
+ client_id = "yourclientid"
195
+ client_secret ="yourclientsecret"
196
+ s = scibite_search.SBSRequestBuilder()
197
+ s.set_url(ss_home)
198
+ s.set_auth_url(sbs_auth_url)
199
+ s.set_oauth2(client_id,client_secret) #Authentication will last according to what was was set up when generating the client
200
+
201
+ # Now you can use the request object
202
+
203
+ # Search over documents
204
+ sample_query = 'schema_id="clinical_trial" AND (title~INDICATION$D011565 AND DRUG$*)'
205
+
206
+ # Note that endpoint is capped at 100 results, but you can paginate using the offset parameter
207
+ response = s.get_docs(query=sample_query,markup=True,limit=100)
208
+
209
+ # Co-ocurrence search across sentences
210
+ # Get the top 50 co-ocurrence sentence aggregates for psoriasis indication and any gene
211
+ response = s.get_aggregates(query='INDICATION$D011565',vocabs=['HGNCGENE'],limit=50)
212
+
213
+ ```
214
+ ## Example call to Workbench
215
+
216
+ ```python
217
+ from scibite_toolkit import workbench
218
+ #first authenticate with the instance
219
+ username = 'username'
220
+ password = 'password'
221
+ client_id = 'client_id'
222
+ wb = WorkbenchRequestBuilder()
223
+ url = 'https://workbench-url.com'
224
+ wb.set_oauth2(client_id, username, password)
225
+ #then set up your call - here we will be creating a WB dataset, uploading a file to it and annotating it
226
+ wb.set_dataset_name = 'My Test Dataset'
227
+ wb.set_dataset_desc = 'My Test Description'
228
+ wb.create_dataset()
229
+ wb.set_file_input('path/to/file.xlsx')
230
+ wb.upload_file_to_dataset()
231
+ #In this example, we will only annotate two columns with pre-selected VOCabs.
232
+ #If you would like to tell WB to annotate the dataset without setting a termite config, just call auto_annotate_dataset
233
+ vocabs = [[5,6],[8,9]]
234
+ attrs = [200,201]
235
+ wb.set_termite_config('',vocabs,attrs)
236
+ wb.auto_annotate_dataset()
237
+ ```
238
+
239
+ ## License
240
+
241
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
@@ -0,0 +1,221 @@
1
+ ### Project Description
2
+
3
+ scibite-toolkit - python library for making calls to [SciBite](https://www.scibite.com/)'s TERMite, CENtree, Workbench and SciBite Search.
4
+ The library also enables post-processing of the JSON returned from such requests.
5
+
6
+ ## Install
7
+
8
+ ```
9
+ $ pip3 install scibite_toolkit
10
+ ```
11
+ Versions listed on [PyPi](https://pypi.org/project/scibite-toolkit/)!
12
+
13
+ ## Example call to TERMite
14
+ In this example call to TERMite, we will annotate one zip file from MEDLINE and then process the output to a dataframe with the built in functions of the toolkit.
15
+
16
+
17
+
18
+ We will use the first zip file from PubMed's Annual Baseline files.
19
+
20
+
21
+
22
+ Two example scripts will be shown - one that authenticates with a SciBite hosted instance of TERMite and one that hosts with a local instance of TERMite (hosted by customer).
23
+
24
+
25
+
26
+ *Please note the following:
27
+
28
+ you can test with any file.
29
+ If you would like to test with just text (and not a file), please use "t.set_text('your text') and don't use the t.set_binary_content command.
30
+
31
+ ### Example 1 - SciBite Hosted instance of TERMite
32
+ ```python
33
+ import pandas as pd
34
+ from scibite_toolkit import termite
35
+
36
+ # Initialize your TERMite Request
37
+ t = termite.TermiteRequestBuilder()
38
+
39
+ # Specify your TERMite API Endpoint and login URL
40
+ t.set_url('url_endpoint')
41
+ t.set_saas_login_url('login_url')
42
+
43
+ # Authenticate with the instance
44
+ username = 'username
45
+ password = 'password'
46
+ t.set_auth_saas(username, password)
47
+
48
+ # Set your runtime options
49
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
50
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
51
+ t.set_output_format('json') # the output format of the response from TERMite
52
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
53
+ t.set_subsume(True) # set subsume run time option (RTO) to true
54
+
55
+ # Execute the request and convert response to dataframe for easy analysis
56
+ termite_response = t.execute()
57
+ resp_df = termite.get_termite_dataframe(termite_response)
58
+ print(resp_df.head(3))
59
+ ```
60
+ ### Example 2 - Local Instance of TERMite (Hosted by Customer)
61
+
62
+ ```python
63
+ import pandas as pd
64
+ from scibite_toolkit import termite
65
+
66
+ # Initialize your TERMite Request
67
+ t = termite.TermiteRequestBuilder()
68
+
69
+ # Specify your TERMite API Endpoint and login URL
70
+ t.set_url('url_endpoint')
71
+
72
+ # Authenticate with the instance
73
+ username = 'username'
74
+ password = 'password^'
75
+ t.set_basic_auth(username, password)
76
+
77
+ # Set your runtime options
78
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
79
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
80
+ t.set_output_format('json') # the output format of the response from TERMite
81
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
82
+ t.set_subsume(True) # set subsume run time option (RTO) to true
83
+
84
+ # Execute the request and convert response to dataframe for easy analysis
85
+ termite_response = t.execute()
86
+ resp_df = termite.get_termite_dataframe(termite_response)
87
+ print(resp_df.head(3))
88
+ ```
89
+ ## Example call to TExpress
90
+ In this example call to TExpress, we will annotate one zip file from Medline and then process the output to a dataframe with the built in functions of the toolkit.
91
+
92
+
93
+
94
+ We will use the first zip file from PubMed's Annual Baseline files.
95
+
96
+
97
+
98
+ Two example scripts will be shown - one that authenticates with a SciBite hosted instance of TExpress and one that authenticates with a local instance of TExpress (hosted by the customer).
99
+
100
+
101
+
102
+ Please note the following:
103
+
104
+ you can test with any file.
105
+ If you would like to test with just text (and not a file), please use "t.set_text('your text') and don't use the t.set_binary_content command.
106
+
107
+ ### Example 1 - SciBite Hosted Instance of TExpress
108
+ ```python
109
+ import pandas as pd
110
+ from scibite_toolkit import texpress
111
+
112
+ # Initialize your TERMite Request
113
+ t = texpress.TexpressRequestBuilder()
114
+
115
+ # Specify your TERMite API Endpoint and login URL
116
+ t.set_url('url_endpoint')
117
+ t.set_saas_login_url('login_url')
118
+
119
+ # Authenticate with the instance
120
+ username = 'username'
121
+ password = 'password'
122
+ t.set_auth_saas(username, password)
123
+
124
+ # Set your runtime options
125
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
126
+ t.set_input_format('medline.xml') # the input format of the data sent to TERMite
127
+ t.set_output_format('json') # the output format of the response from TERMite
128
+ t.set_binary_content('path/to/file') # the file path of the file you want to annotate
129
+ t.set_subsume(True) # set subsume run time option (RTO) to true
130
+ t.set_pattern(':(INDICATION):{0,5}:(INDICATION)') # pattern to tell TExpress what to look for within data
131
+
132
+ # Execute the request and convert response to dataframe for easy analysis
133
+ texpress_resp = t.execute()
134
+ resp_df = texpress.get_texpress_dataframe(texpress_resp)
135
+ print(resp_df.head(3))
136
+ ```
137
+ ### Example 2 - Local Instance of TExpress (Hosted by Customer)
138
+ ```python
139
+ import pandas as pd
140
+ from scibite_toolkit import texpress
141
+
142
+ # Initialize your TERMite Request
143
+ t = texpress.TexpressRequestBuilder()
144
+
145
+ # Specify your TERMite API Endpoint
146
+ t.set_url('url_endpoint')
147
+
148
+ # Authenticate with the instance
149
+ username = 'username'
150
+ password = 'password'
151
+ t.set_basic_auth(username, password)
152
+
153
+ # Set your runtime options
154
+ t.set_entities('INDICATION') # comma separated list of VOCabs you want to run over your data
155
+ t.set_input_format('pdf') # the input format of the data sent to TERMite
156
+ t.set_output_format('medline.xml') # the output format of the response from TERMite
157
+ t.set_binary_content('/path/to/file') # the file path of the file you want to annotate
158
+ t.set_subsume(True) # set subsume run time option (RTO) to true
159
+ t.set_pattern(':(INDICATION):{0,5}:(INDICATION)') # pattern to tell TExpress what to look for within data
160
+
161
+ # Execute the request and convert response to dataframe for easy analysis
162
+ texpress_resp = t.execute()
163
+ resp_df = texpress.get_texpress_dataframe(texpress_resp)
164
+ print(resp_df.head(3))
165
+ ```
166
+ ## Example call to SciBite Search
167
+
168
+ ```python
169
+ from scibite_toolkit import scibite_search
170
+
171
+ # First authenticate - The examples provided are assuming our SaaS-hosted instances, adapt accordingly
172
+ ss_home = 'https://yourdomain-search.saas.scibite.com/'
173
+ sbs_auth_url = "https://yourdomain.saas.scibite.com/"
174
+ client_id = "yourclientid"
175
+ client_secret ="yourclientsecret"
176
+ s = scibite_search.SBSRequestBuilder()
177
+ s.set_url(ss_home)
178
+ s.set_auth_url(sbs_auth_url)
179
+ s.set_oauth2(client_id,client_secret) #Authentication will last according to what was was set up when generating the client
180
+
181
+ # Now you can use the request object
182
+
183
+ # Search over documents
184
+ sample_query = 'schema_id="clinical_trial" AND (title~INDICATION$D011565 AND DRUG$*)'
185
+
186
+ # Note that endpoint is capped at 100 results, but you can paginate using the offset parameter
187
+ response = s.get_docs(query=sample_query,markup=True,limit=100)
188
+
189
+ # Co-ocurrence search across sentences
190
+ # Get the top 50 co-ocurrence sentence aggregates for psoriasis indication and any gene
191
+ response = s.get_aggregates(query='INDICATION$D011565',vocabs=['HGNCGENE'],limit=50)
192
+
193
+ ```
194
+ ## Example call to Workbench
195
+
196
+ ```python
197
+ from scibite_toolkit import workbench
198
+ #first authenticate with the instance
199
+ username = 'username'
200
+ password = 'password'
201
+ client_id = 'client_id'
202
+ wb = WorkbenchRequestBuilder()
203
+ url = 'https://workbench-url.com'
204
+ wb.set_oauth2(client_id, username, password)
205
+ #then set up your call - here we will be creating a WB dataset, uploading a file to it and annotating it
206
+ wb.set_dataset_name = 'My Test Dataset'
207
+ wb.set_dataset_desc = 'My Test Description'
208
+ wb.create_dataset()
209
+ wb.set_file_input('path/to/file.xlsx')
210
+ wb.upload_file_to_dataset()
211
+ #In this example, we will only annotate two columns with pre-selected VOCabs.
212
+ #If you would like to tell WB to annotate the dataset without setting a termite config, just call auto_annotate_dataset
213
+ vocabs = [[5,6],[8,9]]
214
+ attrs = [200,201]
215
+ wb.set_termite_config('',vocabs,attrs)
216
+ wb.auto_annotate_dataset()
217
+ ```
218
+
219
+ ## License
220
+
221
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
@@ -0,0 +1,4 @@
1
+ from .termite import *
2
+ from .texpress import *
3
+
4
+
@@ -0,0 +1,158 @@
1
+ import requests
2
+ import logging
3
+
4
+ # Get the logger for this module
5
+ logger = logging.getLogger(__name__)
6
+
7
+ class CentreeRequestBuilder:
8
+ """
9
+ Class for creating CENtree Requests.
10
+ """
11
+
12
+ def __init__(self, timeout: int = 10):
13
+ """
14
+ Initialize the CentreeRequestBuilder.
15
+
16
+ Parameters
17
+ ----------
18
+ timeout : int, optional
19
+ The timeout for HTTP requests in seconds (default is 10 seconds).
20
+ """
21
+ self.centree_url = ''
22
+ self.headers = {}
23
+ self.session = requests.Session()
24
+ self.timeout = timeout
25
+ self.logger: logging.Logger = logger
26
+
27
+ def set_url(self, centree_url: str):
28
+ """
29
+ Set the URL of the CENtree instance.
30
+
31
+ Parameters
32
+ ----------
33
+ centree_url : str
34
+ The URL of the CENtree instance to be hit.
35
+
36
+ Examples
37
+ --------
38
+ >>> crb.set_url("http://example.com")
39
+ """
40
+ self.centree_url = centree_url.rstrip('/')
41
+ self.logger.info(f"Set CENtree URL to {self.centree_url}")
42
+
43
+ def set_authentication(self, username: str, password: str, remember_me: bool = True, verification: bool = True):
44
+ """
45
+ Authenticates with the CENtree token API using username and password, generates an access token,
46
+ and sets the request header.
47
+
48
+ Parameters
49
+ ----------
50
+ username : str
51
+ The username for authentication.
52
+ password : str
53
+ The password for authentication.
54
+ remember_me : bool, optional
55
+ Whether to remember the user (default is True).
56
+ verification : bool, optional
57
+ Whether to verify SSL certificates (default is True).
58
+
59
+ Examples
60
+ --------
61
+ >>> crb.set_authentication("user", "pass")
62
+ """
63
+ authenticate_url = f"{self.centree_url}/api/authenticate"
64
+
65
+ try:
66
+ token_response = self.session.post(
67
+ authenticate_url,
68
+ json={
69
+ "rememberMe": remember_me,
70
+ "username": username,
71
+ "password": password,
72
+ },
73
+ headers={"Content-Type": "application/json"},
74
+ verify=verification,
75
+ timeout=self.timeout
76
+ )
77
+ token_response.raise_for_status()
78
+ access_token = token_response.json().get("id_token")
79
+
80
+ if not access_token:
81
+ raise ValueError("Access token not found in the response.")
82
+
83
+ self.headers = {"Authorization": f"Bearer {access_token}"}
84
+ self.logger.info("Authentication successful")
85
+
86
+
87
+ except requests.exceptions.HTTPError as http_err:
88
+ self.logger.error(f"HTTP error occurred: {http_err.response.status_code} - {http_err.response.reason}")
89
+ raise http_err # Re-raise the HTTPError for the test to catch
90
+ except requests.exceptions.RequestException as req_err:
91
+ self.logger.error(f"Request error: {req_err}")
92
+ raise req_err # Re-raise the RequestException for the test to catch
93
+ except ValueError as val_err:
94
+ self.logger.error(f"Value error: {val_err}")
95
+ raise val_err # Re-raise the ValueError for the test to catch
96
+ except Exception as err:
97
+ self.logger.error(f"An error occurred: {err}")
98
+ raise err # Re-raise the generic exception for the test to catch
99
+
100
+ def search_classes(self, query: str, ontology_id: str = None, exact: bool = False, obsolete: bool = False,
101
+ page_from: int = 0, page_size: int = 10) -> dict:
102
+ """
103
+ Search classes in the CENtree ontology.
104
+
105
+ Parameters
106
+ ----------
107
+ query : str
108
+ The search query.
109
+ ontology_id : str, optional
110
+ The ontology ID to search within.
111
+ exact : bool, optional
112
+ Whether to perform an exact search (default is False).
113
+ obsolete : bool, optional
114
+ Whether to include obsolete classes (default is False).
115
+ page_from : int, optional
116
+ The starting page number (default is 0).
117
+ page_size : int, optional
118
+ The number of results per page (default is 10).
119
+
120
+ Returns
121
+ -------
122
+ dict
123
+ The JSON response from the search endpoint.
124
+
125
+ Examples
126
+ --------
127
+ >>> result = crb.search_classes("diabetes")
128
+ """
129
+ params = {
130
+ "q": query,
131
+ "ontology": ontology_id,
132
+ "from": page_from,
133
+ "size": page_size
134
+ }
135
+
136
+ # Clean up params dictionary to remove None values
137
+ params = {k: v for k, v in params.items() if v is not None}
138
+
139
+ # Construct the endpoint URL
140
+ endpoint_suffix = ''
141
+ if obsolete:
142
+ endpoint_suffix += '/obsolete'
143
+ if exact:
144
+ endpoint_suffix += '/exact'
145
+
146
+ search_endpoint = f"{self.centree_url}/api/search{endpoint_suffix}"
147
+
148
+ try:
149
+ response = self.session.get(search_endpoint, params=params, headers=self.headers, timeout=self.timeout)
150
+ response.raise_for_status()
151
+ self.logger.info("Search request successful")
152
+ return response.json()
153
+ except requests.exceptions.HTTPError as http_err:
154
+ self.logger.error(f"HTTP error occurred: {http_err}")
155
+ except requests.exceptions.RequestException as req_err:
156
+ self.logger.error(f"Request error occurred: {req_err}")
157
+ except Exception as err:
158
+ self.logger.error(f"An error occurred: {err}")