Skip to content

Commit

Permalink
Annotation manager fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Jan 22, 2024
1 parent 1820db2 commit 2aa88a5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions nifi/user-scripts/annotation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
global LOG_FILE_NAME
global OPERATION_MODE

ANNOTATION_DB_SQL_FILE_PATH = "/opt/data/cogstack-db/sqlite/schemas/annotations_nlp_create_schema.sql"
ANNOTATION_DB_SQL_FILE_PATH = "/opt/cogstack-db/sqlite/schemas/annotations_nlp_create_schema.sql"

# default values from /deploy/nifi.env
USER_SCRIPT_DB_DIR = os.getenv("USER_SCRIPT_DB_DIR")
Expand All @@ -35,9 +35,12 @@
elif _arg[0] == "operation_mode":
OPERATION_MODE = _arg[1]

global output_stream

output_stream = {}

def main():
input_stream = sys.stdin.read()
output_stream = {}

try:
log_file_path = os.path.join(USER_SCRIPT_LOGS_DIR, str(LOG_FILE_NAME))
Expand All @@ -49,15 +52,16 @@ def main():
create_db_from_file(ANNOTATION_DB_SQL_FILE_PATH, db_file_path)

if OPERATION_MODE == "check":
document_id = str(json_data_record["content"][0]["id"])
query = "SELECT * FROM annotations WHERE elasticsearch_id LIKE (" + document_id + "_" + ")"
document_id = str(json_data_record["id"])
query = "SELECT * FROM annotations WHERE elasticsearch_id LIKE (" + document_id + ")"
result = connect_and_query(query, db_file_path)

output_stream = input_stream
if len(result) > 1:
output_stream = len(result)
else:
output_stream = json_data_record

elif OPERATION_MODE == "insert":
query = "INSERT INTO annotations (elasticsearch_id) VALUES (" + '"' + str(json_data_record["meta.docid"]) + "_" + str(json_data_record["nlp.id"]) + '"' +")"
result = connect_and_query(query, db_file_path, sql_script_mode=True)
Expand Down

0 comments on commit 2aa88a5

Please sign in to comment.