Revision: 17594
http://sourceforge.net/p/gate/code/17594
Author: markagreenwood
Date: 2014-03-08 12:07:09 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
generics in the gaz, and added some finally blocks to ensure streams are
properly closed
Modified Paths:
--------------
gate/trunk/src/main/gate/creole/gazetteer/LinearDefinition.java
gate/trunk/src/main/gate/creole/morph/FSMState.java
gate/trunk/src/main/gate/creole/morph/Interpret.java
gate/trunk/src/main/gate/creole/morph/Morph.java
gate/trunk/src/main/gate/creole/morph/ParsingFunctions.java
gate/trunk/src/main/gate/creole/morph/PatternParser.java
gate/trunk/src/main/gate/creole/morph/ReadFile.java
gate/trunk/src/main/gate/creole/morph/StringSet.java
gate/trunk/src/main/gate/creole/nerc/EntityDescriptor.java
gate/trunk/src/main/gate/creole/nerc/EntitySet.java
gate/trunk/src/main/gate/creole/orthomatcher/BasicAnnotationOrthography.java
gate/trunk/src/main/gate/creole/orthomatcher/OrthoMatcher.java
Modified: gate/trunk/src/main/gate/creole/gazetteer/LinearDefinition.java
===================================================================
--- gate/trunk/src/main/gate/creole/gazetteer/LinearDefinition.java
2014-03-08 10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/gazetteer/LinearDefinition.java
2014-03-08 12:07:09 UTC (rev 17594)
@@ -410,7 +410,7 @@
* when reading the list.
*
* @param index
- * @param o
+ * @param ln
*/
@Override
public void add(int index, LinearNode ln) {
Modified: gate/trunk/src/main/gate/creole/morph/FSMState.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/FSMState.java 2014-03-08 10:03:19 UTC
(rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/FSMState.java 2014-03-08 12:07:09 UTC
(rev 17594)
@@ -1,13 +1,14 @@
package gate.creole.morph;
import java.util.ArrayList;
+import java.util.List;
public class FSMState {
private CharMap transitionFunction = new CharMap();
public static final byte CHILD_STATE = 0;
public static final byte ADJ_STATE = 1;
private int index = 0;
- private ArrayList rhses = new ArrayList();
+ private List<RHS> rhses = new ArrayList<RHS>();
public FSMState(int index) {
this.index = index;
@@ -25,7 +26,7 @@
transitionFunction.put(chr, state, type);
}
- public ArrayList getRHSes() {
+ public List<RHS> getRHSes() {
return rhses;
}
Modified: gate/trunk/src/main/gate/creole/morph/Interpret.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/Interpret.java 2014-03-08
10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/Interpret.java 2014-03-08
12:07:09 UTC (rev 17594)
@@ -52,8 +52,8 @@
MorphFunctions morphInst;
- List patterns = new ArrayList();
- List fsms = new ArrayList();
+ List<Pattern> patterns = new ArrayList<Pattern>();
+ List<List<CharClass>> fsms = new ArrayList<List<CharClass>>();
/**
* The initial state of the FSM that backs this morpher
@@ -108,12 +108,12 @@
public void addState(char ch, FSMState fsm, int index) {
if(index == fsms.size()) {
- fsms.add(new ArrayList());
+ fsms.add(new ArrayList<CharClass>());
}
- List fs = (List) fsms.get(index);
+ List<CharClass> fs = fsms.get(index);
for(int i=0;i<fs.size();i++) {
- CharClass cc = (CharClass) fs.get(i);
+ CharClass cc = fs.get(i);
if(cc.ch == ch)
return;
}
@@ -127,20 +127,20 @@
public FSMState getState(char ch, int index) {
if(index >= fsms.size()) return null;
- List fs = (List) fsms.get(index);
+ List<CharClass> fs = fsms.get(index);
for(int i=0;i<fs.size();i++) {
- CharClass cc = (CharClass) fs.get(i);
+ CharClass cc = fs.get(i);
if(cc.ch == ch)
return cc.st;
}
return null;
}
- private Set getStates(char ch, Set states) {
- Set newStates = new HashSet();
- Iterator iter = states.iterator();
+ private Set<FSMState> getStates(char ch, Set<FSMState> states) {
+ Set<FSMState> newStates = new HashSet<FSMState>();
+ Iterator<FSMState> iter = states.iterator();
while (iter.hasNext()) {
- FSMState st = (FSMState) iter.next();
+ FSMState st = iter.next();
FSMState chState = st.next(ch, FSMState.CHILD_STATE);
if (chState != null) {
newStates.add(chState);
@@ -175,7 +175,7 @@
}
foundRule = false;
- Set states = new HashSet();
+ Set<FSMState> states = new HashSet<FSMState>();
states.add(initialState);
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
@@ -195,9 +195,9 @@
}
});
- Iterator iter = states.iterator();
+ Iterator<FSMState> iter = states.iterator();
while (iter.hasNext()) {
- FSMState st = (FSMState) iter.next();
+ FSMState st = iter.next();
rhses.addAll(st.getRHSes());
}
@@ -213,13 +213,13 @@
return patternIndex;
}
- protected String executeRHSes(SortedSet rhses, String word, String
category) {
+ protected String executeRHSes(SortedSet<RHS> rhses, String word, String
category) {
foundRule = false;
// rhses are in sorted order
// we need to check if the word is compatible with pattern
- Iterator rhsiter = rhses.iterator();
+ Iterator<RHS> rhsiter = rhses.iterator();
while (rhsiter.hasNext()){
- RHS r1 = (RHS) rhsiter.next();
+ RHS r1 = rhsiter.next();
String answer = executeRHS(word, category, r1);
if (foundRule) {
@@ -244,7 +244,7 @@
}
private String executeRule(String word, RHS rhs) {
- Pattern p = (Pattern) patterns.get(rhs.getPatternIndex());
+ Pattern p = patterns.get(rhs.getPatternIndex());
short methodIndex = rhs.getMethodIndex();
if (!p.matcher(word).matches()) {
@@ -525,9 +525,9 @@
patterns.add(Pattern.compile(regExp));
String[] rules = ParsingFunctions.normlizePattern(regExp);
for (int m = 0; m < rules.length; m++) {
- Set lss = new HashSet();
+ Set<Set<FSMState>> lss = new HashSet<Set<FSMState>>();
lss.clear();
- Set newSet = new HashSet();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.add(initialState);
lss.add(newSet);
PatternPart parts[] = ParsingFunctions
@@ -535,12 +535,12 @@
for (int j = 0; j < parts.length; j++) {
lss =
ParsingFunctions.createFSMs(parts[j].getPartString(), parts[j].getType(), lss,
this);
}
- Iterator iter = lss.iterator();
+ Iterator<Set<FSMState>> iter = lss.iterator();
while (iter.hasNext()) {
- Set set = (HashSet) iter.next();
- Iterator subIter = set.iterator();
+ Set<FSMState> set = iter.next();
+ Iterator<FSMState> subIter = set.iterator();
while (subIter.hasNext()) {
- FSMState st = (FSMState) subIter.next();
+ FSMState st = subIter.next();
st.addRHS(rhs);
}
}
@@ -548,8 +548,8 @@
//drawFSM();
}
- private Set intersect(Set a, Set b) {
- Set result = new HashSet();
+ private Set<FSMState> intersect(Set a, Set b) {
+ Set<FSMState> result = new HashSet<FSMState>();
Iterator iter = a.iterator();
while (iter.hasNext()) {
FSMState st = (FSMState) iter.next();
Modified: gate/trunk/src/main/gate/creole/morph/Morph.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/Morph.java 2014-03-08 10:03:19 UTC
(rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/Morph.java 2014-03-08 12:07:09 UTC
(rev 17594)
@@ -54,6 +54,8 @@
extends AbstractLanguageAnalyser
implements ProcessingResource, CustomDuplication {
+ private static final long serialVersionUID = 6964689654685956128L;
+
/** File which contains rules to be processed */
protected URL rulesFile;
Modified: gate/trunk/src/main/gate/creole/morph/ParsingFunctions.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/ParsingFunctions.java 2014-03-08
10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/ParsingFunctions.java 2014-03-08
12:07:09 UTC (rev 17594)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import java.util.Stack;
@@ -123,19 +124,20 @@
public static String[] normlizePattern(String line) {
- ArrayList patterns = PatternParser.parsePattern(line);
- String[] pats = new String[patterns.size()];
+ List<String> patterns = PatternParser.parsePattern(line);
+ /*String[] pats = new String[patterns.size()];
for(int i=0;i<patterns.size();i++) {
- pats[i] = (String) patterns.get(i);
+ pats[i] = patterns.get(i);
}
- return pats;
+ return pats;*/
+ return patterns.toArray(new String[patterns.size()]);
}
public static PatternPart[] getPatternParts(String line) {
// the first thing we do is replace all variables with their
respective
// values
- ArrayList patterns = new ArrayList();
+ List<PatternPart> patterns = new ArrayList<PatternPart>();
line = line.replaceAll("[\\(]+","(");
line = line.replaceAll("[\\)]+",")");
line = line.replaceAll("[\\[]+","[");
@@ -263,7 +265,7 @@
PatternPart[] parts = new PatternPart[patterns.size()];
for(int i=0;i<patterns.size();i++) {
- parts[i] = (PatternPart) patterns.get(i);
+ parts[i] = patterns.get(i);
}
return parts;
}
@@ -379,12 +381,12 @@
return parameters;
}
- public static Set createFSMs(String string, int type, Set initStates,
Interpret owner) {
- Set result = new HashSet();
+ public static Set<Set<FSMState>> createFSMs(String string, int type,
Set<Set<FSMState>> initStates, Interpret owner) {
+ Set<Set<FSMState>> result = new HashSet<Set<FSMState>>();
// we create different groups for states
- Iterator iter = initStates.iterator();
+ Iterator<Set<FSMState>> iter = initStates.iterator();
while(iter.hasNext()) {
- HashSet states = (HashSet) iter.next();
+ Set<FSMState> states = iter.next();
switch (type) {
case OR:
result.addAll(orFSMs(string, states, owner));
@@ -411,10 +413,10 @@
}
- private static FSMState next(char ch, HashSet states) {
- Iterator iter = states.iterator();
+ private static FSMState next(char ch, Set<FSMState> states) {
+ Iterator<FSMState> iter = states.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
FSMState nextState = state.next(ch,
FSMState.CHILD_STATE);
if(nextState != null)
return nextState;
@@ -422,10 +424,10 @@
return null;
}
- private static int getIndex(HashSet states) {
- Iterator iter = states.iterator();
+ private static int getIndex(Set<FSMState> states) {
+ Iterator<FSMState> iter = states.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
return state.getIndex();
}
return -1;
@@ -435,7 +437,7 @@
/**
* (abc) -> a -> b -> c ->
*/
- public static ArrayList andFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> andFSMs(String line, Set<FSMState>
initStates, Interpret owner) {
// for the first inital State
// we need to find out if any of the parent contains referece
to it
char ch = line.charAt(0);
@@ -450,9 +452,9 @@
// currentState contains the first state
// this should be added as a child state to all initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState, FSMState.CHILD_STATE);
}
@@ -474,8 +476,8 @@
}
currentState = nextState;
}
- ArrayList nextStates = new ArrayList();
- HashSet newSet = new HashSet();
+ List<Set<FSMState>> nextStates = new ArrayList<Set<FSMState>>();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.add(nextState);
nextStates.add(newSet);
return nextStates;
@@ -486,11 +488,11 @@
* -> b,
* -> c
*/
- public static ArrayList orFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> orFSMs(String line, Set<FSMState>
initStates, Interpret owner) {
// for each character in the line
// we need to find out if any of the initStates contain
reference to it
// if so that should be assigned to all initStates
- HashSet nextStates = new HashSet();
+ Set<FSMState> nextStates = new HashSet<FSMState>();
for(int i=0;i<line.length();i++) {
// for the current character
// we need to find out if any of the parent contains
referece to it
@@ -509,14 +511,14 @@
// currentState contains refenrece for the current
character
// this should be added as a child state to all
initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState,
FSMState.CHILD_STATE);
}
}
- ArrayList newList = new ArrayList();
+ List<Set<FSMState>> newList = new ArrayList<Set<FSMState>>();
newList.add(nextStates);
return newList;
}
@@ -525,11 +527,11 @@
* [abc]+
* each element can travel to itself and can travel to next one
*/
- public static ArrayList orPlusFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> orPlusFSMs(String line, Set<FSMState>
initStates, Interpret owner) {
// for each character in the line
// we need to find out if any of the initStates contain
reference to it
// if so that should be assigned to all initStates
- ArrayList nextStates = new ArrayList();
+ List<FSMState> nextStates = new ArrayList<FSMState>();
for(int i=0;i<line.length();i++) {
// for the current character
// we need to find out if any of the parent contains
referece to it
@@ -548,25 +550,25 @@
// currentState contains refenrece for the current
character
// this should be added as a child state to all
initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState,
FSMState.CHILD_STATE);
}
}
for(int i=0;i<nextStates.size();i++) {
- FSMState from = (FSMState) nextStates.get(i);
+ FSMState from = nextStates.get(i);
for(int j=0;j<nextStates.size();j++) {
- FSMState to = (FSMState) nextStates.get(j);
+ FSMState to = nextStates.get(j);
char ch = line.charAt(j);
from.put(ch, to, FSMState.ADJ_STATE);
}
}
- HashSet newSet = new HashSet();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.addAll(nextStates);
- ArrayList newList = new ArrayList();
+ List<Set<FSMState>> newList = new ArrayList<Set<FSMState>>();
newList.add(newSet);
return newList;
}
@@ -576,7 +578,7 @@
* -> a -> b -> c -> null
* -> a -> b -> c -> a
*/
- public static ArrayList andPlusFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> andPlusFSMs(String line,
Set<FSMState> initStates, Interpret owner) {
// for the first inital State
// we need to find out if any of the parent contains referece
to it
char ch = line.charAt(0);
@@ -593,9 +595,9 @@
// currentState contains the first state
// this should be added as a child state to all initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState, FSMState.CHILD_STATE);
}
@@ -618,8 +620,8 @@
}
nextState.put(line.charAt(0), firstState, FSMState.ADJ_STATE);
- ArrayList nextStates = new ArrayList();
- HashSet newSet = new HashSet();
+ List<Set<FSMState>> nextStates = new ArrayList<Set<FSMState>>();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.add(nextState);
nextStates.add(newSet);
return nextStates;
@@ -629,11 +631,11 @@
* [abc]*
* each element can have reference to adjecent ones and to itself
*/
- public static ArrayList orStarFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> orStarFSMs(String line, Set<FSMState>
initStates, Interpret owner) {
// for each character in the line
// we need to find out if any of the initStates contain
reference to it
// if so that should be assigned to all initStates
- ArrayList nextStates = new ArrayList();
+ List<FSMState> nextStates = new ArrayList<FSMState>();
for(int i=0;i<line.length();i++) {
// for the current character
// we need to find out if any of the parent contains
referece to it
@@ -652,26 +654,26 @@
// currentState contains refenrece for the current
character
// this should be added as a child state to all
initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState,
FSMState.CHILD_STATE);
}
}
for(int i=0;i<nextStates.size();i++) {
- FSMState from = (FSMState) nextStates.get(i);
+ FSMState from = nextStates.get(i);
for(int j=0;j<nextStates.size();j++) {
- FSMState to = (FSMState) nextStates.get(j);
+ FSMState to = nextStates.get(j);
char ch = line.charAt(j);
from.put(ch, to, FSMState.ADJ_STATE);
}
}
- HashSet newSet = new HashSet();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.addAll(nextStates);
- ArrayList newList = new ArrayList();
+ List<Set<FSMState>> newList = new ArrayList<Set<FSMState>>();
newList.add(newSet);
newList.add(initStates);
return newList;
@@ -680,7 +682,7 @@
/**
* (abc)*
*/
- public static ArrayList andStarFSMs(String line, HashSet initStates,
Interpret owner) {
+ public static List<Set<FSMState>> andStarFSMs(String line,
Set<FSMState> initStates, Interpret owner) {
// for the first inital State
// we need to find out if any of the parent contains referece
to it
char ch = line.charAt(0);
@@ -697,9 +699,9 @@
// currentState contains the first state
// this should be added as a child state to all initStates
- Iterator iter = initStates.iterator();
+ Iterator<FSMState> iter = initStates.iterator();
while(iter.hasNext()) {
- FSMState state = (FSMState) iter.next();
+ FSMState state = iter.next();
state.put(ch, currentState, FSMState.CHILD_STATE);
}
@@ -724,8 +726,8 @@
nextState.put(line.charAt(0), firstState, FSMState.ADJ_STATE);
- ArrayList nextStates = new ArrayList();
- HashSet newSet = new HashSet();
+ List<Set<FSMState>> nextStates = new ArrayList<Set<FSMState>>();
+ Set<FSMState> newSet = new HashSet<FSMState>();
newSet.add(nextState);
nextStates.add(newSet);
nextStates.add(initStates);
@@ -758,8 +760,8 @@
// if the value found between the bracket is an integer value
// we won't replace those brackets
StringBuffer newExpr = new StringBuffer(line);
- Stack stack = new Stack();
- Stack bracketIndexes = new Stack();
+ Stack<String> stack = new Stack<String>();
+ Stack<Integer> bracketIndexes = new Stack<Integer>();
for (int i = 0; i < newExpr.length(); i++) {
if (newExpr.charAt(i) == '{') {
@@ -781,7 +783,7 @@
// before adding it to the stack, check if this
is the closing
// one
if (stack.isEmpty()
- || !(((String)
(stack.get(stack.size() - 1)))
+ || !((stack.get(stack.size() -
1))
.equals("\"")))
{
// yes this is the opening one
// add it to the stack
@@ -790,15 +792,15 @@
} else {
// this is the closing one
stack.pop();
- int index = ((Integer)
(bracketIndexes.pop())).intValue();
+ int index =
(bracketIndexes.pop()).intValue();
newExpr.setCharAt(index, '(');
newExpr.setCharAt(i, ')');
}
} else if (newExpr.charAt(i) == '}') {
// remove the element from the stack
// it must be '{', otherwise generate the error
- String bracket = (String) (stack.pop());
- int index = ((Integer)
(bracketIndexes.pop())).intValue();
+ String bracket = (stack.pop());
+ int index = (bracketIndexes.pop()).intValue();
if (!bracket.equals("{")) {
return null;
}
@@ -821,7 +823,7 @@
} else if (newExpr.charAt(i) == ')') {
// remove the element from the stack
// it must be ')', otherwise generate the error
- String bracket = (String) (stack.pop());
+ String bracket = (stack.pop());
bracketIndexes.pop();
if (!bracket.equals("(")) {
return null;
@@ -830,7 +832,7 @@
} else if (newExpr.charAt(i) == ']') {
// remove the element from the stack
// it must be '[', otherwise generate the error
- String bracket = (String) (stack.pop());
+ String bracket = (stack.pop());
bracketIndexes.pop();
if (!bracket.equals("[")) {
return null;
Modified: gate/trunk/src/main/gate/creole/morph/PatternParser.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/PatternParser.java 2014-03-08
10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/PatternParser.java 2014-03-08
12:07:09 UTC (rev 17594)
@@ -5,6 +5,7 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.List;
public class PatternParser {
@@ -107,10 +108,10 @@
varInst.resetPointer();
}
- public static ArrayList parsePattern(String q1) {
+ public static List<String> parsePattern(String q1) {
// arraylist to return - will contain all the OR normalized
queries
- ArrayList patterns = new ArrayList();
+ List<String> patterns = new ArrayList<String>();
// remove all extra spaces from the query
q1 = q1.trim();
@@ -123,7 +124,7 @@
for (int index = 0; index < patterns.size(); index++) {
// get the query to be parsed
- String query = (String) patterns.get(index);
+ String query = patterns.get(index);
// current character and the previous character
char ch = ' ', pre = ' ';
@@ -153,7 +154,7 @@
int brClPos =
findBracketClosingPosition(i + 1, query);
// see if there are any OR operators in
it
- ArrayList orTokens =
findOrTokens(query.substring(i + 1,
+ List<String> orTokens =
findOrTokens(query.substring(i + 1,
brClPos));
// orTokens will have
@@ -179,7 +180,7 @@
// text as ""
text = "";
} else {
- text = (String)
patterns
+ text = patterns
.get(patterns.size() - 1);
}
}
@@ -255,9 +256,9 @@
}
}
- ArrayList queriesToReturn = new ArrayList();
+ List<String> queriesToReturn = new ArrayList<String>();
for (int i = 0; i < patterns.size(); i++) {
- String q = (String) patterns.get(i);
+ String q = patterns.get(i);
if (q.trim().length() == 0) {
continue;
} else if (queriesToReturn.contains(q.trim())) {
@@ -268,7 +269,7 @@
}
for (int i = 0; i < queriesToReturn.size(); i++) {
- String s = (String) queriesToReturn.get(i);
+ String s = queriesToReturn.get(i);
s = s.replaceAll("<", "(");
s = s.replaceAll(">", ")");
s = s.substring(1, s.length() - 1);
@@ -314,19 +315,19 @@
return false;
}
- public static ArrayList writeTokens(ArrayList tokens, ArrayList queries,
+ public static List<String> writeTokens(List<String> tokens,
List<String> queries,
int dupliSize) {
if (dupliSize == 0)
dupliSize = 1;
- ArrayList qToRemove = new ArrayList();
+ List<String> qToRemove = new ArrayList<String>();
for (int j = 0; j < dupliSize; j++) {
for (int i = 1; i <= tokens.size(); i++) {
- String token = (String) tokens.get(i - 1);
+ String token = tokens.get(i - 1);
if (token.trim().equals("{__o__}")) {
token = " ";
}
- String s = (String) queries.get(queries.size()
+ String s = queries.get(queries.size()
- (j * tokens.size() + i));
qToRemove.add(s);
s += token;
@@ -342,12 +343,12 @@
return queries;
}
- public static ArrayList duplicate(ArrayList queries, String s,
+ public static List<String> duplicate(List<String> queries, String s,
int dupliSize, int no) {
if (s == null)
s = "";
- ArrayList strings = new ArrayList();
+ List<String> strings = new ArrayList<String>();
if (dupliSize == 0) {
strings.add(s);
} else {
@@ -365,11 +366,11 @@
return queries;
}
- public static ArrayList findOrTokens(String query) {
+ public static List<String> findOrTokens(String query) {
int balance = 0;
char pre = ' ';
char ch = ' ';
- ArrayList ors = new ArrayList();
+ List<String> ors = new ArrayList<String>();
String s = "";
for (int i = 0; i < query.length(); i++) {
@@ -430,18 +431,18 @@
return -1;
}
- public static ArrayList writeCharInAll(char c, int no, ArrayList
queries) {
+ public static List<String> writeCharInAll(char c, int no, List<String>
queries) {
for (int i = 0; i < no; i++) {
- String s = (String) queries.get(queries.size() - (i +
1));
+ String s = queries.get(queries.size() - (i + 1));
s += "" + c;
queries.set(queries.size() - (i + 1), s);
}
return queries;
}
- public static ArrayList writeStringInAll(String c, int no, ArrayList
queries) {
+ public static List<String> writeStringInAll(String c, int no,
List<String> queries) {
for (int i = 0; i < no; i++) {
- String s = (String) queries.get(queries.size() - (i +
1));
+ String s = queries.get(queries.size() - (i + 1));
s += "" + c;
queries.set(queries.size() - (i + 1), s);
}
Modified: gate/trunk/src/main/gate/creole/morph/ReadFile.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/ReadFile.java 2014-03-08 10:03:19 UTC
(rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/ReadFile.java 2014-03-08 12:07:09 UTC
(rev 17594)
@@ -23,7 +23,7 @@
private int pointer = 0;
/** Stores each line of the file as a separate String in the ArrayList */
- private List data;
+ private List<String> data;
/**
* Constructor - Initialise the buffered Reader instance
@@ -31,7 +31,7 @@
*/
public ReadFile(URL fileURL) {
- data = new ArrayList();
+ data = new ArrayList<String>();
try {
br = new BomStrippingInputStreamReader(fileURL.openStream(),
@@ -87,7 +87,7 @@
*/
public String getNext() {
if(data.size()>pointer) {
- String value = (String)(data.get(pointer));
+ String value = data.get(pointer);
pointer++;
return value;
} else {
Modified: gate/trunk/src/main/gate/creole/morph/StringSet.java
===================================================================
--- gate/trunk/src/main/gate/creole/morph/StringSet.java 2014-03-08
10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/morph/StringSet.java 2014-03-08
12:07:09 UTC (rev 17594)
@@ -1,6 +1,7 @@
package gate.creole.morph;
import java.util.ArrayList;
+import java.util.List;
/**
* <p>Title: StringSet </p>
@@ -13,13 +14,13 @@
public class StringSet extends Variable {
private String varName;
- private ArrayList variables;
+ private List<String> variables;
/**
* Constructor
*/
public StringSet() {
- variables = new ArrayList();
+ variables = new ArrayList<String>();
}
/**
@@ -43,7 +44,7 @@
public String next() {
if(pointer<variables.size()) {
pointer++;
- return (String)(variables.get(pointer-1));
+ return variables.get(pointer-1);
} else {
return null;
}
Modified: gate/trunk/src/main/gate/creole/nerc/EntityDescriptor.java
===================================================================
--- gate/trunk/src/main/gate/creole/nerc/EntityDescriptor.java 2014-03-08
10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/nerc/EntityDescriptor.java 2014-03-08
12:07:09 UTC (rev 17594)
@@ -25,6 +25,8 @@
/** Represents a single named entity */
public class EntityDescriptor implements Serializable{
+ private static final long serialVersionUID = 3651574462048131137L;
+
/** Constructs a new entity descriptor */
public EntityDescriptor(String string, String category, int start, int end) {
this.string = normaliseString(string);
Modified: gate/trunk/src/main/gate/creole/nerc/EntitySet.java
===================================================================
--- gate/trunk/src/main/gate/creole/nerc/EntitySet.java 2014-03-08 10:03:19 UTC
(rev 17593)
+++ gate/trunk/src/main/gate/creole/nerc/EntitySet.java 2014-03-08 12:07:09 UTC
(rev 17594)
@@ -24,13 +24,15 @@
/** Representing a set of entities found in a single text file.
* Each member a the set is an EntityDescriptor
*/
-public class EntitySet extends AbstractSet implements Set, Serializable {
+public class EntitySet extends AbstractSet<EntityDescriptor> implements
Serializable {
+ private static final long serialVersionUID = -4507459923659885322L;
+
/** Constructs an entity set from a Gate annotation set*/
public EntitySet(String fileName, Document document,
AnnotationSet annotationSet) {
this.fileName = fileName;
- myEntities = new HashSet();
+ myEntities = new HashSet<EntityDescriptor>();
if(annotationSet != null){
Iterator<Annotation> annIter = annotationSet.iterator();
while(annIter.hasNext()){
@@ -59,7 +61,7 @@
res.append(fileName);
res.append("\n");
- Iterator entIter = myEntities.iterator();
+ Iterator<EntityDescriptor> entIter = myEntities.iterator();
while(entIter.hasNext()){
/// res += entIter.next().toString() + "\n";
res.append(entIter.next().toString());
@@ -72,8 +74,8 @@
public int size(){ return myEntities.size();}
@Override
- public Iterator iterator() {return myEntities.iterator();}
+ public Iterator<EntityDescriptor> iterator() {return myEntities.iterator();}
String fileName;
- Set myEntities;
+ Set<EntityDescriptor> myEntities;
}
\ No newline at end of file
Modified:
gate/trunk/src/main/gate/creole/orthomatcher/BasicAnnotationOrthography.java
===================================================================
---
gate/trunk/src/main/gate/creole/orthomatcher/BasicAnnotationOrthography.java
2014-03-08 10:03:19 UTC (rev 17593)
+++
gate/trunk/src/main/gate/creole/orthomatcher/BasicAnnotationOrthography.java
2014-03-08 12:07:09 UTC (rev 17594)
@@ -28,6 +28,7 @@
import java.util.Set;
import java.util.regex.Pattern;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
/*
@@ -336,46 +337,52 @@
return true;
} // isUnknownGender
- protected Map<String, Set<String>> initNicknames(
- String nicknameFileEncoding, java.net.URL fileURL) throws IOException {
+ protected Map<String, Set<String>> initNicknames(String nicknameFileEncoding,
+ java.net.URL fileURL) throws IOException {
Pattern spacePat = Pattern.compile("(\\s+)");
nicknameMap = new HashMap<String, Set<String>>();
// create the relative URL
- BufferedReader reader =
- new BomStrippingInputStreamReader(fileURL.openStream(),
- nicknameFileEncoding);
- String lineRead = null;
-
- while((lineRead = reader.readLine()) != null) {
- if(lineRead.length() == 0 || lineRead.charAt(0) == '#') {
- continue;
+ BufferedReader reader = null;
+ try {
+ reader = new BomStrippingInputStreamReader(fileURL.openStream(),
+ nicknameFileEncoding);
+ String lineRead = null;
+
+ while((lineRead = reader.readLine()) != null) {
+ if(lineRead.length() == 0 || lineRead.charAt(0) == '#') {
+ continue;
+ }
+ List<String> nickNameLine =
+ Arrays.asList(spacePat.split(lineRead
+ .toLowerCase().trim()));
+ if(nickNameLine.size() != 3
+ && (nickNameLine.size() != 4 && ((nickNameLine.get(3) != "M")
|| nickNameLine
+ .get(3) != "F"))) {
+ continue;
+ }
+ if(round2Places(Double.valueOf(nickNameLine.get(2))) <
OrthoMatcherHelper
+ .round2Places(minimumNicknameLikelihood)) {
+ continue;
+ }
+ if(nicknameMap.containsKey(nickNameLine.get(0))) {
+ /*
+ * System.out.println("Adding to existing nickname of " +
+ * nickNameLine.get(0) + " " + nickNameLine.get(1));
+ */
+ nicknameMap.get(nickNameLine.get(0)).add(nickNameLine.get(1));
+ } else {
+ /*
+ * System.out.println("Adding new nickname of " +
+ * nickNameLine.get(0) + " " + nickNameLine.get(1));
+ */
+ nicknameMap.put(
+ nickNameLine.get(0),
+ new HashSet<String>(
+ Collections.singleton(nickNameLine.get(1))));
+ }
}
- ArrayList<String> nickNameLine =
- new ArrayList<String>(Arrays.asList(spacePat.split(lineRead
- .toLowerCase().trim())));
- if(nickNameLine.size() != 3
- && (nickNameLine.size() != 4 && ((nickNameLine.get(3) != "M") ||
nickNameLine
- .get(3) != "F"))) {
- continue;
- }
- if(round2Places(Double.valueOf(nickNameLine.get(2))) < OrthoMatcherHelper
- .round2Places(minimumNicknameLikelihood)) {
- continue;
- }
- if(nicknameMap.containsKey(nickNameLine.get(0))) {
- /*
- * System.out.println("Adding to existing nickname of " +
- * nickNameLine.get(0) + " " + nickNameLine.get(1));
- */
- nicknameMap.get(nickNameLine.get(0)).add(nickNameLine.get(1));
- } else {
- /*
- * System.out.println("Adding new nickname of " + nickNameLine.get(0) +
- * " " + nickNameLine.get(1));
- */
- nicknameMap.put(nickNameLine.get(0),
- new HashSet<String>(Collections.singleton(nickNameLine.get(1))));
- }
+ } finally {
+ IOUtils.closeQuietly(reader);
}
return nicknameMap;
}
Modified: gate/trunk/src/main/gate/creole/orthomatcher/OrthoMatcher.java
===================================================================
--- gate/trunk/src/main/gate/creole/orthomatcher/OrthoMatcher.java
2014-03-08 10:03:19 UTC (rev 17593)
+++ gate/trunk/src/main/gate/creole/orthomatcher/OrthoMatcher.java
2014-03-08 12:07:09 UTC (rev 17594)
@@ -60,6 +60,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
@CreoleResource(name="ANNIE OrthoMatcher", comment="ANNIE orthographical
coreference component.",
helpURL="http://gate.ac.uk/userguide/sec:annie:orthomatcher",
icon="ortho-matcher")
public class OrthoMatcher extends AbstractLanguageAnalyser {
@@ -224,6 +225,7 @@
}
/** Initialise this resource, and return it. */
+ @SuppressWarnings("resource")
@Override
public Resource init() throws ResourceInstantiationException {
//initialise the list of annotations which we will match
@@ -232,10 +234,10 @@
"No URL provided for the definition file!");
}
String nicknameFile = null;
-
+ BufferedReader reader = null;
//at this point we have the definition file
try{
- BufferedReader reader = new BomStrippingInputStreamReader(
+ reader = new BomStrippingInputStreamReader(
definitionFileURL.openStream(), encoding);
String lineRead = null;
//boolean foundANickname = false;
@@ -270,6 +272,9 @@
}catch(IOException ioe){
throw new ResourceInstantiationException(ioe);
}
+ finally {
+ IOUtils.closeQuietly(reader);
+ }
return this;
@@ -993,48 +998,50 @@
}
/** creates the lookup tables */
- protected void createAnnotList(String nameFile,String nameList)
- throws IOException{
- //create the relative URL
+ protected void createAnnotList(String nameFile, String nameList)
+ throws IOException {
+ // create the relative URL
URL fileURL = new URL(definitionFileURL, nameFile);
- BufferedReader bufferedReader =
- new BomStrippingInputStreamReader(fileURL.openStream(),
- encoding);
+ BufferedReader bufferedReader = null;
+ try {
+ bufferedReader =
+ new BomStrippingInputStreamReader(fileURL.openStream(),
encoding);
- String lineRead = null;
- while ((lineRead = bufferedReader.readLine()) != null){
- if (nameList.compareTo(CDGLISTNAME)==0){
- Matcher matcher = punctPat.matcher(lineRead.toLowerCase().trim());
- lineRead = matcher.replaceAll(" ").trim();
- if (caseSensitive)
- cdg.add(lineRead);
- else
- cdg.add(lineRead.toLowerCase());
- }// if
- else {
- int index = lineRead.indexOf("£");
- if (index != -1){
- String expr = lineRead.substring(0,index);
- //if not case-sensitive, we need to downcase all strings
- if (!caseSensitive)
- expr = expr.toLowerCase();
- String code = lineRead.substring(index+1,lineRead.length());
- if (nameList.equals(ALIASLISTNAME)) {
- alias.put(expr, code);
- } else if (nameList.equals(ARTLISTNAME)) {
- def_art.put(expr, code);
- } else if (nameList.equals(PREPLISTNAME)) {
- prepos.put(expr, code);
- } else if (nameList.equals(CONNECTORLISTNAME)) {
- connector.put(expr, code);
- } else if (nameList.equals(SPURLISTNAME)){
- spur_match.put(expr, code);
- }
- }//if
- }// else
+ String lineRead = null;
+ while((lineRead = bufferedReader.readLine()) != null) {
+ if(nameList.compareTo(CDGLISTNAME) == 0) {
+ Matcher matcher = punctPat.matcher(lineRead.toLowerCase().trim());
+ lineRead = matcher.replaceAll(" ").trim();
+ if(caseSensitive)
+ cdg.add(lineRead);
+ else cdg.add(lineRead.toLowerCase());
+ }// if
+ else {
+ int index = lineRead.indexOf("£");
+ if(index != -1) {
+ String expr = lineRead.substring(0, index);
+ // if not case-sensitive, we need to downcase all strings
+ if(!caseSensitive) expr = expr.toLowerCase();
+ String code = lineRead.substring(index + 1, lineRead.length());
+ if(nameList.equals(ALIASLISTNAME)) {
+ alias.put(expr, code);
+ } else if(nameList.equals(ARTLISTNAME)) {
+ def_art.put(expr, code);
+ } else if(nameList.equals(PREPLISTNAME)) {
+ prepos.put(expr, code);
+ } else if(nameList.equals(CONNECTORLISTNAME)) {
+ connector.put(expr, code);
+ } else if(nameList.equals(SPURLISTNAME)) {
+ spur_match.put(expr, code);
+ }
+ }// if
+ }// else
- }//while
- }//createAnnotList
+ }// while
+ } finally {
+ IOUtils.closeQuietly(bufferedReader);
+ }
+ }// createAnnotList
/**
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs