I am not a developer. I was asked to find a code that works to detect a sentence that begins with a bullet point and does not end with a full stop.
This is the code that we used:
<rule id="BULLET_POINT_MISSING_PERIOD" name="Ensure bullet point ends with period">
<pattern>
<token spacebefore="no">-</token>
<regexp>\s\w+</regexp>
<!-- <token min="1" max="4" postag="NNP|NN|NPS|NNS" postag_regexp="yes"/> -->
<!-- <token regexp="yes" negate="yes">[.*|.|!|?]$</token> -->
</pattern>
<message>This bullet point should end with a period. Consider adding a full stop after the place name.</message>
<suggestion>
Hello
</suggestion>
<example type="incorrect">
<marker>-Tweed Heads</marker>
</example>
<example type="correct">
-Tweed Heads.
</example>
</rule>
It kinda worked. However, it is also recommended that a full stop be made even if the sentence already has one. Is there a better way for the code to be written?
Hi @jtagnes
I see what you’re trying to do, but it looks like the rule isn’t checking properly if a full stop already exists. Instead of just looking for a missing period, you might want to modify the pattern to check if the last character is not a punctuation mark before suggesting a fix
Also, I noticed that your regex for detecting words after the bullet point is a bit loose. If your bullet points always start with a dash followed by a space, a more precise way to handle it could be using something like:
- \w.*[^.!?]$
That way, it ensures the sentence doesn’t already end with . ! or ? before suggesting a period. Have you tested different cases with multi-word bullet points? I once struggled with a similar issue where my rule accidentally flagged correctly punctuated sentences because I wasn’t handling trailing spaces properly. Maybe worth double-checking