wbtools 3.1.0__tar.gz → 3.3.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.
Files changed (65) hide show
  1. {wbtools-3.1.0 → wbtools-3.3.0}/PKG-INFO +6 -5
  2. wbtools-3.3.0/pyproject.toml +38 -0
  3. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/literature/paper.py +5 -2
  4. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/utils/alliance.py +1 -1
  5. wbtools-3.3.0/wbtools/utils/auth_utils.py +21 -0
  6. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools.egg-info/PKG-INFO +6 -5
  7. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools.egg-info/SOURCES.txt +2 -21
  8. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools.egg-info/requires.txt +2 -1
  9. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools.egg-info/top_level.txt +0 -1
  10. wbtools-3.1.0/setup.py +0 -38
  11. wbtools-3.1.0/tests/config_reader.py +0 -23
  12. wbtools-3.1.0/tests/db/test_afp.py +0 -23
  13. wbtools-3.1.0/tests/db/test_antibody.py +0 -23
  14. wbtools-3.1.0/tests/db/test_expression.py +0 -25
  15. wbtools-3.1.0/tests/db/test_generic.py +0 -44
  16. wbtools-3.1.0/tests/lib/entity_extraction/test_email_addresses.py +0 -35
  17. wbtools-3.1.0/tests/lib/entity_extraction/test_generic.py +0 -46
  18. wbtools-3.1.0/tests/lib/entity_extraction/test_new_variations.py +0 -44
  19. wbtools-3.1.0/tests/lib/test_literature_index.py +0 -29
  20. wbtools-3.1.0/tests/lib/test_scraping.py +0 -18
  21. wbtools-3.1.0/tests/lib/test_text_preprocessing.py +0 -59
  22. wbtools-3.1.0/tests/lib/test_text_similarity.py +0 -52
  23. wbtools-3.1.0/tests/literature/test_corpus.py +0 -86
  24. wbtools-3.1.0/tests/literature/test_paper.py +0 -110
  25. wbtools-3.1.0/wbtools/lib/nlp/__init__.py +0 -0
  26. wbtools-3.1.0/wbtools/lib/nlp/entity_extraction/__init__.py +0 -0
  27. wbtools-3.1.0/wbtools/lib/nlp/literature_index/__init__.py +0 -0
  28. wbtools-3.1.0/wbtools/literature/__init__.py +0 -0
  29. wbtools-3.1.0/wbtools/utils/__init__.py +0 -0
  30. wbtools-3.1.0/wbtools/utils/okta_utils.py +0 -67
  31. {wbtools-3.1.0 → wbtools-3.3.0}/LICENSE +0 -0
  32. {wbtools-3.1.0 → wbtools-3.3.0}/README.md +0 -0
  33. {wbtools-3.1.0 → wbtools-3.3.0}/setup.cfg +0 -0
  34. {wbtools-3.1.0/tests → wbtools-3.3.0/wbtools}/__init__.py +0 -0
  35. {wbtools-3.1.0/tests → wbtools-3.3.0/wbtools}/db/__init__.py +0 -0
  36. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/abstract_manager.py +0 -0
  37. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/afp.py +0 -0
  38. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/antibody.py +0 -0
  39. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/dbmanager.py +0 -0
  40. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/expression.py +0 -0
  41. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/gene.py +0 -0
  42. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/generic.py +0 -0
  43. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/paper.py +0 -0
  44. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/db/person.py +0 -0
  45. {wbtools-3.1.0/tests → wbtools-3.3.0/wbtools}/lib/__init__.py +0 -0
  46. {wbtools-3.1.0/tests/lib/entity_extraction → wbtools-3.3.0/wbtools/lib/email}/__init__.py +0 -0
  47. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/email/generic.py +0 -0
  48. {wbtools-3.1.0/tests/literature → wbtools-3.3.0/wbtools/lib/nlp}/__init__.py +0 -0
  49. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/common.py +0 -0
  50. {wbtools-3.1.0/wbtools → wbtools-3.3.0/wbtools/lib/nlp/entity_extraction}/__init__.py +0 -0
  51. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/entity_extraction/email_addresses.py +0 -0
  52. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/entity_extraction/ntt_extractor.py +0 -0
  53. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/entity_extraction/variations.py +0 -0
  54. {wbtools-3.1.0/wbtools/db → wbtools-3.3.0/wbtools/lib/nlp/literature_index}/__init__.py +0 -0
  55. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/literature_index/abstract_index.py +0 -0
  56. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/literature_index/textpresso.py +0 -0
  57. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/text_preprocessing.py +0 -0
  58. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/nlp/text_similarity.py +0 -0
  59. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/scraping.py +0 -0
  60. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/lib/timeout.py +0 -0
  61. {wbtools-3.1.0/wbtools/lib → wbtools-3.3.0/wbtools/literature}/__init__.py +0 -0
  62. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/literature/corpus.py +0 -0
  63. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools/literature/person.py +0 -0
  64. {wbtools-3.1.0/wbtools/lib/email → wbtools-3.3.0/wbtools/utils}/__init__.py +0 -0
  65. {wbtools-3.1.0 → wbtools-3.3.0}/wbtools.egg-info/dependency_links.txt +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wbtools
3
- Version: 3.1.0
3
+ Version: 3.3.0
4
4
  Summary: Interface to WormBase (www.wormbase.org) curation data, including literature management and NLP functions
5
- Home-page: https://github.com/WormBase/wbtools
6
- Author: Valerio Arnaboldi
7
- Author-email: valearna@caltech.edu
5
+ Author-email: Valerio Arnaboldi <valearna@caltech.edu>
6
+ Project-URL: Homepage, https://github.com/WormBase/wbtools
7
+ Project-URL: Repository, https://github.com/WormBase/wbtools
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
@@ -16,14 +16,15 @@ Requires-Dist: numpy~=1.19.2
16
16
  Requires-Dist: fabric~=2.5.0
