Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,6 +78,35 @@ PERIOD_REQUIRED = {
|
|
78 |
"Other": False
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# 1. Base Exception Classes
|
82 |
class DocumentCheckError(Exception):
|
83 |
"""Base exception for document checker errors."""
|
@@ -215,8 +244,8 @@ class DocumentCheckerConfig:
|
|
215 |
"""Initialize configuration with optional config file."""
|
216 |
self.default_config = {
|
217 |
"logging": {
|
218 |
-
"level":
|
219 |
-
"format":
|
220 |
},
|
221 |
"checks": {
|
222 |
"acronyms": True,
|
@@ -637,35 +666,6 @@ def profile_performance(func):
|
|
637 |
# 8. FAA Document Checker
|
638 |
class FAADocumentChecker(DocumentChecker):
|
639 |
"""Document checker implementation for FAA documents."""
|
640 |
-
|
641 |
-
# Class Constants
|
642 |
-
PERIOD_REQUIRED = {
|
643 |
-
DocumentType.ADVISORY_CIRCULAR: True,
|
644 |
-
DocumentType.AIRWORTHINESS_CRITERIA: False,
|
645 |
-
DocumentType.DEVIATION_MEMO: False,
|
646 |
-
DocumentType.EXEMPTION: False,
|
647 |
-
DocumentType.FEDERAL_REGISTER_NOTICE: False,
|
648 |
-
DocumentType.ORDER: True,
|
649 |
-
DocumentType.POLICY_STATEMENT: False,
|
650 |
-
DocumentType.RULE: False,
|
651 |
-
DocumentType.SPECIAL_CONDITION: False,
|
652 |
-
DocumentType.TECHNICAL_STANDARD_ORDER: True,
|
653 |
-
DocumentType.OTHER: False
|
654 |
-
}
|
655 |
-
|
656 |
-
HEADING_WORDS = {
|
657 |
-
'INFORMATION', 'GENERAL', 'SUMMARY', 'INTRODUCTION', 'BACKGROUND',
|
658 |
-
'DISCUSSION', 'CONCLUSION', 'APPENDIX', 'CHAPTER', 'SECTION',
|
659 |
-
'PURPOSE', 'APPLICABILITY', 'CANCELLATION', 'DEFINITION', 'REQUIREMENTS',
|
660 |
-
'AUTHORITY', 'POLICY', 'SCOPE', 'RELATED', 'MATERIAL', 'DISTRIBUTION',
|
661 |
-
'EXPLANATION', 'PROCEDURES', 'NOTE', 'WARNING', 'CAUTION', 'EXCEPTION',
|
662 |
-
'GROUPS', 'PARTS', 'TABLE', 'FIGURE', 'REFERENCES', 'DEFINITIONS'
|
663 |
-
}
|
664 |
-
|
665 |
-
PREDEFINED_ACRONYMS = {
|
666 |
-
'CFR', 'U.S.', 'USA', 'US', 'U.S.C', 'e.g.', 'i.e.', 'FAQ', 'No.', 'ZIP', 'PDF', 'SSN',
|
667 |
-
'DC', 'MA', 'WA', 'TX', 'MO'
|
668 |
-
}
|
669 |
|
670 |
# Constructor
|
671 |
def __init__(self, config_path: Optional[str] = None):
|
@@ -777,22 +777,7 @@ class FAADocumentChecker(DocumentChecker):
|
|
777 |
issues=[{'error': f'Unsupported document type: {doc_type}'}]
|
778 |
)
|
779 |
|
780 |
-
|
781 |
-
period_required = {
|
782 |
-
"Advisory Circular": True,
|
783 |
-
"Airworthiness Criteria": False,
|
784 |
-
"Deviation Memo": False,
|
785 |
-
"Exemption": False,
|
786 |
-
"Federal Register Notice": False,
|
787 |
-
"Order": True,
|
788 |
-
"Policy Statement": False,
|
789 |
-
"Rule": False,
|
790 |
-
"Special Condition": False,
|
791 |
-
"Technical Standard Order": True,
|
792 |
-
"Other": False
|
793 |
-
}
|
794 |
-
|
795 |
-
should_have_period = period_required.get(doc_type)
|
796 |
if should_have_period is None:
|
797 |
self.logger.error(f"Period requirement not defined for document type: {doc_type}")
|
798 |
return DocumentCheckResult(
|
@@ -2064,6 +2049,31 @@ class DocumentCheckResultsFormatter:
|
|
2064 |
Returns:
|
2065 |
str: Formatted report with consistent styling
|
2066 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2067 |
# Determine caption format based on document type
|
2068 |
if doc_type in ["Advisory Circular", "Order"]:
|
2069 |
table_format = {
|
@@ -2107,61 +2117,6 @@ class DocumentCheckResultsFormatter:
|
|
2107 |
# Update the issue categories with the correct format
|
2108 |
self.issue_categories['caption_check_table'] = table_format
|
2109 |
self.issue_categories['caption_check_figure'] = figure_format
|
2110 |
-
|
2111 |
-
# Define formatting rules for different document types
|
2112 |
-
formatting_rules = {
|
2113 |
-
"italics_only": {
|
2114 |
-
"types": ["Advisory Circular"],
|
2115 |
-
"italics": True,
|
2116 |
-
"quotes": False,
|
2117 |
-
"description": "For Advisory Circulars, referenced document titles should be italicized but not quoted",
|
2118 |
-
"example": "See AC 20-135, *Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria* for information on X."
|
2119 |
-
},
|
2120 |
-
"quotes_only": {
|
2121 |
-
"types": [
|
2122 |
-
"Airworthiness Criteria", "Deviation Memo", "Exemption",
|
2123 |
-
"Federal Register Notice", "Order", "Rule", "Special Condition",
|
2124 |
-
"Technical Standard Order"
|
2125 |
-
],
|
2126 |
-
"italics": False,
|
2127 |
-
"quotes": True,
|
2128 |
-
"description": "For this document type, referenced document titles should be in quotes without italics",
|
2129 |
-
"example": 'See AC 20-135, "Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria" for information on X.'
|
2130 |
-
},
|
2131 |
-
"no_formatting": {
|
2132 |
-
"types": ["Policy Statement", "Other"],
|
2133 |
-
"italics": False,
|
2134 |
-
"quotes": False,
|
2135 |
-
"description": "For this document type, referenced document titles should not use italics or quotes",
|
2136 |
-
"example": "See AC 20-135, Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria for information on X."
|
2137 |
-
}
|
2138 |
-
}
|
2139 |
-
|
2140 |
-
# Find the formatting group for the current document type
|
2141 |
-
format_group = None
|
2142 |
-
for group, rules in formatting_rules.items():
|
2143 |
-
if doc_type in rules["types"]:
|
2144 |
-
format_group = rules
|
2145 |
-
break
|
2146 |
-
|
2147 |
-
# Use default if document type not found
|
2148 |
-
if not format_group:
|
2149 |
-
format_group = formatting_rules["no_formatting"]
|
2150 |
-
|
2151 |
-
# Update the document title check category
|
2152 |
-
self.issue_categories['document_title_check'] = {
|
2153 |
-
'title': 'Referenced Document Title Format Issues',
|
2154 |
-
'description': format_group['description'],
|
2155 |
-
'solution': "Format referenced document titles as follows: " + (
|
2156 |
-
"Italicize the title" if format_group['italics'] else
|
2157 |
-
"Put the title in quotes" if format_group['quotes'] else
|
2158 |
-
"No special formatting required"
|
2159 |
-
),
|
2160 |
-
'example_fix': {
|
2161 |
-
'before': 'See AC 20-135, Powerplant Installation for information on X.',
|
2162 |
-
'after': format_group['example']
|
2163 |
-
}
|
2164 |
-
}
|
2165 |
|
2166 |
output = []
|
2167 |
|
|
|
78 |
"Other": False
|
79 |
}
|
80 |
|
81 |
+
# Document formatting rules
|
82 |
+
DOCUMENT_FORMATTING_RULES = {
|
83 |
+
"italics_only": {
|
84 |
+
"types": ["Advisory Circular"],
|
85 |
+
"italics": True,
|
86 |
+
"quotes": False,
|
87 |
+
"description": "For Advisory Circulars, referenced document titles should be italicized but not quoted",
|
88 |
+
"example": "See AC 20-135, *Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria* for information on X."
|
89 |
+
},
|
90 |
+
"quotes_only": {
|
91 |
+
"types": [
|
92 |
+
"Airworthiness Criteria", "Deviation Memo", "Exemption",
|
93 |
+
"Federal Register Notice", "Order", "Rule", "Special Condition",
|
94 |
+
"Technical Standard Order"
|
95 |
+
],
|
96 |
+
"italics": False,
|
97 |
+
"quotes": True,
|
98 |
+
"description": "For this document type, referenced document titles should be in quotes without italics",
|
99 |
+
"example": 'See AC 20-135, "Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria" for information on X.'
|
100 |
+
},
|
101 |
+
"no_formatting": {
|
102 |
+
"types": ["Policy Statement", "Other"],
|
103 |
+
"italics": False,
|
104 |
+
"quotes": False,
|
105 |
+
"description": "For this document type, referenced document titles should not use italics or quotes",
|
106 |
+
"example": "See AC 20-135, Powerplant Installation and Propulsion System Component Fire Protection Test Methods, Standards, and Criteria for information on X."
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
# 1. Base Exception Classes
|
111 |
class DocumentCheckError(Exception):
|
112 |
"""Base exception for document checker errors."""
|
|
|
244 |
"""Initialize configuration with optional config file."""
|
245 |
self.default_config = {
|
246 |
"logging": {
|
247 |
+
"level": DEFAULT_LOG_LEVEL, # Use constant defined at top
|
248 |
+
"format": DEFAULT_LOG_FORMAT # Use constant defined at top
|
249 |
},
|
250 |
"checks": {
|
251 |
"acronyms": True,
|
|
|
666 |
# 8. FAA Document Checker
|
667 |
class FAADocumentChecker(DocumentChecker):
|
668 |
"""Document checker implementation for FAA documents."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
|
670 |
# Constructor
|
671 |
def __init__(self, config_path: Optional[str] = None):
|
|
|
777 |
issues=[{'error': f'Unsupported document type: {doc_type}'}]
|
778 |
)
|
779 |
|
780 |
+
should_have_period = PERIOD_REQUIRED.get(doc_type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
781 |
if should_have_period is None:
|
782 |
self.logger.error(f"Period requirement not defined for document type: {doc_type}")
|
783 |
return DocumentCheckResult(
|
|
|
2049 |
Returns:
|
2050 |
str: Formatted report with consistent styling
|
2051 |
"""
|
2052 |
+
format_group = None
|
2053 |
+
for group, rules in DOCUMENT_FORMATTING_RULES.items():
|
2054 |
+
if doc_type in rules["types"]:
|
2055 |
+
format_group = rules
|
2056 |
+
break
|
2057 |
+
|
2058 |
+
# Use default if document type not found
|
2059 |
+
if not format_group:
|
2060 |
+
format_group = DOCUMENT_FORMATTING_RULES["no_formatting"]
|
2061 |
+
|
2062 |
+
# Update the document title check category with global rules
|
2063 |
+
self.issue_categories['document_title_check'] = {
|
2064 |
+
'title': 'Referenced Document Title Format Issues',
|
2065 |
+
'description': format_group['description'],
|
2066 |
+
'solution': "Format referenced document titles as follows: " + (
|
2067 |
+
"Italicize the title" if format_group['italics'] else
|
2068 |
+
"Put the title in quotes" if format_group['quotes'] else
|
2069 |
+
"No special formatting required"
|
2070 |
+
),
|
2071 |
+
'example_fix': {
|
2072 |
+
'before': 'See AC 20-135, Powerplant Installation for information on X.',
|
2073 |
+
'after': format_group['example']
|
2074 |
+
}
|
2075 |
+
}
|
2076 |
+
|
2077 |
# Determine caption format based on document type
|
2078 |
if doc_type in ["Advisory Circular", "Order"]:
|
2079 |
table_format = {
|
|
|
2117 |
# Update the issue categories with the correct format
|
2118 |
self.issue_categories['caption_check_table'] = table_format
|
2119 |
self.issue_categories['caption_check_figure'] = figure_format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2120 |
|
2121 |
output = []
|
2122 |
|