summaryrefslogtreecommitdiffstats
path: root/JLanguageTool/src/java/de/danielnaber/languagetool/rules/sk/SlovakVes.java
blob: 3fff582db47905f28ef1a56f01b6b7866239e0db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* LanguageTool, a natural language style checker
 * Copyright (C) 2010 Luboš Lehotský lubo.lehotsky (at) gmail (dot) com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package de.danielnaber.languagetool.rules.sk;


import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import de.danielnaber.languagetool.AnalyzedSentence;
import de.danielnaber.languagetool.AnalyzedTokenReadings;
import de.danielnaber.languagetool.rules.Category;
import de.danielnaber.languagetool.rules.RuleMatch;


public class SlovakVes extends SlovakRule {

  public SlovakVes(final ResourceBundle messages) {
    if (messages != null) {
      super.setCategory(new Category(messages.getString("category_misc")));
    }
    setDefaultOff();
  }

  @Override
  public final String getId() {
    return "SK_VES";
  }

  @Override
  public final String getDescription() {
    return "Názvy obcí, v ktorých je \"Ves\"";
  }

  @Override
  public final RuleMatch[] match(final AnalyzedSentence text) {
    final List<RuleMatch> ruleMatches = new ArrayList<RuleMatch>();
    final AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();
    // never read        boolean prve_uvodzovky;
    boolean tag, tag2, tag3;
    final String pomoc;
    final char znak;

// never read         prve_uvodzovky = false;
    tag = false;
    tag2 = false;
    tag3 = false;

    pomoc = tokens[1].getToken();
    if (pomoc.length() >= 1) {
      znak = pomoc.charAt(0);
    } else {
      znak = '.';
    }

    if (znak == '?') {
// never read  prve_uvodzovky = true;
    }
    for (int i = 1; i < tokens.length; i++) {
      final String token = tokens[i].getToken();
// never read           String premenna = token.toString();
      final char pomocnik;
// never read           final int help; 
      boolean bodka;
      boolean pady;

      pady = false;
      pomocnik = token.charAt(0);
      bodka = false;
      if (token.charAt(0) == '.' || token.charAt(0) == '?'
              || token.charAt(0) == '!') {
        bodka = true;
      }

      if (tokens[i].hasPosTag("AAfs1x") || tokens[i].hasPosTag("AAfs2x")
              || tokens[i].hasPosTag("AAfs3x")
              || tokens[i].hasPosTag("AAfs4x")
              || tokens[i].hasPosTag("AAfs6x")
              || tokens[i].hasPosTag("AAfs7x")) {
        pady = true;
      }
      if (pady && Character.isUpperCase(pomocnik)) {
        tag = true;
      }

      if (tag && !tag2) {
        if (pady && Character.isLowerCase(pomocnik)) {
          tag2 = true;
          //                   premenna = tokens[i].getToken();
        }

      }

      if (tag2) {
        if (token.equals("Ves") || token.equals("Vsi")
                || token.equals("Vsou")) {
          tag3 = true;
        }
      }
      if (tag3 && !bodka) {
        String spravne;
        char prve;

        prve = tokens[i - 1].getToken().charAt(0);
        prve = Character.toUpperCase(prve);
        spravne = tokens[i - 1].getToken().substring(1,
                tokens[i - 1].getToken().length());

        final String msg = "Zmeňte začiatočné písmeno na veľké: <suggestion> "
                + prve + spravne + " </suggestion>";
        final int pos = tokens[i - 1].getStartPos();
        final int pos2 = tokens[i - 1].getToken().length();
        final RuleMatch ruleMatch = new RuleMatch(this, pos, pos + pos2,
                msg, "Zmeňte začiatočné písmeno na veľké: ");

        ruleMatches.add(ruleMatch);

      }

    }
    return toRuleMatchArray(ruleMatches);
  }

  @Override
  public void reset() {// nothing
  }

}