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] Fixed tons of FPs "nouns -> verbs" in disambiguation.xml #10926

Merged
merged 3 commits into from
Oct 18, 2024

Conversation

marcoagpinto
Copy link
Member

@marcoagpinto marcoagpinto commented Oct 13, 2024

Heya, @jaumeortola , @susanaboatto and @p-goulart

This is a disambiguator rule to fix nouns appearing as verbs.

I have fixed 4686 false positives while testing against 950 000 sentences.

I just gave a brief look at the .txt, and it appears to be fine, but here it is anyway.

Dummy rule for testing:

<rulegroup id='MARCOAGPINTO_DIS_VERBO_SUBSTANTIVO' name="Disambiguator: Converter Verbo para Substantivo">
    <rule>
      <pattern>
        <token postag="V.+" postag_regexp="yes"/>
        <token min='1' max='2' postag="D[AI].+|PP.+|Z0.+" postag_regexp="yes"/>
        <marker>
          <and>
            <token postag="VMIP2S0|VMN02S0|VMSF2S0" postag_regexp="yes"/>
            <token postag="NC.+" postag_regexp="yes"/>
          </and>
        </marker>
      </pattern>
        <message>Regra a testar o Disambiguator.</message>
        <short>Testar o Disambiguator.</short>
        <example correction=''><marker>Quero os marines.</marker></example>
    </rule>
</rulegroup>
SentenceSourceChecker: org.languagetool.dev.dumpcheck.DocumentLimitReachedException: Maximum number of documents (950000) reached
Portuguese (Portugal): 4686 total matches
Portuguese (Portugal): 949999 total sentences considered

_0.txt

Summary by CodeRabbit

  • New Features

    • Introduced a new disambiguation rule for rare parts of speech in Portuguese.
  • Improvements

    • Updated existing rules for better handling of the adverb "tão" and expanded patterns for compound conjunctions.
    • Enhanced grammar checking capabilities for complex sentence structures.
  • Documentation

    • Commented out example sentences in the grammar and style files for potential future reference, maintaining structure for clarity.
  • Formatting

    • Improved readability and consistency in rule definitions.

Copy link
Contributor

coderabbitai bot commented Oct 13, 2024

Walkthrough

The changes in this pull request focus on the disambiguation.xml, grammar.xml, and style.xml files for the Portuguese language module in LanguageTool. Key modifications include the addition of a new rule in the RARE_POS group, updates to the TAO_ADV rule, and expansion of the CONJ_COMPOSTAS rule group. Additionally, certain example sentences have been commented out in both the grammar.xml and style.xml files, indicating potential changes or removals. Improvements in formatting and consistency have been made throughout the files.

Changes

File Change Summary
languagetool-language-modules/pt/src/main/resources/org/languagetool/resource/pt/disambiguation.xml - Added new rule in RARE_POS group.
- Modified TAO_ADV rule for clearer patterns.
- Expanded CONJ_COMPOSTAS rule group with new patterns.
- Commented out certain sections indicating potential changes.
- Improved formatting and consistency throughout.
languagetool-language-modules/pt/src/main/resources/org/languagetool/rules/pt/grammar.xml - Commented out example sentence <example>foi sem honra nenhuma abandonado</example>.
languagetool-language-modules/pt/src/main/resources/org/languagetool/rules/pt/style.xml - Commented out several <example> entries across different sections for future reference.

Possibly related PRs

Suggested reviewers

  • p-goulart
  • susanaboatto

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
languagetool-language-modules/pt/src/main/resources/org/languagetool/resource/pt/disambiguation.xml (5)

228-240: Approved: New rule for disambiguating noun/verb ambiguity

This new rule in the RARE_POS group is a valuable addition for disambiguating words that can be both nouns and verbs. The pattern effectively identifies contexts where the ambiguous word is more likely to be a noun, improving the accuracy of part-of-speech tagging.

Consider adding a comment explaining the rationale behind this rule, including examples of words it's designed to handle. This would improve maintainability and make it easier for other contributors to understand and extend the rule if needed.


Line range hint 1068-1570: Approved: Comprehensive updates to English word identification rules

The modifications and additions to the IGNORE_ENGLISH_WORDS rule group significantly enhance LanguageTool's ability to identify and label English words within Portuguese text. The rules cover a wide range of scenarios, including single words, phrases, contractions, and possessives. The use of the IsEnglishWordFilter class adds an extra layer of validation, reducing false positives.

To further improve this rule group, consider implementing a mechanism to handle false positives for words that exist in both English and Portuguese (e.g., "coma", "pasta"). This could involve creating a list of such words and adding exceptions to the relevant rules. Additionally, you might want to add rules to handle common English acronyms and initialisms that might appear in Portuguese text.


Line range hint 1572-1665: Approved: New rule group for contextual English word identification

The new IGNORE_WORDS_AROUND_ENGLISH_WORDS rule group is an excellent addition to the disambiguation process. It effectively extends the identification of English words by considering the context around already identified English words. This approach can significantly improve the accuracy of English word detection in Portuguese text, especially for less common words or proper nouns that might not be in the primary English word list.

To further enhance this rule group, consider adding a rule to handle hyphenated words where one part is already identified as English. For example, if you encounter a word like "cloud-based" and "cloud" is already identified as English, it would be beneficial to mark the entire hyphenated word as English. This could help catch compound words or technical terms that are commonly used in English but might not be in the primary English word list.


Line range hint 1667-1675: Approved: Enhanced handling of words with national prefixes

The modification to the NATIONAL_PREFIXES rule group is a valuable improvement. By ignoring spelling for words that start with national prefixes followed by a hyphen, the system can better handle compound words that may not be in the dictionary but are likely to be correct. This is particularly useful for newly formed words or less common combinations that are nevertheless valid in Portuguese.

