{ "cells": [ { "cell_type": "markdown", "id": "marine-termination", "metadata": {}, "source": [ "![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n", "
tag tekst @parametr link.
')" ] }, { "cell_type": "code", "execution_count": 48, "id": "settled-armor", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Match({'ruleId': 'SENTENCE_WHITESPACE', 'message': 'Add a space between sentences.', 'replacements': [' BeanOps'], 'offsetInContext': 43, 'context': '... will be generated which Is named [...]BeanOps where [...] is the name of the class. I...', 'offset': 183, 'errorLength': 7, 'category': 'TYPOGRAPHY', 'ruleIssueType': 'whitespace', 'sentence': 'BeanOps where [...] is the name of the class.'}),\n", " Match({'ruleId': 'COMMA_PARENTHESIS_WHITESPACE', 'message': 'Don’t put a space after the opening parenthesis.', 'replacements': ['{'], 'offsetInContext': 43, 'context': '...tentionPolicy.SOURCE) public MagicBean { / Whether to generate an all args stat...', 'offset': 1071, 'errorLength': 2, 'category': 'TYPOGRAPHY', 'ruleIssueType': 'whitespace', 'sentence': '/\\n @Target({ElementType.TYPE})\\n @Retention(RetentionPolicy.SOURCE)\\n public MagicBean {\\n /\\n Whether to generate an all args static factory method.'}),\n", " Match({'ruleId': 'A_NNS', 'message': 'The plural noun “equals” cannot be used with the article “an”. Did you mean “an equal” or “equals”?', 'replacements': ['an equal', 'equals'], 'offsetInContext': 43, 'context': '... default false; / Whether to generate an equals and hash code implementation. / boole...', 'offset': 1206, 'errorLength': 9, 'category': 'GRAMMAR', 'ruleIssueType': 'grammar', 'sentence': '/\\n boolean allArgsStaticFactory() default false;\\n /\\n Whether to generate an equals and hash code implementation.'}),\n", " Match({'ruleId': 'COMMA_PARENTHESIS_WHITESPACE', 'message': 'Don’t put a space before the closing parenthesis.', 'replacements': ['}'], 'offsetInContext': 43, 'context': '.../ Class extend() default Object.class; }', 'offset': 1598, 'errorLength': 2, 'category': 'TYPOGRAPHY', 'ruleIssueType': 'whitespace', 'sentence': '/\\n Class extend() default Object.class;\\n }'})]" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import re\n", "import language_tool_python\n", " \n", "def correct_java_grammar(java_file_path):\n", " tool = language_tool_python.LanguageTool('en-US')\n", " lineToAnalyze = \"\"\n", " with open(java_file_path, 'r') as file:\n", " javadoc_mode = False\n", " for line in file:\n", " line.strip()\n", " #print(line)\n", " if line.startswith('//'):\n", " lineToAnalyze += line + \" \"\n", " elif line.startswith('/*') and line.endswith('*/'):\n", " lineToAnalyze += line + \" \"\n", " elif line.startswith('/*') and not line.endswith('*/'):\n", " lineToAnalyze += line + \" \"\n", " javadoc_mode = True\n", " \n", " elif javadoc_mode:\n", " if line.endswith('*/'):\n", " javadoc_mode = False\n", " lineToAnalyze += line + \" \"\n", " else:\n", " lineToAnalyze += line + \" \"\n", "\n", " #print(x(lineToAnalyze))\n", " errors = tool.check(x(lineToAnalyze))\n", " \n", "\n", " return [errors for errors in errors if errors.ruleId != 'MORFOLOGIK_RULE_EN_US']\n", "\n", "correct_java_grammar(\"./class.java\") # kod przekopiowany z \n", "# https://github.com/bowbahdoe/magic-bean/blob/main/src/main/java/dev/mccue/magicbean/MagicBean.java" ] } ], "metadata": { "author": "Rafał Jaworski", "email": "rjawor@amu.edu.pl", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "lang": "pl", "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.1" }, "subtitle": "15. Korekta gramatyczna", "title": "Komputerowe wspomaganie tłumaczenia", "year": "2021" }, "nbformat": 4, "nbformat_minor": 5 }