17
17
  Requires-Dist: gensim~=3.8.3
18
18
  Requires-Dist: nltk~=3.5
19
- Requires-Dist: setuptools~=50.3.2
20
19
  Requires-Dist: regex~=2020.10.28
21
20
  Requires-Dist: pdfminer.six==20201018
22
21
  Requires-Dist: pytz~=2021.1
23
22
  Requires-Dist: pandas~=1.3.3
24
23
  Requires-Dist: requests~=2.31.0
25
24
  Requires-Dist: python-dateutil~=2.8.2
25
+ Requires-Dist: python-dotenv~=1.0.0
26
26
  Requires-Dist: grobid-client
27
+ Requires-Dist: agr-cognito-py
27
28
 
28
29
  # WBtools
29
30
  > Interface to WormBase curation database and Text Mining functions
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "wbtools"
7
+ version = "3.3.0"
8
+ authors = [
9
+ {name = "Valerio Arnaboldi", email = "valearna@caltech.edu"},
10
+ ]
11
+ description = "Interface to WormBase (www.wormbase.org) curation data, including literature management and NLP functions"
12
+ readme = "README.md"
13
+ requires-python = ">=3.6"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "psycopg2-binary",
21
+ "numpy~=1.19.2",
22
+ "fabric~=2.5.0",
23
+ "gensim~=3.8.3",
24
+ "nltk~=3.5",
25
+ "regex~=2020.10.28",
26
+ "pdfminer.six==20201018",
27
+ "pytz~=2021.1",
28
+ "pandas~=1.3.3",
29
+ "requests~=2.31.0",
30
+ "python-dateutil~=2.8.2",
31
+ "python-dotenv~=1.0.0",
32
+ "grobid-client",
33
+ "agr-cognito-py",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/WormBase/wbtools"
38
+ Repository = "https://github.com/WormBase/wbtools"
@@ -26,7 +26,7 @@ from wbtools.lib.nlp.entity_extraction.email_addresses import get_email_addresse
26
26
  from wbtools.lib.nlp.text_preprocessing import preprocess, get_documents_from_text, PaperSections
27
27
  from wbtools.lib.timeout import timeout
28
28
  from wbtools.literature.person import WBAuthor
29
- from wbtools.utils.okta_utils import get_authentication_token, generate_headers
29
+ from wbtools.utils.auth_utils import get_authentication_token, generate_headers
30
30
 
31
31
  logger = logging.getLogger(__name__)
32
32
 
@@ -193,6 +193,7 @@ class WBPaper(object):
193
193
  blue_api_base_url = os.environ.get('API_SERVER', "literature-rest.alliancegenome.org")
194
194
  all_reffiles_for_pap_api = f'https://{blue_api_base_url}/reference/referencefile/show_all/{self.agr_curie}'
195
195
  request = urllib.request.Request(url=all_reffiles_for_pap_api)
196
+ request.add_header("Authorization", f"Bearer {get_authentication_token()}")
196
197
  request.add_header("Content-type", "application/json")
197
198
  request.add_header("Accept", "application/json")
198
199
  added_ref_files = 0
@@ -227,7 +228,9 @@ class WBPaper(object):
227
228
  raise Exception("PaperDBManager not set")
228
229
  # Get Alliance reference info from WBPaperID
229
230
  ref_info_from_xref_api = f"https://{ABC_API}/reference/by_cross_reference/WB:WBPaper{self.paper_id}"
230
- ref_info: dict = get_data_from_url(ref_info_from_xref_api)
231
+ token = get_authentication_token()
232
+ headers = generate_headers(token)
233
+ ref_info: dict = get_data_from_url(ref_info_from_xref_api, headers)
231
234
  if ref_info:
232
235
  self.abstract = ref_info["abstract"]
233
236
  self.title = ref_info["title"]
@@ -3,7 +3,7 @@ import logging
3
3
  import urllib.request
4
4
 
5
5
  from wbtools.lib.nlp.common import EntityType
6
- from wbtools.utils.okta_utils import get_authentication_token
6
+ from wbtools.utils.auth_utils import get_authentication_token
7
7
 
8
8
 
9
9
  logger = logging.getLogger(__name__)
@@ -0,0 +1,21 @@
1
+ """
2
+ Authentication utilities for AGR API access.
3
+
4
+ This module provides authentication token generation using AWS Cognito
5
+ via the agr_cognito_py library. The functions are re-exported for
6
+ backward compatibility with code that was using the old Okta-based
7
+ authentication.
8
+
9
+ Required environment variables for Cognito authentication:
10
+ - COGNITO_ADMIN_CLIENT_ID
11
+ - COGNITO_ADMIN_CLIENT_SECRET
12
+ - COGNITO_TOKEN_URL
13
+ - COGNITO_ADMIN_SCOPE
14
+ """
15
+
16
+ from agr_cognito_py import (
17
+ get_admin_token as get_authentication_token,
18
+ generate_headers
19
+ )
20
+
21
+ __all__ = ['get_authentication_token', 'generate_headers']
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wbtools
3
- Version: 3.1.0
3
+ Version: 3.3.0
4
4
  Summary: Interface to WormBase (www.wormbase.org) curation data, including literature management and NLP functions
5
- Home-page: https://github.com/WormBase/wbtools
6
- Author: Valerio Arnaboldi
7
- Author-email: valearna@caltech.edu
5
+ Author-email: Valerio Arnaboldi <valearna@caltech.edu>
6
+ Project-URL: Homepage, https://github.com/WormBase/wbtools
7
+ Project-URL: Repository, https://github.com/WormBase/wbtools
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
@@ -16,14 +16,15 @@ Requires-Dist: numpy~=1.19.2
16
16
  Requires-Dist: fabric~=2.5.0
17
17
  Requires-Dist: gensim~=3.8.3
18
18
  Requires-Dist: nltk~=3.5
