Git Product home page Git Product logo

Comments (1)

f-knorr avatar f-knorr commented on July 20, 2024

Some ideas to approach this issue:

  1. Start at PatternRuleMatcher.formatMatches
  2. If you replace the body of the if(!newWay)-block by
            int skipped = 0;
            String replacement = tokenReadings[firstMatchTok + repTokenPos - 1].getToken();
            if (j >= patternTokenMatchers.size()) {
              //System.err.println("Rule "+rule.getFullId()+" refers to token \\"+(j+1)+" but has only "+patternTokenMatchers.size()+" tokens.");
            } else if(patternTokenMatchers.get(j).getPatternToken().getMaxOccurrence() > 1 &&
                      (j == 0 || patternTokenMatchers.get(j-1).getPatternToken().getSkipNext() < 1)) {
              // for matched tokens with max="x" where x > 1, the entire token is returned
              for (int idx = positions.get(j) - 1; idx > 0; idx--) {
                skipped++;
                replacement = tokenReadings[firstMatchTok + repTokenPos - 1 - skipped].getToken().concat(" ").concat(replacement);
              }
            }
          // in case <match> elements weren't used (yet)
          errorMessage = errorMessage.replace("\\" + (j + 1),
              replacement);

The following rule will work correctly:

        <rule id="test_referencing_token_with_max" name="Test referencing a token by \y with max='x', where x > 1">
            <pattern>
                <token max="2">abc</token>
                <token max="2">def</token>
            </pattern>
            <message>A repeated token should be repeated in the suggestion: <suggestion>\1first \2second</suggestion></message>
            <example correction="abc abcfirst defsecond">That's <marker>abc abc def</marker>.</example>
            <example correction="abc abcfirst def defsecond">That's <marker>abc abc def def</marker>.</example>
            <example correction="abcfirst defsecond">That's <marker>abc def</marker>.</example>
        </rule>

However, this will not change the behavior of rule where the referencing is done by <match no="1"/> (= newWay = true)

from languagetool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.