Skip to content

Commit 55757a0

Browse files
committed
Set Claude to work analyzing all of the javadoc errors and warnings in the util package. Spoiler: it was a lot
1 parent 86b58d6 commit 55757a0

137 files changed

Lines changed: 7326 additions & 156 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/edu/stanford/nlp/util/AbstractIterator.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
/**
66
* Iterator with <code>remove()</code> defined to throw an
77
* <code>UnsupportedOperationException</code>.
8+
*
9+
* @param <E> The type of the elements returned by this iterator
810
*/
911
public abstract class AbstractIterator<E> implements Iterator<E> {
1012

13+
/** Constructor for subclasses. */
14+
public AbstractIterator() { }
15+
1116
/** {@inheritDoc} */
1217
@Override
1318
public abstract boolean hasNext();

‎src/edu/stanford/nlp/util/AcronymMatcher.java‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,44 @@ private static List<String> getMainTokenStrs(String[] tokens) {
208208
return mainTokenStrs;
209209
}
210210

211+
/**
212+
* Filters a list of tokens down to the "main" tokens: the nonempty ones
213+
* which are at least 4 characters long or start with an uppercase letter.
214+
*
215+
* @param tokens The tokens to filter
216+
* @return A new list containing the main tokens, in their original order
217+
*/
211218
public static List<String> getMainStrs(List<String> tokens) {
212219
List<String> mainTokenStrs = new ArrayList<>(tokens.size());
213220
mainTokenStrs.addAll(tokens.stream().filter(text -> !text.isEmpty() && (text.length() >= 4 || Character.isUpperCase(text.charAt(0)))).collect(Collectors.toList()));
214221
return mainTokenStrs;
215222
}
216223

224+
/**
225+
* Returns true if the given string is an acronym of the given tokens.
226+
*
227+
* @param str The candidate acronym
228+
* @param tokens The tokens of the candidate expansion
229+
* @return true if {@code str} is an acronym of {@code tokens}
230+
* @see AcronymMatcher#isAcronymImpl(String, List)
231+
*/
217232
public static boolean isAcronym(String str, String[] tokens) {
218233
return isAcronymImpl(str, Arrays.asList(tokens));
219234
}
220235

221236
// Public static utility methods
222237

238+
/**
239+
* Returns true if the given string is an acronym of the given tokens.
240+
* The characters '-', '.' and '_' are first removed from {@code str}; if its length
241+
* then differs from the number of tokens, stopwords are removed from the tokens.
242+
* It is an acronym if each character matches (case-insensitively) the first
243+
* character of the corresponding token. Empty tokens match any character.
244+
*
245+
* @param str The candidate acronym
246+
* @param tokens The tokens of the candidate expansion
247+
* @return true if {@code str} is an acronym of {@code tokens}
248+
*/
223249
public static boolean isAcronymImpl(String str, List<String> tokens) {
224250
// Remove some words from the candidate acronym
225251
str = discardPattern.matcher(str).replaceAll("");
@@ -242,6 +268,16 @@ public static boolean isAcronymImpl(String str, List<String> tokens) {
242268
}
243269
}
244270

271+
/**
272+
* Returns true if the given string is an acronym of the given tokens.
273+
* Tokens which are {@link CoreMap}s contribute their text annotation;
274+
* any other object contributes its {@code toString()}.
275+
*
276+
* @param str The candidate acronym
277+
* @param tokens The tokens of the candidate expansion
278+
* @return true if {@code str} is an acronym of {@code tokens}
279+
* @see AcronymMatcher#isAcronymImpl(String, List)
280+
*/
245281
public static boolean isAcronym(String str, List<?> tokens) {
246282
List<String> strs = new ArrayList<>(tokens.size());
247283
for (Object tok : tokens) {
@@ -259,6 +295,8 @@ public static boolean isAcronym(String str, List<?> tokens) {
259295
/**
260296
* Returns true if either chunk1 or chunk2 is acronym of the other.
261297
*
298+
* @param chunk1 The first chunk, with text and tokens annotations
299+
* @param chunk2 The second chunk, with text and tokens annotations
262300
* @return true if either chunk1 or chunk2 is acronym of the other
263301
*/
264302
public static boolean isAcronym(CoreMap chunk1, CoreMap chunk2) {
@@ -276,7 +314,15 @@ public static boolean isAcronym(CoreMap chunk1, CoreMap chunk2) {
276314
return isAcro;
277315
}
278316

279-
/** @see AcronymMatcher#isAcronym(edu.stanford.nlp.util.CoreMap, edu.stanford.nlp.util.CoreMap) */
317+
/**
318+
* Returns true if either chunk1 or chunk2 is acronym of the other.
319+
* The text of each chunk is its tokens joined with spaces.
320+
*
321+
* @param chunk1 The tokens of the first chunk
322+
* @param chunk2 The tokens of the second chunk
323+
* @return true if either chunk1 or chunk2 is acronym of the other
324+
* @see AcronymMatcher#isAcronym(edu.stanford.nlp.util.CoreMap, edu.stanford.nlp.util.CoreMap)
325+
*/
280326
public static boolean isAcronym(String[] chunk1, String[] chunk2) {
281327
String text1 = StringUtils.join(chunk1);
282328
String text2 = StringUtils.join(chunk2);
@@ -292,6 +338,15 @@ public static boolean isAcronym(String[] chunk1, String[] chunk2) {
292338
return isAcro;
293339
}
294340

341+
/**
342+
* Returns true if either chunk1 or chunk2 is a "fancy" acronym of the other,
343+
* as determined by {@link #isFancyAcronymImpl(String, List)}.
344+
* The text of each chunk is its tokens joined with spaces.
345+
*
346+
* @param chunk1 The tokens of the first chunk
347+
* @param chunk2 The tokens of the second chunk
348+
* @return true if either chunk is a fancy acronym of the other
349+
*/
295350
public static boolean isFancyAcronym(String[] chunk1, String[] chunk2) {
296351
String text1 = StringUtils.join(chunk1);
297352
String text2 = StringUtils.join(chunk2);
@@ -301,6 +356,14 @@ public static boolean isFancyAcronym(String[] chunk1, String[] chunk2) {
301356
return isFancyAcronymImpl(text1, tokenStrs2) || isFancyAcronymImpl(text2, tokenStrs1);
302357
}
303358

359+
/**
360+
* Returns true if the characters of {@code str} (after removing '-', '.' and '_')
361+
* occur in order, case-sensitively, in the space-joined text of the tokens.
362+
*
363+
* @param str The candidate acronym
364+
* @param tokens The tokens of the candidate expansion
365+
* @return true if {@code str} is a fancy acronym of {@code tokens}
366+
*/
304367
public static boolean isFancyAcronymImpl(String str, List<String> tokens) {
305368
str = discardPattern.matcher(str).replaceAll("");
306369
String text = StringUtils.join(tokens);

‎src/edu/stanford/nlp/util/ArgumentParser.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,37 @@ public class ArgumentParser {
6868

6969
private ArgumentParser() {} // static class
7070

71+
/** Marks a field as an option which can be filled from properties or command-line arguments. */
7172
@Documented
7273
@Retention(RetentionPolicy.RUNTIME)
7374
@Target(ElementType.FIELD)
7475
public @interface Option {
76+
/**
77+
* The name of the option (matched case-insensitively).
78+
*
79+
* @return The option name; if empty, the field name is used
80+
*/
7581
String name() default "";
7682

83+
/**
84+
* A description of the option, shown in usage messages.
85+
*
86+
* @return The description of the option
87+
*/
7788
String gloss() default "";
7889

90+
/**
91+
* Whether the option must be set; if a required option is missing, filling options throws an exception.
92+
*
93+
* @return true if the option is required
94+
*/
7995
boolean required() default false;
8096

97+
/**
98+
* Alternate names for the option.
99+
*
100+
* @return A comma-separated list of alternate names, or empty for none
101+
*/
81102
String alt() default "";
82103
}
83104

@@ -89,10 +110,13 @@ private ArgumentParser() {} // static class
89110
ArgumentParser.class,
90111
};
91112

113+
/** The classes to fill options in; if null, all classes visible on the classpath are searched. */
92114
@Option(name = "option_classes", gloss = "Fill options from these classes")
93115
public static Class<?>[] optionClasses; // = null;
116+
/** The number of threads to use; defaults to the number of available processors. */
94117
@Option(name = "threads", gloss = "Number of threads on machine")
95118
public static int threads = Runtime.getRuntime().availableProcessors();
119+
/** The host name of this machine, or "(unknown)" if it could not be determined. */
96120
@Option(name = "host", gloss = "Name of computer we are running on")
97121
public static String host = "(unknown)";
98122
@SuppressWarnings({"FieldCanBeLocal", "RedundantFieldInitialization"})

‎src/edu/stanford/nlp/util/ArrayCoreMap.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ public void compact() {
261261
}
262262
}
263263

264+
/**
265+
* Reallocates the internal arrays to hold exactly newSize entries.
266+
*
267+
* @param newSize The new capacity
268+
* @throws RuntimeException if newSize is smaller than the current size
269+
*/
264270
public void setCapacity(int newSize) {
265271
if (size > newSize) { throw new RuntimeException("You cannot set capacity to smaller than the current size."); }
266272
Class[] newKeys = new Class[newSize];

‎src/edu/stanford/nlp/util/ArrayHeap.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @author Dan Klein
1919
* @author Christopher Manning
2020
* @version 1.2, 07/31/02
21+
* @param <E> the type of elements held in the heap
2122
*/
2223
public class ArrayHeap<E> extends AbstractSet<E> implements Heap<E> {
2324

@@ -283,12 +284,21 @@ public void clear() {
283284
objectToEntry.clear();
284285
}
285286

287+
/**
288+
* Logs each array position with the score of its entry, in array order.
289+
* All elements must implement {@link Scored}, or a ClassCastException is thrown.
290+
*/
286291
public void dump() {
287292
for (int j = 0; j < indexToEntry.size(); j++) {
288293
log.info(" " + j + " " + ((Scored) indexToEntry.get(j).object).score());
289294
}
290295
}
291296

297+
/**
298+
* Checks the heap ordering and the stored array positions, logging any problems.
299+
* If the ordering is violated, the heap is dumped and the JVM is exited
300+
* (with status 0).
301+
*/
292302
public void verify() {
293303
for (int i = 0; i < indexToEntry.size(); i++) {
294304
if (i != 0) {
@@ -316,12 +326,22 @@ public ArrayHeap(Comparator<? super E> cmp) {
316326
objectToEntry = Generics.newHashMap();
317327
}
318328

329+
/** Create an ArrayHeap with the given initial capacity.
330+
*
331+
* @param cmp The objects added will be ordered using the {@code Comparator}.
332+
* @param initCapacity The initial capacity of the backing list and map
333+
*/
319334
public ArrayHeap(Comparator<? super E> cmp, int initCapacity) {
320335
this.cmp = cmp;
321336
indexToEntry = new ArrayList<>(initCapacity);
322337
objectToEntry = Generics.newHashMap(initCapacity);
323338
}
324339

340+
/**
341+
* Returns the elements in a new LinkedList, in the heap's iteration (sorted) order.
342+
*
343+
* @return A new list of the heap's elements in sorted order
344+
*/
325345
public List<E> asList() {
326346
return new LinkedList<>(this);
327347
}

‎src/edu/stanford/nlp/util/ArrayMap.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
*
99
* @author Dan Klein
1010
* @author Roger Levy
11+
*
12+
* @param <K> The type of the keys
13+
* @param <V> The type of the values
1114
*/
1215
public final class ArrayMap<K,V> extends AbstractMap<K,V> implements Serializable {
1316

1417
private static final long serialVersionUID = 1L;
1518

19+
/** The entries; only the first {@code size} slots are in use. */
1620
private Entry<K,V>[] entryArray;
21+
/** The length of {@code entryArray}. */
1722
private int capacity;
23+
/** The number of entries in the map. */
1824
private int size;
1925

2026
static final class Entry<K,V> implements Map.Entry<K,V>, Serializable {
@@ -69,20 +75,31 @@ public String toString() {
6975
}
7076

7177

78+
/** Creates an empty map with an initial capacity of 2. */
7279
@SuppressWarnings("unchecked")
7380
public ArrayMap() {
7481
size = 0;
7582
capacity = 2;
7683
entryArray = new Entry[2];
7784
}
7885

86+
/**
87+
* Creates an empty map with the given initial capacity.
88+
*
89+
* @param capacity The initial length of the backing array
90+
*/
7991
@SuppressWarnings("unchecked")
8092
public ArrayMap(int capacity) {
8193
size = 0;
8294
this.capacity = capacity;
8395
entryArray = new Entry[capacity];
8496
}
8597

98+
/**
99+
* Creates a map containing the entries of {@code m}.
100+
*
101+
* @param m The map whose entries are copied
102+
*/
86103
@SuppressWarnings("unchecked")
87104
public ArrayMap(Map<? extends K, ? extends V> m) {
88105
size = 0;
@@ -91,6 +108,14 @@ public ArrayMap(Map<? extends K, ? extends V> m) {
91108
this.putAll(m);
92109
}
93110

111+
/**
112+
* Creates a map from parallel arrays of keys and values.
113+
* The keys are not checked for duplicates.
114+
*
115+
* @param keys The keys
116+
* @param values The values; {@code values[i]} is the value for {@code keys[i]}
117+
* @throws IllegalArgumentException if the arrays have different lengths
118+
*/
94119
@SuppressWarnings("unchecked")
95120
public ArrayMap(K[] keys, V[] values) {
96121
if (keys.length!=values.length) throw new IllegalArgumentException("different number of keys and values.");
@@ -102,10 +127,25 @@ public ArrayMap(K[] keys, V[] values) {
102127
}
103128
}
104129

130+
/**
131+
* Creates an empty map with the default initial capacity.
132+
*
133+
* @param <K> The type of the keys
134+
* @param <V> The type of the values
135+
* @return A new empty ArrayMap
136+
*/
105137
public static <K, V> ArrayMap<K, V> newArrayMap() {
106138
return new ArrayMap<>();
107139
}
108140

141+
/**
142+
* Creates an empty map with the given initial capacity.
143+
*
144+
* @param <K> The type of the keys
145+
* @param <V> The type of the values
146+
* @param capacity The initial length of the backing array
147+
* @return A new empty ArrayMap
148+
*/
109149
public static <K, V> ArrayMap<K, V> newArrayMap(int capacity) {
110150
return new ArrayMap<>(capacity);
111151
}
@@ -198,6 +238,10 @@ public V remove(Object key) {
198238
return null;
199239
}
200240

241+
/**
242+
* Cached value of {@link #hashCode()}; 0 means not yet computed.
243+
* It is not reset when the map is modified.
244+
*/
201245
protected int hashCodeCache; // = 0;
202246

203247
@Override

‎src/edu/stanford/nlp/util/ArraySet.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
/**
1010
* An array-backed set.
11+
*
12+
* @param <E> the type of elements in the set
1113
* @author Roger Levy (rog@stanford.edu)
1214
*/
1315
public class ArraySet<E> extends AbstractSet<E> implements Serializable {
1416

17+
/** The list holding the elements of the set. */
1518
private final List<E> backer;
1619

1720
/**
@@ -24,6 +27,7 @@ public ArraySet() {
2427
/**
2528
* Constructs an ArraySet, using the given list as the backing collection.
2629
* Note that this is not a copy constructor!
30+
* @param source the list to use (not copied) as the backing collection
2731
*/
2832
public ArraySet(List<E> source) {
2933
this.backer = source;

0 commit comments

Comments
 (0)