19
- Requires-Dist: setuptools~=50.3.2
20
19
  Requires-Dist: regex~=2020.10.28
21
20
  Requires-Dist: pdfminer.six==20201018
22
21
  Requires-Dist: pytz~=2021.1
23
22
  Requires-Dist: pandas~=1.3.3
24
23
  Requires-Dist: requests~=2.31.0
25
24
  Requires-Dist: python-dateutil~=2.8.2
25
+ Requires-Dist: python-dotenv~=1.0.0
26
26
  Requires-Dist: grobid-client
27
+ Requires-Dist: agr-cognito-py
27
28
 
28
29
  # WBtools
29
30
  > Interface to WormBase curation database and Text Mining functions
@@ -1,25 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
- setup.py
4
- tests/__init__.py
5
- tests/config_reader.py
6
- tests/db/__init__.py
7
- tests/db/test_afp.py
8
- tests/db/test_antibody.py
9
- tests/db/test_expression.py
10
- tests/db/test_generic.py
11
- tests/lib/__init__.py
12
- tests/lib/test_literature_index.py
13
- tests/lib/test_scraping.py
14
- tests/lib/test_text_preprocessing.py
15
- tests/lib/test_text_similarity.py
16
- tests/lib/entity_extraction/__init__.py
17
- tests/lib/entity_extraction/test_email_addresses.py
18
- tests/lib/entity_extraction/test_generic.py
19
- tests/lib/entity_extraction/test_new_variations.py
20
- tests/literature/__init__.py
21
- tests/literature/test_corpus.py
22
- tests/literature/test_paper.py
3
+ pyproject.toml
23
4
  wbtools/__init__.py
24
5
  wbtools.egg-info/PKG-INFO
25
6
  wbtools.egg-info/SOURCES.txt
@@ -58,4 +39,4 @@ wbtools/literature/paper.py
58
39
  wbtools/literature/person.py
59
40
  wbtools/utils/__init__.py
60
41
  wbtools/utils/alliance.py
61
- wbtools/utils/okta_utils.py
42
+ wbtools/utils/auth_utils.py
@@ -3,11 +3,12 @@ numpy~=1.19.2
3
3
  fabric~=2.5.0
4
4
  gensim~=3.8.3
5
5
  nltk~=3.5
6
- setuptools~=50.3.2
7
6
  regex~=2020.10.28
8
7
  pdfminer.six==20201018
9
8
  pytz~=2021.1
10
9
  pandas~=1.3.3
11
10
  requests~=2.31.0
12
11
  python-dateutil~=2.8.2
12
+ python-dotenv~=1.0.0
13
13
  grobid-client
14
+ agr-cognito-py
@@ -1,2 +1 @@
1
- tests
2
1
  wbtools
