Class PatternRuleMatcher

    • Field Detail

      • currentlyActiveRules

        private static final java.util.Map<java.lang.String,​java.lang.Integer> currentlyActiveRules
      • SUGGESTION_START_TAG

        private static final java.lang.String SUGGESTION_START_TAG
        See Also:
        Constant Field Values
      • SUGGESTION_END_TAG

        private static final java.lang.String SUGGESTION_END_TAG
        See Also:
        Constant Field Values
      • useList

        private final boolean useList
      • monitorRules

        private final boolean monitorRules
    • Constructor Detail

      • PatternRuleMatcher

        PatternRuleMatcher​(PatternRule rule,
                           boolean useList)
    • Method Detail

      • getCurrentRules

        public static java.util.Map<java.lang.String,​java.lang.Integer> getCurrentRules()
      • createRuleMatch

        @Nullable
        private @Nullable RuleMatch createRuleMatch​(java.util.List<java.lang.Integer> tokenPositions,
                                                    AnalyzedTokenReadings[] tokens,
                                                    int firstMatchToken,
                                                    int lastMatchToken,
                                                    int firstMarkerMatchToken,
                                                    int lastMarkerMatchToken,
                                                    AnalyzedSentence sentence)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • matchPreservesCase

        private boolean matchPreservesCase​(java.util.List<Match> suggestionMatches,
                                           java.lang.String msg)
        Checks if the suggestion starts with a match that is supposed to preserve case. If it does not, perform the default conversion to uppercase.
        Returns:
        true, if the match preserves the case of the token.
      • translateElementNo

        private int translateElementNo​(int i)
        Gets the index of the element indexed by i, adding any offsets because of the phrases in the rule.
        Parameters:
        i - Current element index.
        Returns:
        int Index translated into XML element no.
      • formatMatches

        private java.lang.String formatMatches​(AnalyzedTokenReadings[] tokenReadings,
                                               java.util.List<java.lang.Integer> positions,
                                               int firstMatchTok,
                                               java.lang.String errorMsg,
                                               java.util.List<Match> suggestionMatches)
                                        throws java.io.IOException
        Replace back references generated with <match> and \\1 in message using Match class, and take care of skipping.
        Parameters:
        tokenReadings - Array of AnalyzedTokenReadings that were matched against the pattern
        positions - Array of relative positions of matched tokens
        firstMatchTok - Position of the first matched token
        errorMsg - String containing suggestion markup
        Returns:
        String Formatted message.
        Throws:
        java.io.IOException
      • concatWithoutExtraSpace

        private static java.lang.String concatWithoutExtraSpace​(java.lang.String leftSide,
                                                                java.lang.String rightSide)
      • formatMultipleSynthesis

        static java.lang.String formatMultipleSynthesis​(java.lang.String[] matches,
                                                        java.lang.String leftSide,
                                                        java.lang.String rightSide)
      • concatMatches

        private java.lang.String[] concatMatches​(int start,
                                                 int index,
                                                 int tokenIndex,
                                                 AnalyzedTokenReadings[] tokens,
                                                 int nextTokenPos,
                                                 java.util.List<Match> suggestionMatches)
                                          throws java.io.IOException
        Concatenates the matches, and takes care of phrases (including inflection using synthesis).
        Parameters:
        start - Position of the element as referenced by match element in the rule.
        index - The index of the element found in the matching sentence.
        tokenIndex - The position of the token in the AnalyzedTokenReadings array.
        tokens - Array of AnalyzedTokenReadings
        Returns:
        Throws:
        java.io.IOException
      • phraseLen

        private int phraseLen​(int i)
      • combineLists

        private static java.lang.String[] combineLists​(java.lang.String[][] input,
                                                       java.lang.String[] output,
                                                       int r,
                                                       Language lang)
        Creates a Cartesian product of the arrays stored in the input array.
        Parameters:
        input - Array of string arrays to combine.
        output - Work array of strings.
        r - Starting parameter (use 0 to get all combinations).
        lang - Text language for adding spaces in some languages.
        Returns:
        Combined array of String.