From c937e31b186ad08c2b7df7a8e556ea097fd7fdc5 Mon Sep 17 00:00:00 2001 From: tsuky_chen <3107760494@qq.com> Date: Sun, 31 Dec 2023 01:02:27 +0800 Subject: [PATCH] add eval libreoffice writer compare table & equation --- desktop_env/evaluators/metrics/__init__.py | 2 +- desktop_env/evaluators/metrics/docs.py | 61 +++++++++++++++++++ .../0810415c-bde4-4443-9047-d5f70165a697.json | 36 ++++++++++- .../663876c7-3471-43db-ba51-f410b13d9d7d.json | 36 ++++++++++- .../66399b0d-8fda-4618-95c4-bfc6191617e9.json | 36 ++++++++++- .../936321ce-5236-426a-9a20-e0e3c5dc536f.json | 36 ++++++++++- .../adf5e2c3-64c7-4644-b7b6-d2f0167927e7.json | 6 +- 7 files changed, 197 insertions(+), 16 deletions(-) diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index 69d65c5..d7d823b 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -1,3 +1,3 @@ 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 +from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, compare_insert_equation diff --git a/desktop_env/evaluators/metrics/docs.py b/desktop_env/evaluators/metrics/docs.py index 6953dd8..2502b5e 100644 --- a/desktop_env/evaluators/metrics/docs.py +++ b/desktop_env/evaluators/metrics/docs.py @@ -53,6 +53,67 @@ def compare_docx_files(file1, file2): return 1 +def compare_docx_tables(docx_file1, docx_file2): + doc1 = Document(docx_file1) + doc2 = Document(docx_file2) + + # get list of tables in docx + tables1 = doc1.tables + tables2 = doc2.tables + + if len(tables1) != len(tables2): + return 0 + + # Compare each table content + for table1, table2 in zip(tables1, tables2): + + if len(table1.rows) != len(table2.rows) or len(table1.columns) != len(table2.columns): + return 0 + + # Compare each cell + for i in range(len(table1.rows)): + for j in range(len(table1.columns)): + if table1.cell(i, j).text != table2.cell(i, j).text: + return 0 + + return 1 + +def compare_line_spacing(docx_file1, docx_file2): + + doc1 = Document(docx_file1) + doc2 = Document(docx_file2) + + if len(doc1.paragraphs) != len(doc2.paragraphs): + return 0 + + # Compare each paragraph line spacing + for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs): + + spacing1 = para1.paragraph_format.line_spacing + spacing2 = para2.paragraph_format.line_spacing + + if spacing1 != spacing2: + return 0 + + return 1 + +def compare_insert_equation(docx_file1, docx_file2): + + if not compare_docx_files(docx_file1, docx_file2): + return False + + doc1 = Document(docx_file1) + doc2 = Document(docx_file2) + + # Compare each paragraph if it contains equation + 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 + + + # file1 = 'path/to/file1.docx' # file2 = 'path/to/file2.docx' diff --git a/evaluation_examples/examples/libreoffice_writer/0810415c-bde4-4443-9047-d5f70165a697.json b/evaluation_examples/examples/libreoffice_writer/0810415c-bde4-4443-9047-d5f70165a697.json index 7af2f3e..55902e5 100644 --- a/evaluation_examples/examples/libreoffice_writer/0810415c-bde4-4443-9047-d5f70165a697.json +++ b/evaluation_examples/examples/libreoffice_writer/0810415c-bde4-4443-9047-d5f70165a697.json @@ -3,10 +3,40 @@ "snapshot": "libreoffice_writer", "instruction": "Make the line spacing of first two paragraph into double line spacing", "source": "https://www.youtube.com/watch?v=Q_AaL6ljudU", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.google.com/uc?export=download&id=1u7y8cUXqe-QzNX3YaPpZKYyphwv5IjHF_O5TjMnqvS4", + "path": "Desktop/Double_Line_Spacing.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Double_Line_Spacing.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=1D8_1WItMwyWkUPodohUKevIORE4pDw3C", + "dest": "Double_Line_Spacing_Gold.docx" + }, + "result": { + "type": "vm_file", + "path": "Desktop/Double_Line_Spacing.docx", + "dest": "Double_Line_Spacing.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/663876c7-3471-43db-ba51-f410b13d9d7d.json b/evaluation_examples/examples/libreoffice_writer/663876c7-3471-43db-ba51-f410b13d9d7d.json index 84f0ddc..5e3d9b5 100644 --- a/evaluation_examples/examples/libreoffice_writer/663876c7-3471-43db-ba51-f410b13d9d7d.json +++ b/evaluation_examples/examples/libreoffice_writer/663876c7-3471-43db-ba51-f410b13d9d7d.json @@ -3,10 +3,40 @@ "snapshot": "libreoffice_writer", "instruction": "Insert the equation \"(a + b)^2 = a^2 + 2 a b + b^2\"", "source": "https://askubuntu.com/questions/319593/how-to-type-science-equations-in-libre-office", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://docs.google.com/document/d/1ui9Kerbgm4oT_8sE7C_t2DJN9F6_ovu2o3zvY0Ro56Q/edit?usp=drive_link", + "path": "Desktop/Insert_Equation.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Insert_Equation.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "compare_insert_equation", + "expected": { + "type": "cloud_file", + "path": "https://drive.google.com/uc?export=download&id=1mbaglsw_xrVXJT8aNkuMQ9cTUh9Xhv9V", + "dest": "Insert_Equation_Gold.docx" + }, + "result": { + "type": "vm_file", + "path": "Desktop/Insert_Equation.docx", + "dest": "Insert_Equation.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/66399b0d-8fda-4618-95c4-bfc6191617e9.json b/evaluation_examples/examples/libreoffice_writer/66399b0d-8fda-4618-95c4-bfc6191617e9.json index 3c34403..c2cb282 100644 --- a/evaluation_examples/examples/libreoffice_writer/66399b0d-8fda-4618-95c4-bfc6191617e9.json +++ b/evaluation_examples/examples/libreoffice_writer/66399b0d-8fda-4618-95c4-bfc6191617e9.json @@ -3,10 +3,40 @@ "snapshot": "libreoffice_writer", "instruction": "Insert a 7*5 empty table", "source": "https://www.youtube.com/watch?v=l25Evu4ohKg", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.google.com/uc?export=download&id=1fl11qfMJ3Z7TTY3leaTpofkOKY8FhoklkxOK_vIx_J0", + "path": "Desktop/Insert_Empty_Table.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Insert_Empty_Table.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "compare_docx_tables", + "expected": { + "type": "cloud_file", + "path": "https://drive.google.com/uc?export=download&id=1i8WGOU1EM1NwoVPwFuLltoeS8uKn1j3bUVPeA4bwTO0", + "dest": "Insert_Empty_Table_Gold.docx" + }, + "result": { + "type": "vm_file", + "path": "Desktop/Insert_Empty_Table.docx", + "dest": "Insert_Empty_Table.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/936321ce-5236-426a-9a20-e0e3c5dc536f.json b/evaluation_examples/examples/libreoffice_writer/936321ce-5236-426a-9a20-e0e3c5dc536f.json index 3c4ac52..a55ed82 100644 --- a/evaluation_examples/examples/libreoffice_writer/936321ce-5236-426a-9a20-e0e3c5dc536f.json +++ b/evaluation_examples/examples/libreoffice_writer/936321ce-5236-426a-9a20-e0e3c5dc536f.json @@ -3,10 +3,40 @@ "snapshot": "libreoffice_writer", "instruction": "Convert the content seperated by commas to a table", "source": "https://www.youtube.com/watch?v=l25Evu4ohKg", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.google.com/uc?export=download&id=1bLaEmCfVoHzi51-i66O-YRIJv0xW66irXf0pmyT5B8E", + "path": "Desktop/Convert_Text_To_Table.docx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/Convert_Text_To_Table.docx" + } + } + ], "trajectory": "trajectories/", "related_apps": [ "libreoffice_writer" ], - "evaluator": "evaluation_dir" -} + "evaluator": { + "func": "compare_docx_tables", + "expected": { + "type": "cloud_file", + "path": "https://drive.google.com/uc?export=download&id=1DY7J6xtnLCUa8lsAXjdY9VK1XxrbXE6G", + "dest": "Convert_Text_To_Table_Gold.docx" + }, + "result": { + "type": "vm_file", + "path": "Desktop/Convert_Text_To_Table.docx", + "dest": "Convert_Text_To_Table.docx" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/libreoffice_writer/adf5e2c3-64c7-4644-b7b6-d2f0167927e7.json b/evaluation_examples/examples/libreoffice_writer/adf5e2c3-64c7-4644-b7b6-d2f0167927e7.json index 8cd9da2..8c2564b 100644 --- a/evaluation_examples/examples/libreoffice_writer/adf5e2c3-64c7-4644-b7b6-d2f0167927e7.json +++ b/evaluation_examples/examples/libreoffice_writer/adf5e2c3-64c7-4644-b7b6-d2f0167927e7.json @@ -1,7 +1,7 @@ { "id": "adf5e2c3-64c7-4644-b7b6-d2f0167927e7", "snapshot": "libreoffice_writer", - "instruction": "Helping me adding CITATION_TEXT to my reference list, and add a cross reference after the word \"WHERE_WE_ADD_REFERENCE\"", + "instruction": "Helping me adding CITATION_TEXT:\"C. Luo and M. J. Carey, \"LSM-based storage techniques: a survey,\" The VLDB Journal, vol. 29, no. 1, pp. 393–418, 2020.\" to my reference list, and add a cross reference after the word \"WHERE_WE_ADD_REFERENCE\"", "source": "https://seekstar.github.io/2022/04/11/libreoffice%E5%BC%95%E7%94%A8%E6%96%87%E7%8C%AE/", "config": [ { @@ -9,7 +9,7 @@ "parameters": { "files": [ { - "url": "https://drive.google.com/uc?export=download&id=1boNZ3JuqUx2apMqExL3UX9A4Sopi77ke7yKnIO3cpbg", + "url": "https://doc-00-20-docstext.googleusercontent.com/export/hglu5spf1pl3kjo47q5hl516lk/fm9rfictm643s722v6huocv1t8/1703936520000/108888117743638485671/108888117743638485671/1boNZ3JuqUx2apMqExL3UX9A4Sopi77ke7yKnIO3cpbg?format=docx&dat=AOBvIb0aOSBJsn7KXrdM4-kYvBzstZwFeJ04cq3PPIlMtRwz8ONEDNFmGVQ6yTj9QF89iCgMY5Nrtyqmuh1DgCncJKWadsXRe0pwDkP-LFXnU3sQ4j4h1Cx-DscnonNv53syeLZLiKiQI2BeqxQ8_3dji3UDwAqoSue5xteFhWh4D8yNWdfAYDP8frGmEUm92DegHuvzRaLLJt2HWSvyTt9ZhZfX_0ome1hqdE89bYpdzS2Z9K7Cke2YushT1KPR0BO51ZX5MXyuppdS6uJ5ZX0S6yoJ5XUIXl2uQgUeV0DKvMBhelGrLAs9YdzAw6UvStH5B5Sd91JhFL9LN_1ttWuBYyddJldgf85tYJFRjtQ_sTnfTEC4KZ1eUjU7pFKRVGFJ78jY_BzYYHG-UWL7lkuwtroRp55Fv40sn7ynCUuTgsmiki678_xOGU9_LpP6UU567_29W3KJVfqFBBES3Y3_fIGyLrO081jG8076QNsF4UULcz2u7Q1Jnps1--4XRDa1hIZvGHTUWA6FM9bCWd8Cd9_RFlklYwKa38-PSGdRa5_b8Jz07o1xKyPjfQ6CeMZ5rZ1wzwREc4ZdL4ae7eWUHZsyK9Gd2tLnCfLjeP2sCTGUrFKHtS9k6Vtd-SlorajknLK8V48npAlWzESxDIQcGqHQqfJJKljaH5q2IBKsOPvH8xxfzAEkkI3Kmqasx8NE2BXr8X-f1AXbAb1PvjDOO9TJnhfbgcVm4_5fGl5D0ODoOQZ_g48KpJglaWV3qyBHMFBVEW3Xtr5gRQg5IEVK8zmdMwjmXDDhySOKHCNZDUutKzj0G57cxPVW5TOr93M9zVNh7zeh3iIyyDYAzKw3SnXYGubxFKY6ezcEmNaGfhPSRooKvxgcKBJYFAk", "path": "Desktop/Add_Citation_Cross_Reference.docx" } ] @@ -30,7 +30,7 @@ "func": "compare_docx_files", "expected": { "type": "cloud_file", - "path": "https://doc-14-20-docstext.googleusercontent.com/export/hglu5spf1pl3kjo47q5hl516lk/erhjsu6vpod00o7ruf95hlnqkk/1703931360000/108888117743638485671/108888117743638485671/1tiN6A9-zQ2gfDPTWAYK5mv5JbUe2Y_PqPIyuvsu7PgA?format=docx&dat=AOBvIb1uRgycIK4pNup7ZrnJqwNjYOgTUlrhxAc8DnBWzUt9zDxLm3e4s0KQytzQ1qvFZaBr8-ymrVv7Mmb7ovpVk4k8sgS_2MRD1m-tMUDiUEGFtoxrECd4Xoaspuwb-BZttyU1cCdY3U12qcNWy5Cts_uys6ouKZok01Z7s1J233udfrMbXvDt_X-HeNo_7e6Bh64ZC4ohHOKZddsuayKYxPTKpgnho_8FPuWXqZDKyfYRDoTXxGWv-WrZSVqRSHP6GMtBdWc1-QBuWzH_iRTM64joeveSDppMjMeB5bjdJQ7EXf-EjA8MjSxtvQQGBmun7PoZ-W7fLmQ1E3fZKJ5BwQDOIJHDCBar83iHHoXOUJ1Q5UbkKcCS0nJ_pprCzRYXLSeVfN0_bdGuY2lSE8GhX-yGlyGIjAIZK-YulOFXwV0--4aD10rh43A5GLmSLeNZe6maUU33j1V-zUtp1qPgRk3SnPJENNOXf-sOYAvQqSgROSBvAwElqgHUMD_ROK692M7_7OtFe4sjs0eVnBzROEHy-ZznXqdSXJj6-2vloXHWfswPfE-Mq5kc7F1zX4CY6H1kQ-zgHzeLX-qQA6YmgZPJ0pLzFkAkBiMAjPigA_2dy7jk-niePSbZ9DcgYoX6iv6MkJ0y6JE_HQF7Gr6kDBiOjOyDp7gFoMj35F41Fac1wpSJmoiUEGLg0qGRBZ6BPc54m-AAFuy-2s4BUUtPgk-FlTD1jSpHDXLbJ-VQFglx1CYpfqFAnmIE8yseQPh3GqQYyCtCfD-zzO-CRTT9A-XOQVuH27npfk2gMDKtGwJr7XhNL8lL9b8540uTjt9nFnmNfDZCFK01VULdHZesSBedqM4iApgVVnjok8nmYw14e9WSgJOdjeiYAwI", + "path": "https://drive.google.com/uc?export=download&id=1eJSr8J2eiGr6K5n59MGOwY-8dgCPIjYh", "dest": "Add_Citation_Cross_Reference_Gold.docx" }, "result": {