To make this rule even more robust, consider adding a check for the second part of the compound word (after the hyphen). You could verify if this part exists as a standalone word in the Portuguese dictionary. This additional check would help prevent false positives where a national prefix is followed by a non-existent or misspelled word. For example:

<rule>
    <pattern>
        <marker>
            <token regexp="yes" postag_regexp="yes" postag="(N|A).+">(&national_prefixes;)-<match regexp="[a-záàâãéêíóôõúç]+"/></token>
        </marker>
    </pattern>
    <filter class="org.languagetool.rules.patterns.DictionaryExistsFilter" args="2"/>
    <disambig action="ignore_spelling"/>
</rule>

This modification would ensure that both parts of the compound word are valid, further improving the accuracy of the spell-checking process.


Line range hint 1-1675: Overall assessment: Significant improvements to Portuguese disambiguation rules

The changes made to this disambiguation.xml file represent a substantial enhancement to LanguageTool's ability to process Portuguese text. The additions and modifications focus on several key areas:

  1. Improved disambiguation of words that can be both nouns and verbs.
  2. Enhanced detection and handling of English words within Portuguese text.
  3. Better processing of words with national prefixes.

These improvements will likely result in more accurate part-of-speech tagging, better handling of multilingual content, and improved overall performance of LanguageTool for Portuguese texts.

As the rule set continues to grow and become more complex, consider implementing a system for automated testing of these rules. This could involve creating a comprehensive test suite with various edge cases and multilingual scenarios. Such a system would help ensure that future modifications don't inadvertently break existing functionality and would make it easier to validate the effectiveness of new rules.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7933bef and c224bf8.

📒 Files selected for processing (1)
  • languagetool-language-modules/pt/src/main/resources/org/languagetool/resource/pt/disambiguation.xml (1 hunks)
🧰 Additional context used

@marcoagpinto
Copy link
Member Author

Hello @jaumeortola , @susanaboatto and @p-goulart ,

I have done major fixes in the disambiguator regarding nouns that appear incorrectly as verbs.

I had to comment out examples in grammar.xml and style.xml broken by the new changes.

This is a major improvement which should fix tons and tons and tons of false positives.

Please take your time to review the code.

Thanks!

Dummy rule to test it:

<rulegroup id='MARCOAGPINTO_DIS_VERBO_SUBSTANTIVO' name="Disambiguator: Converter Verbo para Substantivo">
    <rule>
      <pattern>
        <token postag="V.+" postag_regexp="yes"/>
        <token min='1' max='2' postag="(SPS00:)?D[AI].+|PP.+|Z0.+" postag_regexp="yes"/>
        <marker>
          <and>
            <token postag="VMIP2S0|VMN02S0|VMSF2S0|VMIP1S0|VMP00SM" postag_regexp="yes"/>
            <token postag="NC.+" postag_regexp="yes"/>
          </and>
        </marker>
      </pattern>
        <message>Regra a testar o Disambiguator.</message>
        <short>Testar o Disambiguator.</short>
        <example correction=''><marker>Quero os marines.</marker></example>
        <example correction=''><marker>Terminar o curso.</marker></example>
        <example correction=''><marker>Terminar o doutorado.</marker></example>
        <example correction=''><marker>Vendeu o mercado.</marker></example>
        <example correction=''><marker>Vendeu no mercado.</marker></example>
    </rule>
</rulegroup>
SentenceSourceChecker: org.languagetool.dev.dumpcheck.DocumentLimitReachedException: Maximum number of documents (950000) reached
Portuguese (Portugal): 16644 total matches
Portuguese (Portugal): 949999 total sentences considered
Portuguese (Portugal): ø0.02 rule matches per sentence

1_NEW_RULE_20241016.txt

@jaumeortola
Copy link
Member

@marcoagpinto What happens with the examples that you commented out? Are they now FPs? Can you fix them?

@marcoagpinto
Copy link
Member Author

@jaumeortola

They are false positives now, I believe.

I have been terribly stressed and spend the nights rewriting rules.

Maybe they should be left commented out if they are false positives, and then somewhere in time they are replaced?

Right now, I am finishing rewriting and testing another rule.

@marcoagpinto
Copy link
Member Author

I have been basically rewriting pt-PT rules because @p-goulart told me I can approve them myself, so I spend the nights rewriting and approving.

@marcoagpinto
Copy link
Member Author

Anyway, I believe the patch only broke three (3) examples?

There is more gain than loss, I believe.

@marcoagpinto marcoagpinto merged commit 73cda5d into master Oct 18, 2024
5 checks passed
@marcoagpinto marcoagpinto deleted the lt_marcoagpinto_20241013_1044 branch October 18, 2024 17:21
@marcoagpinto
Copy link
Member Author

@jaumeortola

Thank you!

❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️

I was napping.

😛 😛 😛 😛 😛 😛 😛

I spend the nights awaken and try to sleep during the days.

@jaumeortola
Copy link
Member

@marcoagpinto
I see some issues with this change.

  • There are many FPs in with the rule A_WORD, and other rules.
  • There are some test failures in premium rules.

We need to revert the disambiguation rule, and do more tests before adding it.

@marcoagpinto
Copy link
Member Author

@jaumeortola

Please revert it if you can.

I have been since 4am fixing the FPs, but they are too many for me to handle all at once.

It may take more than a day... my guess is that it may take days to review everything.

Thank you!

@marcoagpinto
Copy link
Member Author

@jaumeortola

I found the "revert" button and created a pull request to revert it.

I am looking at the results and I need a few days to fix them.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants