Skip to content

Commit d34a2f3

Browse files
author
Dominika Tkaczyk
committed
regexps corrected and exception handling added
1 parent 9339e13 commit d34a2f3

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

cermine-impl/src/main/java/pl/edu/icm/cermine/bibref/sentiment/CitationPositionFinder.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void findByAuthorYear(String fullText, BibEntry citation, DocumentPositi
107107
}
108108
}
109109

110-
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+et\\s+al\\.\\s+\\((\\d\\d\\d\\d)\\)");
110+
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+et\\s+al\\.\\s+\\((\\d{4})\\)");
111111
refMatcher = refPattern.matcher(fullText);
112112
while (refMatcher.find()) {
113113
String year = refMatcher.group(2);
@@ -119,7 +119,7 @@ private void findByAuthorYear(String fullText, BibEntry citation, DocumentPositi
119119
}
120120
}
121121

122-
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+(and|&)\\s+[A-Z][^\\s\\.]+\\s+\\((\\d\\d\\d\\d)\\)");
122+
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+(and|&)\\s+[A-Z][^\\s\\.]+\\s+\\((\\d{4})\\)");
123123
refMatcher = refPattern.matcher(fullText);
124124
while (refMatcher.find()) {
125125
String year = refMatcher.group(3);
@@ -131,7 +131,7 @@ private void findByAuthorYear(String fullText, BibEntry citation, DocumentPositi
131131
}
132132
}
133133

134-
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+\\((\\d\\d\\d\\d)\\)");
134+
refPattern = Pattern.compile("([A-Z][^\\s\\.]+)\\s+\\((\\d{4})\\)");
135135
refMatcher = refPattern.matcher(fullText);
136136
while (refMatcher.find()) {
137137
String year = refMatcher.group(2);
@@ -164,7 +164,7 @@ private void findByAuthorYearFuzzy(String fullText, BibEntry citation, DocumentP
164164

165165
private void findByNumber(String fullText, BibEntry citation, String leftBracket, String rightBracket,
166166
DocumentPositions positions) {
167-
Pattern numberPattern = Pattern.compile("^[^\\d]{0,10}(\\d+)");
167+
Pattern numberPattern = Pattern.compile("^[^\\d]{0,10}(\\d{1,5})");
168168
Matcher numberMatcher = numberPattern.matcher(citation.getText());
169169
String number;
170170
if (numberMatcher.find()) {
@@ -181,14 +181,16 @@ private void findByNumber(String fullText, BibEntry citation, String leftBracket
181181
if (number.equals(match)) {
182182
positions.addPosition(citation, refMatcher.start(1), refMatcher.end(1));
183183
} else {
184-
Pattern rangePattern = Pattern.compile("^(\\d+)[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d+)$");
184+
Pattern rangePattern = Pattern.compile("^(\\d{1,5})[" + String.valueOf(CharacterUtils.DASH_CHARS) + "](\\d{1,5})$");
185185
Matcher rangeMatcher = rangePattern.matcher(match);
186186
if (rangeMatcher.find()) {
187-
int lower = Integer.parseInt(rangeMatcher.group(1));
188-
int upper = Integer.parseInt(rangeMatcher.group(2));
189-
if (TextUtils.isNumberBetween(number, lower, upper+1)) {
190-
positions.addPosition(citation, refMatcher.start(1), refMatcher.end(1));
191-
}
187+
try {
188+
int lower = Integer.parseInt(rangeMatcher.group(1));
189+
int upper = Integer.parseInt(rangeMatcher.group(2));
190+
if (TextUtils.isNumberBetween(number, lower, upper+1)) {
191+
positions.addPosition(citation, refMatcher.start(1), refMatcher.end(1));
192+
}
193+
} catch (NumberFormatException e) {}
192194
}
193195
}
194196
}

0 commit comments

Comments
 (0)