From 094fe418fd374e69166b14630b63c4ca9b2bd3d8 Mon Sep 17 00:00:00 2001 From: dschiese Date: Mon, 1 Apr 2024 16:31:40 +0200 Subject: [PATCH 1/6] Splitted Insert-Queries --- .../component/mt_helsinki_nlp.py | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/qanary-component-MT-Python-HelsinkiNLP/component/mt_helsinki_nlp.py b/qanary-component-MT-Python-HelsinkiNLP/component/mt_helsinki_nlp.py index b83a578b..16e379b0 100644 --- a/qanary-component-MT-Python-HelsinkiNLP/component/mt_helsinki_nlp.py +++ b/qanary-component-MT-Python-HelsinkiNLP/component/mt_helsinki_nlp.py @@ -57,7 +57,7 @@ def qanary_service(): result = tokenizers[lang].batch_decode(translation, skip_special_tokens=True)[0] # building SPARQL query TODO: verify this annotation AnnotationOfQuestionTranslation ?? - SPARQLquery = """ + SPARQLqueryAnnotationOfQuestionTranslation = """ PREFIX qa: PREFIX oa: PREFIX xsd: @@ -70,6 +70,27 @@ def qanary_service(): oa:annotatedBy ; oa:annotatedAt ?time . + }} + }} + WHERE {{ + BIND (IRI(str(RAND())) AS ?a) . + BIND (now() as ?time) + }} + """.format( + uuid=triplestore_ingraph, + qanary_question_uri=question_uri, + translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation + target_lang=TARGET_LANG, + app_name=SERVICE_NAME_COMPONENT + ) + + SPARQLqueryAnnotationOfQuestionLanguage = """ + PREFIX qa: + PREFIX oa: + PREFIX xsd: + + INSERT {{ + GRAPH <{uuid}> {{ ?b a qa:AnnotationOfQuestionLanguage ; oa:hasTarget <{qanary_question_uri}> ; oa:hasBody "{src_lang}"^^xsd:string ; @@ -78,22 +99,21 @@ def qanary_service(): }} }} WHERE {{ - BIND (IRI(str(RAND())) AS ?a) . BIND (IRI(str(RAND())) AS ?b) . BIND (now() as ?time) }} """.format( uuid=triplestore_ingraph, qanary_question_uri=question_uri, - translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation src_lang=lang, - target_lang=TARGET_LANG, app_name=SERVICE_NAME_COMPONENT ) - logging.info(f'SPARQL: {SPARQLquery}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionTranslation}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionLanguage}') # inserting new data to the triplestore - insert_into_triplestore(triplestore_endpoint, SPARQLquery) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionTranslation) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionLanguage) return jsonify(request.get_json()) From 4b46c3aa216b93c4f0abb6cf76fd03a012431ff1 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Mon, 1 Apr 2024 19:48:10 +0200 Subject: [PATCH 2/6] Adjusted missing three components --- .../component/mt_libretranslate.py | 41 +++++++-- .../component/mt_mbart_nlp.py | 32 +++++-- .../component/mt_nllb.py | 92 +++++++++++-------- 3 files changed, 114 insertions(+), 51 deletions(-) diff --git a/qanary-component-MT-Python-LibreTranslate/component/mt_libretranslate.py b/qanary-component-MT-Python-LibreTranslate/component/mt_libretranslate.py index fb4fe683..7f888dcf 100644 --- a/qanary-component-MT-Python-LibreTranslate/component/mt_libretranslate.py +++ b/qanary-component-MT-Python-LibreTranslate/component/mt_libretranslate.py @@ -43,17 +43,40 @@ def qanary_service(): result, _ = translate_input(text, lang) # building SPARQL query TODO: verify this annotation AnnotationOfQuestionTranslation ?? - SPARQLquery = """ + SPARQLqueryAnnotationOfQuestionTranslation = """ PREFIX qa: PREFIX oa: PREFIX xsd: + INSERT {{ GRAPH <{uuid}> {{ ?a a qa:AnnotationOfQuestionTranslation ; - oa:hasTarget <{qanary_question_uri}> ; - oa:hasBody "{translation_result}"@en ; + oa:hasTarget <{qanary_question_uri}> ; + oa:hasBody "{translation_result}"@{target_lang} ; oa:annotatedBy ; oa:annotatedAt ?time . + + }} + }} + WHERE {{ + BIND (IRI(str(RAND())) AS ?a) . + BIND (now() as ?time) + }} + """.format( + uuid=triplestore_ingraph, + qanary_question_uri=question_uri, + translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation + target_lang=TARGET_LANG, + app_name=SERVICE_NAME_COMPONENT + ) + + SPARQLqueryAnnotationOfQuestionLanguage = """ + PREFIX qa: + PREFIX oa: + PREFIX xsd: + + INSERT {{ + GRAPH <{uuid}> {{ ?b a qa:AnnotationOfQuestionLanguage ; oa:hasTarget <{qanary_question_uri}> ; oa:hasBody "{src_lang}"^^xsd:string ; @@ -62,21 +85,21 @@ def qanary_service(): }} }} WHERE {{ - BIND (IRI(str(RAND())) AS ?a) . BIND (IRI(str(RAND())) AS ?b) . - BIND (now() as ?time) + BIND (now() as ?time) }} """.format( uuid=triplestore_ingraph, qanary_question_uri=question_uri, - translation_result=result, src_lang=lang, app_name=SERVICE_NAME_COMPONENT ) - - logging.info(f'SPARQL: {SPARQLquery}') + + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionTranslation}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionLanguage}') # inserting new data to the triplestore - insert_into_triplestore(triplestore_endpoint, SPARQLquery) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionTranslation) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionLanguage) return jsonify(request.get_json()) diff --git a/qanary-component-MT-Python-MBart/component/mt_mbart_nlp.py b/qanary-component-MT-Python-MBart/component/mt_mbart_nlp.py index 705d473b..9e4ad552 100644 --- a/qanary-component-MT-Python-MBart/component/mt_mbart_nlp.py +++ b/qanary-component-MT-Python-MBart/component/mt_mbart_nlp.py @@ -72,7 +72,7 @@ def qanary_service(): # building SPARQL query TODO: verify this annotation AnnotationOfQuestionTranslation ?? - SPARQLquery = """ + SPARQLqueryAnnotationOfQuestionTranslation = """ PREFIX qa: PREFIX oa: PREFIX xsd: @@ -85,6 +85,27 @@ def qanary_service(): oa:annotatedBy ; oa:annotatedAt ?time . + }} + }} + WHERE {{ + BIND (IRI(str(RAND())) AS ?a) . + BIND (now() as ?time) + }} + """.format( + uuid=triplestore_ingraph, + qanary_question_uri=question_uri, + translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation + target_lang=TARGET_LANG, + app_name=SERVICE_NAME_COMPONENT + ) + + SPARQLqueryAnnotationOfQuestionLanguage = """ + PREFIX qa: + PREFIX oa: + PREFIX xsd: + + INSERT {{ + GRAPH <{uuid}> {{ ?b a qa:AnnotationOfQuestionLanguage ; oa:hasTarget <{qanary_question_uri}> ; oa:hasBody "{src_lang}"^^xsd:string ; @@ -93,22 +114,21 @@ def qanary_service(): }} }} WHERE {{ - BIND (IRI(str(RAND())) AS ?a) . BIND (IRI(str(RAND())) AS ?b) . BIND (now() as ?time) }} """.format( uuid=triplestore_ingraph, qanary_question_uri=question_uri, - translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation src_lang=lang, - target_lang=target_lang, app_name=SERVICE_NAME_COMPONENT ) - logging.info(f'SPARQL: {SPARQLquery}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionTranslation}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionLanguage}') # inserting new data to the triplestore - insert_into_triplestore(triplestore_endpoint, SPARQLquery) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionTranslation) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionLanguage) return jsonify(request.get_json()) diff --git a/qanary-component-MT-Python-NLLB/component/mt_nllb.py b/qanary-component-MT-Python-NLLB/component/mt_nllb.py index beffd6f9..a5204329 100644 --- a/qanary-component-MT-Python-NLLB/component/mt_nllb.py +++ b/qanary-component-MT-Python-NLLB/component/mt_nllb.py @@ -70,43 +70,63 @@ def qanary_service(): # building SPARQL query TODO: verify this annotation AnnotationOfQuestionTranslation ?? - SPARQLquery = """ - PREFIX qa: - PREFIX oa: - PREFIX xsd: - - INSERT {{ - GRAPH <{uuid}> {{ - ?a a qa:AnnotationOfQuestionTranslation ; - oa:hasTarget <{qanary_question_uri}> ; - oa:hasBody "{translation_result}"@{target_lang} ; - oa:annotatedBy ; - oa:annotatedAt ?time . - - ?b a qa:AnnotationOfQuestionLanguage ; - oa:hasTarget <{qanary_question_uri}> ; - oa:hasBody "{src_lang}"^^xsd:string ; - oa:annotatedBy ; - oa:annotatedAt ?time . + SPARQLqueryAnnotationOfQuestionTranslation = """ + PREFIX qa: + PREFIX oa: + PREFIX xsd: + + INSERT {{ + GRAPH <{uuid}> {{ + ?a a qa:AnnotationOfQuestionTranslation ; + oa:hasTarget <{qanary_question_uri}> ; + oa:hasBody "{translation_result}"@{target_lang} ; + oa:annotatedBy ; + oa:annotatedAt ?time . + + }} }} - }} - WHERE {{ - BIND (IRI(str(RAND())) AS ?a) . - BIND (IRI(str(RAND())) AS ?b) . - BIND (now() as ?time) - }} - """.format( - uuid=triplestore_ingraph, - qanary_question_uri=question_uri, - translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation - src_lang=lang, - target_lang=target_lang, - app_name=SERVICE_NAME_COMPONENT - ) - - logging.info(f'SPARQL: {SPARQLquery}') - # inserting new data to the triplestore - insert_into_triplestore(triplestore_endpoint, SPARQLquery) + WHERE {{ + BIND (IRI(str(RAND())) AS ?a) . + BIND (now() as ?time) + }} + """.format( + uuid=triplestore_ingraph, + qanary_question_uri=question_uri, + translation_result=result.replace("\"", "\\\""), #keep quotation marks that are part of the translation + target_lang=TARGET_LANG, + app_name=SERVICE_NAME_COMPONENT + ) + + SPARQLqueryAnnotationOfQuestionLanguage = """ + PREFIX qa: + PREFIX oa: + PREFIX xsd: + + INSERT {{ + GRAPH <{uuid}> {{ + ?b a qa:AnnotationOfQuestionLanguage ; + oa:hasTarget <{qanary_question_uri}> ; + oa:hasBody "{src_lang}"^^xsd:string ; + oa:annotatedBy ; + oa:annotatedAt ?time . + }} + }} + WHERE {{ + BIND (IRI(str(RAND())) AS ?b) . + BIND (now() as ?time) + }} + """.format( + uuid=triplestore_ingraph, + qanary_question_uri=question_uri, + src_lang=lang, + app_name=SERVICE_NAME_COMPONENT + ) + + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionTranslation}') + logging.info(f'SPARQL: {SPARQLqueryAnnotationOfQuestionLanguage}') + # inserting new data to the triplestore + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionTranslation) + insert_into_triplestore(triplestore_endpoint, SPARQLqueryAnnotationOfQuestionLanguage) return jsonify(request.get_json()) From 2a6d13fcfc0400a1394b1105d9257c5f395695a7 Mon Sep 17 00:00:00 2001 From: Dennis Schiese <135758800+dschiese@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:38:55 +0200 Subject: [PATCH 3/6] Update __init__.py v0.1.1 -> v0.1.2 - Bugfix Insert-Query --- qanary-component-MT-Python-HelsinkiNLP/component/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qanary-component-MT-Python-HelsinkiNLP/component/__init__.py b/qanary-component-MT-Python-HelsinkiNLP/component/__init__.py index 45d776ae..75d0e380 100644 --- a/qanary-component-MT-Python-HelsinkiNLP/component/__init__.py +++ b/qanary-component-MT-Python-HelsinkiNLP/component/__init__.py @@ -1,7 +1,7 @@ from component.mt_helsinki_nlp import mt_helsinki_nlp_bp from flask import Flask -version = "0.1.1" +version = "0.1.2" # default config file (use -c parameter on command line specify a custom config file) configfile = "app.conf" From 4dac0754162bbac528397a6f52069eef04838177 Mon Sep 17 00:00:00 2001 From: Dennis Schiese <135758800+dschiese@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:39:11 +0200 Subject: [PATCH 4/6] Update __init__.py v0.1.1 -> v0.1.2 - Bugfix Insert-Query --- qanary-component-MT-Python-LibreTranslate/component/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qanary-component-MT-Python-LibreTranslate/component/__init__.py b/qanary-component-MT-Python-LibreTranslate/component/__init__.py index 1618bb65..1de4ddf5 100644 --- a/qanary-component-MT-Python-LibreTranslate/component/__init__.py +++ b/qanary-component-MT-Python-LibreTranslate/component/__init__.py @@ -3,7 +3,7 @@ from component.mt_libretranslate import get_languages from flask import Flask -version = "0.1.1" +version = "0.1.2" # default config file configfile = "app.conf" From 6aada89365489d3877aaebe9717232f638994d95 Mon Sep 17 00:00:00 2001 From: Dennis Schiese <135758800+dschiese@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:39:23 +0200 Subject: [PATCH 5/6] Update __init__.py v0.1.1 -> v0.1.2 - Bugfix Insert-Query --- qanary-component-MT-Python-MBart/component/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qanary-component-MT-Python-MBart/component/__init__.py b/qanary-component-MT-Python-MBart/component/__init__.py index 08b49033..40da0f2f 100644 --- a/qanary-component-MT-Python-MBart/component/__init__.py +++ b/qanary-component-MT-Python-MBart/component/__init__.py @@ -1,7 +1,7 @@ from component.mt_mbart_nlp import mt_mbart_nlp_bp from flask import Flask -version = "0.1.1" +version = "0.1.2" # default config file configfile = "app.conf" From 5e79455e52db1aa49985988369a1be532ba5dfcf Mon Sep 17 00:00:00 2001 From: Dennis Schiese <135758800+dschiese@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:39:38 +0200 Subject: [PATCH 6/6] Update __init__.py v0.1.1 -> v0.1.2 - Bugfix Insert-Query --- qanary-component-MT-Python-NLLB/component/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qanary-component-MT-Python-NLLB/component/__init__.py b/qanary-component-MT-Python-NLLB/component/__init__.py index 395798dd..70ec854c 100644 --- a/qanary-component-MT-Python-NLLB/component/__init__.py +++ b/qanary-component-MT-Python-NLLB/component/__init__.py @@ -1,7 +1,7 @@ from component.mt_nllb import mt_nllb_bp from flask import Flask -version = "0.1.1" +version = "0.1.2" # default config file configfile = "app.conf"