wbtools-3.1.0/setup.py DELETED
@@ -1,38 +0,0 @@
1
- import setuptools
2
-
3
- with open("README.md", "r") as fh:
4
- long_description = fh.read()
5
-
6
- setuptools.setup(
7
- name="wbtools",
8
- version="3.1.0",
9
- author="Valerio Arnaboldi",
10
- author_email="valearna@caltech.edu",
11
- description="Interface to WormBase (www.wormbase.org) curation data, including literature management and NLP "
12
- "functions",
13
- long_description=long_description,
14
- long_description_content_type="text/markdown",
15
- url="https://github.com/WormBase/wbtools",
16
- packages=setuptools.find_packages(),
17
- classifiers=[
18
- "Programming Language :: Python :: 3",
19
- "License :: OSI Approved :: MIT License",
20
- "Operating System :: OS Independent",
21
- ],
22
- python_requires='>=3.6',
23
- install_requires=[
24
- 'psycopg2-binary',
25
- 'numpy~=1.19.2',
26
- 'fabric~=2.5.0',
27
- 'gensim~=3.8.3',
28
- 'nltk~=3.5',
29
- 'setuptools~=50.3.2',
30
- 'regex~=2020.10.28',
31
- 'pdfminer.six==20201018',
32
- 'pytz~=2021.1',
33
- 'pandas~=1.3.3',
34
- 'requests~=2.31.0',
35
- 'python-dateutil~=2.8.2',
36
- 'grobid-client'
37
- ]
38
- )
@@ -1,23 +0,0 @@
1
- import configparser
2
- import os
3
-
4
- import dotenv
5
-
6
-
7
- def read_config_file(file_path):
8
- config = configparser.ConfigParser()
9
- config.read(file_path)
10
- return config
11
-
12
-
13
- def read_db_config():
14
- return read_config_file(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "local_config", "db.cfg"))
15
-
16
-
17
- def read_tpc_config():
18
- return read_config_file(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "local_config",
19
- "textpresso.cfg"))
20
-
21
-
22
- def load_env_file():
23
- dotenv.load_dotenv(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "local_config", ".env"))
@@ -1,23 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_db_config
5
- from wbtools.db.afp import WBAFPDBManager
6
-
7
-
8
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
9
- "local_config", "db.cfg")), "Test DB config file not present")
10
- class TestWBAFPDBManager(unittest.TestCase):
11
-
12
- def setUp(self) -> None:
13
- config = read_db_config()
14
- self.db_manager = WBAFPDBManager(dbname=config["wb_database"]["db_name"],
15
- user=config["wb_database"]["db_user"],
16
- password=config["wb_database"]["db_password"],
17
- host=config["wb_database"]["db_host"])
18
-
19
- def test_get_stats_timeseries(self):
20
- monthly_stats = self.db_manager.get_stats_timeseries(bin_period='m')
21
- self.assertTrue(len(monthly_stats) > 0)
22
- self.assertTrue(len(monthly_stats[0]) == 2)
23
- self.assertTrue(len(monthly_stats[0][1]) == 5)
@@ -1,23 +0,0 @@
1
- import datetime
2
- import os
3
- import unittest
4
-
5
- from tests.config_reader import read_db_config
6
- from wbtools.db.antibody import WBAntibodyDBManager
7
-
8
-
9
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
10
- "local_config", "db.cfg")), "Test DB config file not present")
11
- class TestWBDBManager(unittest.TestCase):
12
-
13
- def setUp(self) -> None:
14
- config = read_db_config()
15
- self.db_manager = WBAntibodyDBManager(dbname=config["wb_database"]["db_name"],
16
- user=config["wb_database"]["db_user"],
17
- password=config["wb_database"]["db_password"],
18
- host=config["wb_database"]["db_host"])
19
-
20
- def test_get_antibody_str_values(self):
21
- antib_str_values = self.db_manager.get_antibody_str_values(
22
- from_date=datetime.datetime.now() - datetime.timedelta(days=365))
23
- self.assertTrue(len(antib_str_values) > 0)
@@ -1,25 +0,0 @@
1
- import unittest
2
- import os
3
-
4
- from tests.config_reader import read_db_config
5
- from wbtools.db.expression import WBExpressionDBManager
6
-
7
-
8
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
9
- "local_config", "db.cfg")), "Test DB config file not present")
10
- class TestWBExpressionDBManager(unittest.TestCase):
11
-
12
- def setUp(self) -> None:
13
- config = read_db_config()
14
- self.db_manager = WBExpressionDBManager(dbname=config["wb_database"]["db_name"],
15
- user=config["wb_database"]["db_user"],
16
- password=config["wb_database"]["db_password"],
17
- host=config["wb_database"]["db_host"])
18
-
19
- def test_get_all_expression_sentences(self):
20
- sentences = self.db_manager.get_all_expression_sentences()
21
- self.assertTrue(sentences)
22
-
23
-
24
- if __name__ == '__main__':
25
- unittest.main()
@@ -1,44 +0,0 @@
1
- import re
2
- import unittest
3
- import os
4
-
5
- from tests.config_reader import read_db_config
6
- from wbtools.db.generic import WBGenericDBManager
7
- from wbtools.lib.nlp.entity_extraction.ntt_extractor import ALL_VAR_REGEX
8
-
9
-
10
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
11
- "local_config", "db.cfg")), "Test DB config file not present")
12
- class TestWBDBManager(unittest.TestCase):
13
-
14
- def setUp(self) -> None:
15
- config = read_db_config()
16
- self.db_manager = WBGenericDBManager(dbname=config["wb_database"]["db_name"],
17
- user=config["wb_database"]["db_user"],
18
- password=config["wb_database"]["db_password"],
19
- host=config["wb_database"]["db_host"])
20
-
21
- def test_get_curated_variations(self):
22
- curated_variations = self.db_manager.get_curated_variations()
23
- self.assertGreater(len(curated_variations), 0)
24
- curated_variations = self.db_manager.get_curated_variations(exclude_id_used_as_name=True)
25
- allele_regex = ALL_VAR_REGEX.format(designations=self.db_manager.get_allele_designations())
26
- for variation in curated_variations:
27
- self.assertTrue(re.match(allele_regex, variation.lower()))
28
-
29
- def test_entity_name_id_maps(self):
30
- gene_name_id_map = self.db_manager.get_gene_name_id_map()
31
- self.assertTrue(len(gene_name_id_map) > 0)
32
-
33
- def test_get_curated_transgenes(self):
34
- all_curated = self.db_manager.get_curated_transgenes(exclude_id_used_as_name=False, exclude_invalid=False)
35
- exclude_invalid = self.db_manager.get_curated_transgenes(exclude_id_used_as_name=False, exclude_invalid=True)
36
- self.assertGreater(len(all_curated), len(exclude_invalid))
37
-
38
- def test_get_blacklisted_emails(self):
39
- blacklisted_emails = self.db_manager.get_blacklisted_email_addresses()
40
- self.assertGreater(len(blacklisted_emails), 0)
41
-
42
-
43
- if __name__ == '__main__':
44
- unittest.main()
@@ -1,35 +0,0 @@
1
- import unittest
2
- import os
3
-
4
- from tests.config_reader import read_db_config, load_env_file
5
- from wbtools.lib.nlp.entity_extraction.email_addresses import get_email_addresses_from_text
6
- from wbtools.literature.corpus import CorpusManager
7
-
8
-
9
- class TestEmailAddresses(unittest.TestCase):
10
-
11
- def test_get_email_addresses_from_text(self):
12
- text = "test@email.com is a valid email address. @email is not. test@ is not. Other valid email addresses are:" \
13
- " t.test@stat.email.org"
14
- addr = get_email_addresses_from_text(text)
15
- self.assertEqual(len(addr), 2)
16
-
17
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "data",
18
- "local_config", "db.cfg")), "Test DB config file not present")
19
- def test_get_email_addresses_from_paper(self):
20
- config = read_db_config()
21
- load_env_file()
22
- cm = CorpusManager()
23
- cm.load_from_wb_database(db_name=config["wb_database"]["db_name"], db_user=config["wb_database"]["db_user"],
24
- db_password=config["wb_database"]["db_password"],
25
- db_host=config["wb_database"]["db_host"],
26
- paper_ids=['00062455'])
27
- email_addresses = get_email_addresses_from_text(cm.get_paper('00062455').get_text_docs(
28
- include_supplemental=False, return_concatenated=True))
29
- email_addresses_in_wb = cm.get_paper('00062455').get_authors_with_email_address_in_wb()
30
- self.assertEqual(len(email_addresses), 3)
31
- self.assertGreaterEqual(len(email_addresses_in_wb), 2)
32
-
33
-
34
- if __name__ == '__main__':
35
- unittest.main()
@@ -1,46 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_db_config
5
- from wbtools.db.generic import WBGenericDBManager
6
- from wbtools.lib.nlp.common import EntityType
7
- from wbtools.lib.nlp.entity_extraction.ntt_extractor import NttExtractor
8
-
9
-
10
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "data",
11
- "local_config", "db.cfg")), "Test DB config file not present")
12
- class TestGenericNLP(unittest.TestCase):
13
-
14
- def setUp(self) -> None:
15
- config = read_db_config()
16
- self.db_manager = WBGenericDBManager(
17
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
18
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
19
- self.ntt_extractor = NttExtractor(db_manager=self.db_manager)
20
-
21
- def test_extract_entities(self):
22
- text = " g2 is a new variant"
23
- variations = self.ntt_extractor.extract_all_entities_by_type(text, entity_type=EntityType.VARIATION)
24
- self.assertEqual(len(variations), 1)
25
- self.assertTrue("g2" in variations)
26
-
27
- def test_get_strains_from_text(self):
28
- text = " AB4 is a strain, (N2) is another one, but AAA23 is not a strain "
29
- strains = self.ntt_extractor.extract_all_entities_by_type(text, EntityType.STRAIN, match_curated=True)
30
- self.assertEqual(len(strains), 2)
31
-
32
- def test_get_species_from_text(self):
33
- text = "C. elegans is a model organism. C. elegans, C. elegans and C. elegans. C. elegans (1), C. elegans [2], " \
34
- "C. tropicalis, D. melanogaster, Drosophila melanogaster, D.melanogaster"
35
- species = self.ntt_extractor.extract_species_regex(text=text,
36
- taxon_id_name_map=self.db_manager.get_taxon_id_names_map(),
37
- blacklist=["4853"],
38
- whitelist=["Homo sapiens"],
39
- min_matches=2)
40
- self.assertTrue(len(species) == 2 and
41
- "Caenorhabditis elegans" in species and
42
- "Drosophila melanogaster" in species)
43
-
44
-
45
- if __name__ == '__main__':
46
- unittest.main()
@@ -1,44 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_db_config
5
- from wbtools.db.generic import WBGenericDBManager
6
- from wbtools.lib.nlp.common import EntityType
7
- from wbtools.lib.nlp.entity_extraction.ntt_extractor import NttExtractor
8
- from wbtools.lib.nlp.entity_extraction.variations import is_variation_suspicious
9
-
10
-
11
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "data",
12
- "local_config", "db.cfg")), "Test DB config file not present")
13
- class TestNLPNewVariations(unittest.TestCase):
14
-
15
- def setUp(self) -> None:
16
- self.text = " g2 is a new variant"
17
- config = read_db_config()
18
- db_manager = WBGenericDBManager(
19
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
20
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
21
- self.ntt_extractor = NttExtractor(db_manager=db_manager)
22
-
23
- def test_get_new_variations_from_text(self):
24
- variations = self.ntt_extractor.extract_all_entities_by_type(self.text, EntityType.VARIATION,
25
- match_curated=False,
26
- exclude_curated=True)
27
- self.assertGreater(len(variations), 0)
28
- text = "The result- ing ez72syb1455 animals show the exact same gfp expression pattern as that of the " \
29
- "parental ez72 strain and also display no mutant phenotype (Figures S2A–S2C), thereby supporting past " \
30
- "evidence [8] that the tra-1b isoform bears no relevant Tra function."
31
- variations = self.ntt_extractor.extract_all_entities_by_type(text, EntityType.VARIATION, match_curated=False,
32
- exclude_curated=True)
33
- self.assertTrue("ez72syb1455" in variations)
34
-
35
- def test_is_variation_suspicious(self):
36
- variations = self.ntt_extractor.extract_all_entities_by_type(self.text, EntityType.VARIATION,
37
- match_curated=False,
38
- exclude_curated=True)
39
- is_susp = is_variation_suspicious(variations[0])
40
- self.assertEqual(is_susp, "potentially new")
41
-
42
-
43
- if __name__ == '__main__':
44
- unittest.main()
@@ -1,29 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_tpc_config
5
- from wbtools.lib.nlp.literature_index.textpresso import TextpressoLiteratureIndex
6
-
7
-
8
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
9
- "local_config", "textpresso.cfg")),
10
- "Textpresso test config file not present")
11
- class TestTextpressoLiteratureIndex(unittest.TestCase):
12
-
13
- def setUp(self) -> None:
14
- config = read_tpc_config()
15
- self.lit_index = TextpressoLiteratureIndex(api_url=config["tpc"]["api_base_url"],
16
- api_token=config["tpc"]["api_token"], use_cache=True,
17
- corpora=[config["tpc"]["corpora"]])
18
-
19
- def test_num_documents(self):
20
- self.assertGreater(self.lit_index.num_documents(), 0)
21
- self.assertGreater(self.lit_index.num_documents(), 0)
22
-
23
- def test_count_matching_documents(self):
24
- count = self.lit_index.count_matching_documents("DREAM complex")
25
- self.assertGreater(count, 0)
26
-
27
-
28
- if __name__ == '__main__':
29
- unittest.main()
@@ -1,18 +0,0 @@
1
- import unittest
2
-
3
- from wbtools.lib.scraping import get_cgc_allele_designations, get_cgc_lab_designations
4
-
5
-
6
- class TestScraping(unittest.TestCase):
7
-
8
- def test_get_cgc_allele_designations(self):
9
- cgc_designations = get_cgc_allele_designations()
10
- self.assertTrue(len(cgc_designations) > 0)
11
-
12
- def test_get_cgc_lab_designations(self):
13
- cgc_lab_designations = get_cgc_lab_designations()
14
- self.assertTrue(len(cgc_lab_designations) > 0)
15
-
16
-
17
- if __name__ == '__main__':
18
- unittest.main()
@@ -1,59 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_db_config, load_env_file
5
- from wbtools.lib.nlp.common import PaperSections
6
- from wbtools.lib.nlp.text_preprocessing import remove_sections_from_text, get_documents_from_text, preprocess
7
- from wbtools.literature.corpus import CorpusManager
8
-
9
- TESTDATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
10
-
11
-
12
- class TestTextPreprocessing(unittest.TestCase):
13
-
14
- def setUp(self):
15
- config = read_db_config()
16
- load_env_file()
17
- self.cm = CorpusManager()
18
- self.cm.load_from_wb_database(db_name=config["wb_database"]["db_name"],
19
- db_user=config["wb_database"]["db_user"],
20
- db_password=config["wb_database"]["db_password"],
21
- db_host=config["wb_database"]["db_host"],
22
- paper_ids=['00062455'])
23
-
24
- def test_sectioning(self):
25
- text = list(self.cm.corpus.values())[0].get_text_docs()[0]
26
- self.assertTrue("REFERENCES" not in remove_sections_from_text(
27
- text=text, sections_to_remove=[PaperSections.INTRODUCTION, PaperSections.REFERENCES],
28
- must_be_present=[PaperSections.RESULTS]))
29
-
30
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
31
- "local_config", "db.cfg")), "Test DB config file not present")
32
- def test_sectioning_cell_template(self):
33
- config = read_db_config()
34
- load_env_file()
35
- cm = CorpusManager()
36
- cm.load_from_wb_database(db_name=config["wb_database"]["db_name"], db_user=config["wb_database"]["db_user"],
37
- db_password=config["wb_database"]["db_password"],
38
- db_host=config["wb_database"]["db_host"],
39
- paper_ids=['00059375'])
40
- fulltext = cm.get_paper('00059375').get_text_docs(remove_sections=[PaperSections.REFERENCES],
41
- must_be_present=[PaperSections.METHOD, PaperSections.RESULTS])
42
- self.assertTrue(fulltext)
43
-
44
- def test_get_documents_from_text(self):
45
- docs = get_documents_from_text(list(self.cm.corpus.values())[0].main_text)
46
- self.assertEqual(len(docs), 1)
47
- docs = get_documents_from_text(list(self.cm.corpus.values())[0].main_text, split_sentences=True)
48
- self.assertGreater(len(docs), 10)
49
-
50
- def test_preprocess(self):
51
- doc = get_documents_from_text(list(self.cm.corpus.values())[0].main_text)[0]
52
- prep_text = preprocess(doc, lower=True, tokenize=True, remove_alpha=True, remove_stopwords=True)
53
- self.assertGreater(len(prep_text), 10)
54
- self.assertTrue(all([k == k.lower() for k in prep_text]))
55
- self.assertTrue("the" not in prep_text)
56
-
57
-
58
- if __name__ == '__main__':
59
- unittest.main()
@@ -1,52 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from gensim.models import Word2Vec
5
- from gensim.test.utils import common_texts
6
-
7
- from tests.config_reader import read_db_config, load_env_file
8
- from wbtools.lib.nlp.common import PaperSections
9
- from wbtools.lib.nlp.text_similarity import get_softcosine_index, get_similar_documents
10
- from wbtools.literature.corpus import CorpusManager
11
-
12
- TESTDATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
13
-
14
-
15
- class TestTextSimilarity(unittest.TestCase):
16
-
17
- def setUp(self) -> None:
18
- config = read_db_config()
19
- load_env_file()
20
- self.cm = CorpusManager()
21
- self.cm.load_from_wb_database(db_name=config["wb_database"]["db_name"],
22
- db_user=config["wb_database"]["db_user"],
23
- db_password=config["wb_database"]["db_password"],
24
- db_host=config["wb_database"]["db_host"],
25
- paper_ids=['00026804', '00026805', '00026806', '00026807', '00026808',
26
- '00026809', '00026810', '00026811', '00026812', '00026813',
27
- '00026814', '00026815', '00026816', '00026817', '00026818',
28
- '00026819', '00026820', '00026821', '00026822', '00026823'])
29
-
30
- def test_soft_cosine_similarity(self):
31
- corpus_list_token, idx_paperid_map = self.cm.get_flat_corpus_list_and_idx_paperid_map(
32
- split_sentences=False, remove_sections=[PaperSections.REFERENCES], lowercase=True, tokenize=True,
33
- remove_stopwords=True, remove_alpha=True)
34
- model = Word2Vec(common_texts, min_count=1)
35
- docsim_index, dictionary = get_softcosine_index(model=model, corpus_list_token=corpus_list_token)
36
- query_docs = [corpus_list_token[0], corpus_list_token[1]]
37
- sim_docs = get_similar_documents(docsim_index, dictionary, query_docs, idx_paperid_map)
38
- self.assertTrue(idx_paperid_map[0] in [sim_doc.paper_id for sim_doc in sim_docs[0:2]])
39
- self.assertTrue(idx_paperid_map[1] in [sim_doc.paper_id for sim_doc in sim_docs[0:2]])
40
-
41
- corpus_list_token, idx_paperid_map = self.cm.get_flat_corpus_list_and_idx_paperid_map(
42
- split_sentences=True, remove_sections=[PaperSections.REFERENCES], lowercase=True, tokenize=True,
43
- remove_stopwords=True, remove_alpha=True)
44
- docsim_index, dictionary = get_softcosine_index(model=model, corpus_list_token=corpus_list_token)
45
- query_docs = [corpus_list_token[0], corpus_list_token[1]]
46
- sim_docs = get_similar_documents(docsim_index, dictionary, query_docs, idx_paperid_map)
47
- self.assertTrue(idx_paperid_map[0] in [sim_doc.paper_id for sim_doc in sim_docs[0:2]])
48
- self.assertTrue(idx_paperid_map[1] in [sim_doc.paper_id for sim_doc in sim_docs[0:2]])
49
-
50
-
51
- if __name__ == '__main__':
52
- unittest.main()
@@ -1,86 +0,0 @@
1
- import os
2
- import unittest
3
- import tempfile
4
-
5
- from tests.config_reader import read_db_config, load_env_file
6
- from wbtools.lib.nlp.common import PaperSections
7
- from wbtools.literature.corpus import CorpusManager
8
- from wbtools.literature.paper import WBPaper
9
-
10
- TESTDATA_DIR = os.path.join(os.path.dirname(__file__), '../data', 'text_files')
11
-
12
-
13
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
14
- "local_config", "db.cfg")), "Test DB config file not present")
15
- class TestCorpusManager(unittest.TestCase):
16
-
17
- def setUp(self) -> None:
18
- config = read_db_config()
19
- load_env_file()
20
- self.cm = CorpusManager()
21
- self.cm.load_from_wb_database(db_host=config["wb_database"]["db_host"],
22
- db_user=config["wb_database"]["db_user"],
23
- db_password=config["wb_database"]["db_password"],
24
- db_name=config["wb_database"]["db_name"], max_num_papers=2)
25
-
26
- def test_get_flat_corpus_list_and_idx_paperid_map(self):
27
- flat_list, idx_paperid_map = self.cm.get_flat_corpus_list_and_idx_paperid_map(
28
- tokenize=True, remove_stopwords=True, remove_alpha=True)
29
- self.assertEqual(len(flat_list), len(idx_paperid_map))
30
- self.assertTrue(len(idx_paperid_map[0]) == 8)
31
- self.assertEqual(len(set(idx_paperid_map.values())), self.cm.size())
32
-
33
- def test_split_sentences(self):
34
- cl1, map1 = self.cm.get_flat_corpus_list_and_idx_paperid_map(tokenize=False, remove_stopwords=False,
35
- remove_alpha=False, split_sentences=True)
36
- cl2, map2 = self.cm.get_flat_corpus_list_and_idx_paperid_map(tokenize=True, remove_stopwords=True,
37
- remove_alpha=True, split_sentences=True)
38
- self.assertEqual(len(cl1), len(cl2))
39
-
40
- def test_exclude_sections(self):
41
- test_list, _ = self.cm.get_flat_corpus_list_and_idx_paperid_map(
42
- split_sentences=False, remove_sections=[PaperSections.INTRODUCTION, PaperSections.REFERENCES],
43
- must_be_present=[PaperSections.RESULTS], lowercase=False, tokenize=False, remove_stopwords=False,
44
- remove_alpha=False)
45
- pass
46
-
47
- def test_load_from_wb_database(self):
48
- db_config = read_db_config()
49
- cm = CorpusManager()
50
- cm.load_from_wb_database(db_name=db_config["wb_database"]["db_name"], db_user=db_config["wb_database"]["db_user"],
51
- db_password=db_config["wb_database"]["db_password"],
52
- db_host=db_config["wb_database"]["db_host"], max_num_papers=2)
53
- self.assertTrue(cm.size() == 2)
54
- cm = CorpusManager()
55
- cm.load_from_wb_database(db_name=db_config["wb_database"]["db_name"],
56
- db_user=db_config["wb_database"]["db_user"],
57
- db_password=db_config["wb_database"]["db_password"],
58
- db_host=db_config["wb_database"]["db_host"], max_num_papers=2,
59
- exclude_temp_pdf=True)
60
- self.assertFalse(any([paper.is_temp() for paper in cm.get_all_papers()]))
61
-
62
- def test_load_supplemental(self):
63
- db_config = read_db_config()
64
- cm = CorpusManager()
65
- cm.load_from_wb_database(db_name=db_config["wb_database"]["db_name"],
66
- db_user=db_config["wb_database"]["db_user"],
67
- db_password=db_config["wb_database"]["db_password"],
68
- db_host=db_config["wb_database"]["db_host"],
69
- paper_ids=["00062512"])
70
- self.assertTrue(len(cm.get_paper("00062512").supplemental_docs) > 0)
71
-
72
- # def test_load_from_wb_database_afp(self):
73
- # db_config = read_db_config()
74
- # cm = CorpusManager()
75
- # cm.load_from_wb_database(db_name=db_config["wb_database"]["db_name"],
76
- # db_user=db_config["wb_database"]["db_user"],
77
- # db_password=db_config["wb_database"]["db_password"],
78
- # db_host=db_config["wb_database"]["db_host"],
79
- # max_num_papers=2,
80
- # load_curation_info=True, load_afp_info=True,
81
- # exclude_temp_pdf=True, exclude_afp_processed=True, must_be_autclass_flagged=True)
82
- # self.assertFalse(any([paper.afp_processed for paper in cm.get_all_papers()]))
83
-
84
-
85
- if __name__ == '__main__':
86
- unittest.main()
@@ -1,110 +0,0 @@
1
- import os
2
- import unittest
3
-
4
- from tests.config_reader import read_db_config, load_env_file
5
- from wbtools.db.paper import WBPaperDBManager
6
- from wbtools.lib.nlp.common import PaperSections
7
- from wbtools.literature.corpus import CorpusManager
8
- from wbtools.literature.paper import WBPaper
9
-
10
- TESTDATA_DIR = os.path.join(os.path.dirname(__file__), '../data', 'text_files')
11
-
12
-
13
- class TestWBPaper(unittest.TestCase):
14
-
15
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
16
- "local_config", "db.cfg")), "Test DB config file not present")
17
- def test_load_curation_info_from_db(self):
18
- config = read_db_config()
19
- load_env_file()
20
- paper = WBPaper(paper_id="00004161", db_manager=WBPaperDBManager(
21
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
22
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"]))
23
- paper.paper_id = "00004161"
24
- paper.agr_curie = paper.db_manager.get_paper_curie(paper.paper_id)
25
- paper.load_curation_info_from_db()
26
- self.assertTrue(paper.aut_class_values["seqchange"] == 'high')
27
-
28
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
29
- "local_config", "db.cfg")), "Test DB config file not present")
30
- def test_load_bib_info(self):
31
- config = read_db_config()
32
- db_manager = WBPaperDBManager(
33
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
34
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
35
- paper = WBPaper(paper_id="00004161", db_manager=db_manager)
36
- paper.agr_curie = paper.db_manager.get_paper_curie(paper.paper_id)
37
- with db_manager:
38
- paper.load_bib_info()
39
- self.assertGreater(len(paper.authors), 0)
40
- self.assertTrue(paper.abstract.startswith("Niemann-Pick type C (NP-C) disease is a progressive"))
41
-
42
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
43
- "local_config", "db.cfg")), "Test DB config file not present")
44
- def test_extract_all_email_addresses_from_text(self):
45
- config = read_db_config()
46
- load_env_file()
47
- cm = CorpusManager()
48
- cm.load_from_wb_database(db_host=config["wb_database"]["db_host"],
49
- db_user=config["wb_database"]["db_user"],
50
- db_password=config["wb_database"]["db_password"],
51
- db_name=config["wb_database"]["db_name"], paper_ids=['00026804'])
52
- addresses = cm.get_paper('00026804').extract_all_email_addresses_from_text()
53
- self.assertGreater(len(addresses), 0)
54
-
55
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
56
- "local_config", "db.cfg")), "Test DB config file not present")
57
- def test_pdf2txt_conversion(self):
58
- config = read_db_config()
59
- load_env_file()
60
- db_manager = WBPaperDBManager(
61
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
62
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
63
- paper = WBPaper(paper_id="00003969", db_manager=db_manager)
64
- paper.load_bib_info()
65
- paper.load_text_from_pdf_files()
66
- fulltext = paper.get_text_docs()
67
- self.assertGreater(len(fulltext), 0)
68
- self.assertTrue("u253, u423 deletion in exon 3" in fulltext[0])
69
-
70
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
71
- "local_config", "db.cfg")), "Test DB config file not present")
72
- def test_pdf_table_conversion(self):
73
- config = read_db_config()
74
- load_env_file()
75
- db_manager = WBPaperDBManager(
76
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
77
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
78
- paper = WBPaper(paper_id="00059755", db_manager=db_manager)
79
- paper.agr_curie = paper.db_manager.get_paper_curie(paper.paper_id)
80
- paper.load_text_from_pdf_files()
81
- fulltext = paper.get_text_docs()
82
- self.assertTrue(fulltext)
83
-
84
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
85
- "local_config", "db.cfg")), "Test DB config file not present")
86
- def test_tokenize_sentences_with_tables(self):
87
- config = read_db_config()
88
- load_env_file()
89
- db_manager = WBPaperDBManager(
90
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
91
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
92
- paper = WBPaper(paper_id="00003969", db_manager=db_manager)
93
- paper.agr_curie = paper.db_manager.get_paper_curie(paper.paper_id)
94
- paper.load_text_from_pdf_files()
95
- sentences = paper.get_text_docs(split_sentences=True)
96
- self.assertGreater(len(sentences), 0)
97
-
98
- @unittest.skipIf(not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data",
99
- "local_config", "db.cfg")), "Test DB config file not present")
100
- def test_two_cols_conversion(self):
101
- config = read_db_config()
102
- load_env_file()
103
- db_manager = WBPaperDBManager(
104
- dbname=config["wb_database"]["db_name"], user=config["wb_database"]["db_user"],
105
- password=config["wb_database"]["db_password"], host=config["wb_database"]["db_host"])
106
- paper = WBPaper(paper_id="00055367", db_manager=db_manager)
107
- paper.agr_curie = paper.db_manager.get_paper_curie(paper.paper_id)
108
- paper.load_text_from_pdf_files()
109
- fulltext = paper.get_text_docs()
110
- self.assertTrue(fulltext)
File without changes
File without changes
File without changes
@@ -1,67 +0,0 @@
1
- import os
2
- from json import loads
3
- from os import environ, path
4
- import logging
5
- import logging.config
6
- from datetime import datetime
7
- from dateutil.relativedelta import relativedelta
8
- import requests
9
-
10
-
11
- def generate_headers(token):
12
- """
13
-
14
- :param token:
15
- :return:
16
- """
17
-
18
- authorization = 'Bearer ' + token
19
- headers = {
20
- 'Authorization': authorization,
21
- 'Content-Type': 'application/json',
22
- 'Accept': 'application/json'
23
- }
24
- return headers
25
-
26
-
27
- def update_okta_token(): # pragma: no cover
28
- """
29
-
30
- :return:
31
- """
32
-
33
- url = f"https://{os.environ.get('OKTA_DOMAIN')}/v1/token"
34
- headers = {
35
- 'Content-Type': 'application/x-www-form-urlencoded',
36
- 'Accept': 'application/json'
37
- }
38
- data_dict = dict()
39
- data_dict['grant_type'] = 'client_credentials'
40
- data_dict['client_id'] = environ.get('OKTA_CLIENT_ID')
41
- data_dict['client_secret'] = environ.get('OKTA_CLIENT_SECRET')
42
- data_dict['scope'] = 'admin'
43
- post_return = requests.post(url, headers=headers, data=data_dict)
44
- logging.warning(post_return.text)
45
- response_dict = loads(post_return.text)
46
- token = response_dict['access_token']
47
- okta_file = environ.get('TMP_PATH') + 'okta_token'
48
- os.makedirs(environ.get('TMP_PATH'), exist_ok=True)
49
- with open(okta_file, 'w') as okta_fh:
50
- okta_fh.write("%s" % token)
51
- return token
52
-
53
-
54
- def get_authentication_token(): # pragma: no cover
55
- okta_file = environ.get('TMP_PATH') + 'okta_token'
56
- token = ''
57
- if path.isfile(okta_file):
58
- one_day_ago = datetime.now() - relativedelta(days=1)
59
- file_time = datetime.fromtimestamp(path.getmtime(okta_file))
60
- if file_time > one_day_ago:
61
- with open(okta_file, 'r') as okta_fh:
62
- token = okta_fh.read().replace("\n", "")
63
- else:
64
- token = update_okta_token()
65
- else:
66
- token = update_okta_token()
67
- return token
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes