diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index d7d823b..d6ec005 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -1,3 +1,4 @@ from .table import compare_table from .table import check_sheet_list, check_xlsx_freeze, check_zoom from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, compare_insert_equation +from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers \ No newline at end of file diff --git a/desktop_env/evaluators/metrics/docs.py b/desktop_env/evaluators/metrics/docs.py index 2502b5e..bf57864 100644 --- a/desktop_env/evaluators/metrics/docs.py +++ b/desktop_env/evaluators/metrics/docs.py @@ -100,7 +100,7 @@ def compare_line_spacing(docx_file1, docx_file2): def compare_insert_equation(docx_file1, docx_file2): if not compare_docx_files(docx_file1, docx_file2): - return False + return 0 doc1 = Document(docx_file1) doc2 = Document(docx_file2) @@ -109,9 +109,42 @@ def compare_insert_equation(docx_file1, docx_file2): for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs): for run1, run2 in zip(para1.runs, para2.runs): if run1.element.xpath('.//w:object') and run2.element.xpath('.//w:object'): - return True - return False + return 1 + return 0 +def compare_font_names(expected_font, docx_file): + doc = Document(docx_file) + + for paragraph in doc.paragraphs: + for run in paragraph.runs: + font_name = run.font.name + if font_name != expected_font: + return 0 + return 1 + +def compare_subscript_contains(docx_file1, docx_file2): + doc1 = Document(docx_file1) + doc2 = Document(docx_file2) + + for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs): + for run1, run2 in zip(para1.runs, para2.runs): + # check if two paras both contain subscript + if run1.font.subscript and run2.font.subscript: + return 1 + return 0 + +def has_page_numbers_in_footers(docx_file): + doc = Document(docx_file) + + for section in doc.sections: + footer = section.footer + if footer is None: + return 0 + footer_text = footer.paragraphs[0].text if footer.paragraphs else '' + if not any(char.isdigit() for char in footer_text): + # if no digit in footer, then no page number + return 0 + return 1 # file1 = 'path/to/file1.docx' diff --git a/evaluation_examples/examples/libreoffice_writer/0b17a146-2934-46c7-8727-73ff6b6483e8.json b/evaluation_examples/examples/libreoffice_writer/0b17a146-2934-46c7-8727-73ff6b6483e8.json index 047c003..82c9437 100644 --- a/evaluation_examples/examples/libreoffice_writer/0b17a146-2934-46c7-8727-73ff6b6483e8.json +++ b/evaluation_examples/examples/libreoffice_writer/0b17a146-2934-46c7-8727-73ff6b6483e8.json @@ -3,10 +3,40 @@ "snapshot": "libreoffice_writer", "instruction": "Enter subscript", "source": "https://ask.libreoffice.org/t/how-to-enter-superscript-and-subscript-in-libreoffice-base-forms-reports/23413", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.google.com/uc?export=download&id=1E6exEA2ZlfIOiiX2NkwRofOApeoIw5AaGJ0JXyDp47c", + "path": "Desktop/Enter_Subscript.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Enter_Subscript.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "compare_line_spacing", + "expected": { + "type": "cloud_file", + "path": "https://drive.google.com/uc?export=download&id=1XVz6gPg_7_-KBAtXTmrfAA5x-jWPjn-7", + "dest": "Enter_Subscript_Gold.docx" + }, + "result": { + "type": "vm_file", + "path": "Desktop/Enter_Subscript.docx", + "dest": "Enter_Subscript.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/0e47de2a-32e0-456c-a366-8c607ef7a9d2.json b/evaluation_examples/examples/libreoffice_writer/0e47de2a-32e0-456c-a366-8c607ef7a9d2.json index 6b4aa8d..55b3d77 100644 --- a/evaluation_examples/examples/libreoffice_writer/0e47de2a-32e0-456c-a366-8c607ef7a9d2.json +++ b/evaluation_examples/examples/libreoffice_writer/0e47de2a-32e0-456c-a366-8c607ef7a9d2.json @@ -3,10 +3,35 @@ "snapshot": "libreoffice_writer", "instruction": "Add page number for every page at the bottom left", "source": "https://ask.libreoffice.org/t/how-to-start-page-numbering-on-a-certain-page/39931/4", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.google.com/uc?export=download&id=1xj-MauDLOp8TKI76GBd4nV-MRpdwIY8_URql15itlnI", + "path": "Desktop/Add_Page_Number_Bottom_Left.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Add_Page_Number_Bottom_Left.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "has_page_numbers_in_footers", + "result": { + "type": "vm_file", + "path": "Desktop/Add_Page_Number_Bottom_Left.docx", + "dest": "Add_Page_Number_Bottom_Left.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/0e763496-b6bb-4508-a427-fad0b6c3e195.json b/evaluation_examples/examples/libreoffice_writer/0e763496-b6bb-4508-a427-fad0b6c3e195.json index 70e5f67..0d401b1 100644 --- a/evaluation_examples/examples/libreoffice_writer/0e763496-b6bb-4508-a427-fad0b6c3e195.json +++ b/evaluation_examples/examples/libreoffice_writer/0e763496-b6bb-4508-a427-fad0b6c3e195.json @@ -3,10 +3,36 @@ "snapshot": "libreoffice_writer", "instruction": "Change the font to \"Times New Roman\" throughout the text.", "source": "https://ask.libreoffice.org/t/how-do-i-change-the-font-for-the-whole-document-in-writer/9220", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://doc-04-20-docstext.googleusercontent.com/export/hglu5spf1pl3kjo47q5hl516lk/0jdord1s8easgk928n14o5ploc/1703957510000/108888117743638485671/108888117743638485671/1irIYOEZskuu70YPnhHYBy4-3uNpt7seiWfiL8ioG8hI?format=docx&dat=AOBvIb3dVvZfsPetuWvygmWVE0DN2EwCvS70RO3tsI1xB-JfwsFWjAhZ-G_wtxHYj7_U3pqO1GAElZkQ2iEjiC0SQWWnfWvbKAYqWgy9SX-YGKT2qQFy8lk1DJ4n62nmLLSheQcC21L7s66OOtRriBzQCIS-JTIqA-e7WhH3tgmBeGtgGl0QFootAsI-XsOYm_h0XtkJhfptTw1m4VcCapv5VW9NZhdqbaZHXT1UgGUtMqqRAN0ByJbhcbTmXeM_NDwyE650ti82NDkGZDo52zjxNxo8DeraUPl9Gz6Nq4q3uQPfxsPRMdIn0feWei8RlJLdHPAaGHKFpHH8BRmjb6VFoGvbsk3kUIROd326NCKNtRT_7g9SVYHw_zSSLW-yZa9IvVJIdn_9Qc1kiCT7uvCMc-pn3R7Yk7yB4Xx7cBvQx1CdhE0Pv0PBbOXnMT10mkVDAs1q4YBzB92zpY9U6Ll3ZNNiXfCaBB8uCgGWtFtyml999_hJG1OTHDCN4mwAnsfmVlj3wJM8gbwlPCUjvIH4vEeS-jWGdTroqaPGFTSBp8UY9nFNrM2VZNa0uxGPwM8Y_S3YxIjqILsbPPiID3R9g4mwp4yFfpQ18opy1W9uWu4D4WmoVFzVHnTuYZ5y3FETB2gSLuMB-gLMpDzUAHwm16VpOdth44h9d2ViHlN61ybbj01-cl75iKCztEZ6NWJFv1mfCF4r33pYDiSOw8oTMXsFxYIlsMub_KLiav9S5Rh9V084Lz9jypnjzid-_mKCuKYXP0xqhOsiwoI8Gk1Z7CAgAJgx6EkmOag-XEjSqF9sYyHyLCLR_8UwWKqUpHumusriVciFgm7LhhQ8B21s-TUgBDP4Zby1G1v6GHe71w3UWK4dZ83wf0MsZUg", + "path": "Desktop/Change_Font_Through_File.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Change_Font_Through_File.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "compare_font_names", + "expected": "Times New Roman", + "result": { + "type": "vm_file", + "path": "Desktop/Change_Font_Through_File.docx", + "dest": "Change_Font_Through_File.docx" + } + } +} \ No newline at end of file