Coverage for nlprp/constants.py: 100%

64 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-08-27 10:34 -0500

1r""" 

2crate_anon/nlprp/constants.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CRATE. 

10 

11 CRATE is free software: you can redistribute it and/or modify 

12 it under the terms of the GNU General Public License as published by 

13 the Free Software Foundation, either version 3 of the License, or 

14 (at your option) any later version. 

15 

16 CRATE is distributed in the hope that it will be useful, 

17 but WITHOUT ANY WARRANTY; without even the implied warranty of 

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19 GNU General Public License for more details. 

20 

21 You should have received a copy of the GNU General Public License 

22 along with CRATE. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26Natural Language Processing Request Protocol (NLPRP) constants. 

27 

28""" 

29 

30from cardinal_pythonlib.sqlalchemy.dialect import SqlaDialectName 

31from semantic_version import Version 

32 

33 

34# ============================================================================= 

35# NLPRP strings 

36# ============================================================================= 

37 

38 

39class NlprpKeys: 

40 """ 

41 JSON dictionary keys used by the NLPRP. 

42 """ 

43 

44 ARGS = "args" # request 

45 CLIENT_JOB_ID = "client_job_id" # bidirectional 

46 CLIENT_JOB_IDS = "client_job_ids" # request 

47 CODE = "code" # response 

48 COLUMN_COMMENT = "column_comment" # response 

49 COLUMN_NAME = "column_name" # response 

50 COLUMN_TYPE = "column_type" # response 

51 COLUMNS = "columns" # response 

52 COMMAND = "command" # request 

53 CONTENT = "content" # request 

54 DATA_TYPE = "data_type" # response 

55 DATETIME_COMPLETED = "datetime_completed" # response 

56 DATETIME_SUBMITTED = "datetime_submitted" # response 

57 DELETE_ALL = "delete_all" # request 

58 DESCRIPTION = "description" # response 

59 ERRORS = "errors" # response 

60 INCLUDE_TEXT = "include_text" # request 

61 IS_DEFAULT_VERSION = "is_default_version" # response 

62 IS_NULLABLE = "is_nullable" # response 

63 MESSAGE = "message" # response 

64 METADATA = "metadata" # bidirectional 

65 NAME = "name" # bidirectional 

66 N_DOCPROCS = "n_docprocs" # response 

67 N_DOCPROCS_COMPLETED = "n_docprocs_completed" # response 

68 PROCESSORS = "processors" # bidirectional 

69 PROTOCOL = "protocol" # bidirectional 

70 QUEUE = "queue" # bidirectional 

71 QUEUE_ID = "queue_id" # response 

72 QUEUE_IDS = "queue_ids" # request 

73 RESULTS = "results" # response 

74 SCHEMA_TYPE = "schema_type" # response 

75 SERVER_INFO = "server_info" # response 

76 SQL_DIALECT = "sql_dialect" # response 

77 STATUS = "status" # response 

78 SUCCESS = "success" # response 

79 TABULAR_SCHEMA = "tabular_schema" # response 

80 TEXT = "text" # request 

81 TITLE = "title" # response 

82 VERSION = "version" # bidirectional 

83 

84 

85class NlprpValues: 

86 """ 

87 JSON dictionary values used by the NLPRP. 

88 """ 

89 

90 BUSY = "busy" 

91 NLPRP_PROTOCOL_NAME = "nlprp" 

92 READY = "ready" 

93 TABULAR = "tabular" # for schema_type 

94 UNKNOWN = "unknown" # for schema_type 

95 

96 

97class NlprpCommands: 

98 """ 

99 NLPRP commands. 

100 """ 

101 

102 LIST_PROCESSORS = "list_processors" 

103 PROCESS = "process" 

104 SHOW_QUEUE = "show_queue" 

105 FETCH_FROM_QUEUE = "fetch_from_queue" 

106 DELETE_FROM_QUEUE = "delete_from_queue" 

107 

108 

109ALL_NLPRP_COMMANDS = [ 

110 v for k, v in NlprpCommands.__dict__.items() if not k.startswith("_") 

111] 

112 

113 

114class SqlDialects: 

115 """ 

116 SQL dialects supported by the NLPRP. 

117 """ 

118 

119 MSSQL = SqlaDialectName.MSSQL 

120 MYSQL = SqlaDialectName.MYSQL 

121 ORACLE = SqlaDialectName.ORACLE 

122 POSTGRES = SqlaDialectName.POSTGRES 

123 SQLITE = SqlaDialectName.SQLITE 

124 

125 

126ALL_SQL_DIALECTS = [ 

127 v for k, v in SqlDialects.__dict__.items() if not k.startswith("_") 

128] 

129 

130 

131class NlprpVersions: 

132 """ 

133 NLPRP versions where something changed. 

134 """ 

135 

136 # The version from which fetch_from_queue returns 202 (Accepted) for "in 

137 # progress"/pending, rather than 102 (Processing): 

138 FETCH_Q_PENDING_RETURNS_202 = Version("0.3.0")