Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pt] Fix hexadecimal number bug #10601

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments,
for (String antiPattern : antiPatterns) {
Pattern p = Pattern.compile(antiPattern);
Matcher matcher = p.matcher(sentenceObj.getText());
if (matcher.find()) {
while (matcher.find()) {
// partial overlap is enough to filter out a match:
if (matcher.start() <= match.getToPos() && matcher.end() >= match.getToPos() ||
matcher.start() <= match.getFromPos() && matcher.end() >= match.getFromPos()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,20 @@
<disambig action="ignore_spelling"/>
</rule>

<rule id="HEXADECIMAL_NOTATION">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'name' attribute is missing. I think it is required in some tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rule within a rulegroup, though, and the rulegroup has both a name and an id attribute. Should be fine..?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes. If the tests pass, it is fine.

<pattern>
<token regexp="yes" case_sensitive="yes">0x[0-9A-Fa-f]+</token>
</pattern>
<disambig action="ignore_spelling"/>
</rule>

<rule id="OCTAL_NOTATION">
<pattern>
<token regexp="yes" case_sensitive="yes">0o[0-7]+</token>
</pattern>
<disambig action="ignore_spelling"/>
</rule>

<rule id="X_AS_MULTIPLICATION_SIGN_IGNORE">
<pattern>
<token regexp="yes">&number_token;x&number_token;[a-zA-Z]*</token>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41780,20 +41780,23 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
<example>UHCI: a versão USB 1.x</example>
</rule>
<rule>
<regexp>(?&lt;!([a-vyz]|[a-vyz]\d|[a-vyz]\d{2}|[a-vyz]\d{3}|[a-vyz]\d{4}|[a-vyz]\d{5}))((?!(?:[,;\(\.][x\*]([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)|(?:[\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)[x\*][,;\.\)\!\?]))([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)[x\*]([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+))</regexp>
<regexp>(?&lt;!([a-vyz]|[a-vyz]\d|[a-vyz]\d{2}|[a-vyz]\d{3}|[a-vyz]\d{4}|[a-vyz]\d{5}))((?!(?:[,;\(\.][x\*]([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)|(?:[\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)[x\*][,;\.\)\!\?]))([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?)[x\*]([\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+[a-zA-Z]*))</regexp>
<filter class="org.languagetool.rules.patterns.RegexAntiPatternFilter" args="antipatterns:\b0x[a-fA-F0-9]{2,4}"/>
<message>Prefira o símbolo de multiplicação.</message>
<suggestion>\4×\5</suggestion>
<suggestion>\4·\5</suggestion>
<example correction='2,998×10⁸|2,998·10⁸'>c=<marker>2,998x10⁸</marker> m/s</example>
<example correction="6.626×10⁻³⁴|6.626·10⁻³⁴">h = <marker>6.626x10⁻³⁴</marker> J.s</example>
<example correction="5×2|5·2"><marker>5*2</marker> = 10</example>
<!-- unit spacing rule will need to apply independently, and only after this is accepted -->
<example correction="10,5×17,2|10,5·17,2">Uma área de <marker>10,5x17,2</marker>km.</example>
<example correction="10,5×17,2km|10,5·17,2km">Uma área de <marker>10,5x17,2km</marker>.</example>
<example>a=2·x²+5</example>
<example>4,5×2,5=11,25</example>
<example>Oxihalídeos do Amerício na forma de AmVIO2X2, AmVO2X, AmIVOX2 e AmIIIOX…</example>
<example>Número 1Z1141X30370035113</example>
<example>- 1 X, 2 X, 4 X</example>
<example>Qualquer octeto 0x00 - 0x20 ou 0x7F - 0x9F2</example>
<example correction="0×5Q|0·5Q">No entanto, <marker>0x5Q</marker> não é um octal ou um hexadecimal.</example>
</rule>
<rule>
<regexp>([a-z]|[\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?[a-z]{0,1})\*([a-z]|[\d\.,⁻¹²³⁴⁵⁶⁷⁸⁹⁰]+?[a-z]{0,1})</regexp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ public void testPortugueseSpellerIgnoresDiceRollNotation() throws Exception {
assertNoErrors("20d10", ltBR, ruleBR);
}

@Test
public void testPortugueseSpellerIgnoresHexadecimalAndOctalNumbers() throws Exception {
// Disambiguator rule
assertNoErrors("0x1A", ltBR, ruleBR);
assertNoErrors("0x9f", ltBR, ruleBR);
assertNoErrors("0xdeadbeef", ltBR, ruleBR);
assertNoErrors("0x5F6A", ltBR, ruleBR);
assertNoErrors("0o23", ltBR, ruleBR);
assertNoErrors("0o777", ltBR, ruleBR);
assertSingleError("0o8", ltBR, ruleBR, new String[]{}); // bad octal
assertSingleError("0xQ34", ltBR, ruleBR, new String[]{}); // bad hexadecimal
assertNoErrors("0x34Q", ltBR, ruleBR); // this is accepted because of stuff like "5x5m"
}

@Test
public void testPortugueseSpellerIgnoresNonstandardTimeFormat() throws Exception {
// Disambiguator rule; this is a style/typography issue to be taken care of in XML rules
Expand Down