Skip to content

Commit 64fd4ab

Browse files
authored
IVS-18 - Enhance protocol feature description check (#270)
* IVS-18 - Enhance protocol feature description check * avoid duplicate error output, change in output msg
1 parent 84a048b commit 64fd4ab

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
echo $CONDA/bin >> $GITHUB_PATH
2828
- name: Install dependencies
2929
run: |
30-
pip install behave pytest tabulate pyparsing sqlalchemy numpy pydantic pydot sqlalchemy_utils django python-dotenv deprecated pandas
30+
pip install behave pytest tabulate pyparsing sqlalchemy numpy pydantic pydot sqlalchemy_utils django python-dotenv deprecated pandas pyspellchecker
3131
wget -O /tmp/ifcopenshell_python.zip https://s3.amazonaws.com/ifcopenshell-builds/ifcopenshell-python-`python3 -c 'import sys;print("".join(map(str, sys.version_info[0:2])))'`-v0.8.0-90ae709-linux64.zip
3232
mkdir -p `python3 -c 'import site; print(site.getusersitepackages())'`
3333
unzip -d `python3 -c 'import site; print(site.getusersitepackages())'` /tmp/ifcopenshell_python.zip

features/IFC101_Only-official-ifc-versions-allowed.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@W00030
44
Feature: IFC101 - Only official IFC versions allowed
55

6-
This rule verifies that the IFC model has a schema identifier corresponding to any of the official versions released by buildingSMART.
6+
The rule verifies that the IFC model has a schema identifier corresponding to any of the official versions released by buildingSMART.
77
Specifically, IFC2x3 TC1 (version 2.3.0.1), IFC4 ADD2 TC1 (version 4.0.2.1), or IFC4.3 ADD2 (version 4.3.2.0).
88

99
Scenario: Verifying Current Schema Identifier for IFC version

features/IFC102_Absence-of-deprecated-entities.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@implementer-agreement
55
Feature: IFC102 - Absence of deprecated entities
66

7-
This rule verifies that the IFC model does not have deprecated entities, attributes or enumerators.
7+
The rule verifies that the IFC model does not have deprecated entities, attributes or enumerators.
88
By definition, a deprecated entity shall not be exported by applications.
99
Complying interpreters shall still be able to import deprecated definitions.
1010
IFC2X3: https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/deprecated_constructs.htm

features/rule_creation_protocol/protocol.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pydantic import model_validator, field_validator, Field, ValidationError
55
from pyparsing import Word, alphas, nums, Literal, Combine, StringEnd, alphanums, ParseException
66
import pyparsing
7+
from spellchecker import SpellChecker
78

89

910
from .validation_helper import ValidatorHelper, ParsePattern
@@ -178,14 +179,54 @@ def validate_ifc_input(cls, value):
178179

179180
@field_validator('description')
180181
def validate_description(cls, value=list) -> list:
181-
"""must include a description of the rule that start with "The rule verifies ...""" # allow for comma's
182-
if not any(value.startswith(f"{prefix} rule verifies{optional_comma}") for prefix in ("This", "The") for optional_comma in ("", ",")):
182+
"""
183+
Validates that the description starts with 'The rule verifies ...'.
184+
Captures cases where an incorrect prefix is used or the format is entirely incorrect.
185+
"""
186+
valid_prefix = "The"
187+
invalid_prefix = "This"
188+
189+
valid_start = any(value.startswith(f"{prefix} rule verifies{optional_comma}")
190+
for prefix in [valid_prefix, invalid_prefix]
191+
for optional_comma in ("", ","))
192+
193+
incorrect_prefix_start = any(value.startswith(f"{prefix} rule verifies{optional_comma}")
194+
for prefix in (invalid_prefix,)
195+
for optional_comma in ("", ","))
196+
197+
if incorrect_prefix_start:
183198
raise ProtocolError(
184199
value=value,
185-
message=f"The description must start with 'The rule verifies', it now starts with {value}"
200+
message=f"The description starts with an incorrect prefix '{invalid_prefix}'. It should start with 'The rule verifies'."
186201
)
187-
return value
188202

203+
if not valid_start:
204+
spell = SpellChecker()
205+
misspelled_words = spell.unknown(value.split()[:4])
206+
if misspelled_words:
207+
corrections = {word: spell.correction(word) for word in misspelled_words}
208+
corrected_string = ' '.join([corrections.get(word, word) for word in value.split()])
209+
corrected_valid_start = any(corrected_string.startswith(f"{prefix} rule verifies{optional_comma}")
210+
for prefix in [valid_prefix]
211+
for optional_comma in ("", ","))
212+
213+
message = f"The feature description contains spelling errors. Here are the incorrect words and their suggested corrections: {corrections}."
214+
215+
if not corrected_valid_start:
216+
message += f" Additionally, after corrections, the description still does not start with 'The rule verifies'. It starts with '{' '.join(corrected_string.split()[:4])}'."
217+
218+
raise ProtocolError(
219+
value=value,
220+
message=message
221+
)
222+
else:
223+
raise ProtocolError(
224+
value=value,
225+
message=f"The description must start with 'The rule verifies', but it now starts with '{' '.join(value.split()[:4])}'."
226+
)
227+
228+
return value
229+
189230
@field_validator('steps')
190231
def validate_steps(cls, value):
191232
"""Check only correct keywords are applied: 'Given', 'Then', 'And'"""

0 commit comments

Comments
 (0)