Revision: 17755
http://sourceforge.net/p/gate/code/17755
Author: markagreenwood
Date: 2014-03-30 16:43:57 +0000 (Sun, 30 Mar 2014)
Log Message:
-----------
tidied up the warning mess that was caused by a checkin done from an old
version of the code rather than svn head
Modified Paths:
--------------
gate/trunk/plugins/Learning/src/gate/learning/ArraysDataSetDefinition.java
gate/trunk/plugins/Learning/src/gate/learning/DocFeatureVectors.java
gate/trunk/plugins/Learning/src/gate/learning/LightWeightLearningApi.java
gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesList.java
gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
Modified:
gate/trunk/plugins/Learning/src/gate/learning/ArraysDataSetDefinition.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/ArraysDataSetDefinition.java
2014-03-30 15:06:10 UTC (rev 17754)
+++ gate/trunk/plugins/Learning/src/gate/learning/ArraysDataSetDefinition.java
2014-03-30 16:43:57 UTC (rev 17755)
@@ -54,7 +54,7 @@
int maxPosPosition = 0;
/** Put the types and feautures and others into the arrays. */
- void putTypeAndFeatIntoArray(List attrs) {
+ void putTypeAndFeatIntoArray(List<? extends Attribute> attrs) {
numTypes = obtainNumberOfNLPTypes(attrs);
typesInDataSetDef = new String[numTypes];
featuresInDataSetDef = new String[numTypes];
@@ -74,7 +74,7 @@
}
/** Get the number of features in the dataset definition unit. */
- static int obtainNumberOfNLPTypes(List attrs) {
+ static int obtainNumberOfNLPTypes(List<? extends Attribute> attrs) {
int num = 0;
if(attrs == null) {
return num;
@@ -87,10 +87,10 @@
}
/** Get the type, feature, name and position of each of attribute features.
*/
- void obtainGATETypesAndFeatures(List attrs) {
+ void obtainGATETypesAndFeatures(List<? extends Attribute> attrs) {
int num0 = 0;
for(int i = 0; i < attrs.size(); i++) {
- Attribute attr = (Attribute)attrs.get(i);
+ Attribute attr = attrs.get(i);
if(!attr.isClass()) {
typesInDataSetDef[num0] = attr.getType();
featuresInDataSetDef[num0] = attr.getFeature();
@@ -113,12 +113,12 @@
* Get the annotation features of the two arguments of relation for all the
* ATTRIBUTE_RELs.
*/
- void obtainArgs(List relAttrs) {
+ void obtainArgs(List<AttributeRelation> relAttrs) {
int num0 = 0;
arg1s = new String[numTypes];
arg2s = new String[numTypes];
for(int i = 0; i < relAttrs.size(); i++) {
- AttributeRelation attr = (AttributeRelation)relAttrs.get(i);
+ AttributeRelation attr = relAttrs.get(i);
if(!attr.isClass()) {
arg1s[num0] = attr.getArg1();
arg2s[num0] = attr.getArg2();
Modified: gate/trunk/plugins/Learning/src/gate/learning/DocFeatureVectors.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/DocFeatureVectors.java
2014-03-30 15:06:10 UTC (rev 17754)
+++ gate/trunk/plugins/Learning/src/gate/learning/DocFeatureVectors.java
2014-03-30 16:43:57 UTC (rev 17755)
@@ -8,13 +8,16 @@
package gate.learning;
import gate.util.GateException;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Hashtable;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
/**
@@ -50,8 +53,7 @@
fvs = new SparseFeatureVector[numInstances];
// For each istance
for(int i = 0; i < numInstances; ++i) {
- Hashtable indexValues = new Hashtable();
- int n = 0;
+ Map<Object,Object> indexValues = new HashMap<Object,Object>();
String[] feat = nlpDoc.featuresInLine[i].toString().split(
ConstantParameters.ITEMSEPARATOR);
// Some variables for normalising the feature values of the same ngram
@@ -134,8 +136,7 @@
case 3: // for tf*idf representation
val = (Long.parseLong(featVal) + 1)
* Math.log((double)numDocs
- / (Long.parseLong(featList.idfFeatures.get(featCur)
- .toString())));
+ / featList.idfFeatures.get(featCur));
break;
default:
try {
@@ -175,18 +176,17 @@
if(positionCurr == 0)
indexValues.put(featList.featuresList.get(featCur), valNow);
else if(positionCurr < 0)
- indexValues.put(new
Long((Long.parseLong(featList.featuresList
- .get(featCur).toString()) - positionCurr
- * ConstantParameters.MAXIMUMFEATURES)), new Float(-1*valNow
- / (double)positionCurr));
+ indexValues.put(featList.featuresList
+ .get(featCur) - positionCurr
+ * ConstantParameters.MAXIMUMFEATURES, -1f*valNow
+ / (double)positionCurr);
else indexValues.put(
- new Long((Long.parseLong(featList.featuresList.get(featCur)
- .toString()) + (positionCurr + maxNegPosition)
- * ConstantParameters.MAXIMUMFEATURES)), new Float(
- valNow / (double)positionCurr));
+ (featList.featuresList.get(featCur)
+ + (positionCurr + maxNegPosition)
+ * ConstantParameters.MAXIMUMFEATURES),
+ valNow / (double)positionCurr);
}
- ++n;
}
}
prevPosition = positionCurr;
@@ -201,12 +201,11 @@
for(int ii = 0; ii < tempSize; ++ii) {
tempVals[ii] /= sum;
tempVals[ii] *= ngramWeight;
- indexValues.put(new Long(tempInds[ii]), new Float(tempVals[ii]));
+ indexValues.put(tempInds[ii], tempVals[ii]);
}
} else {
for(int ii = 0; ii < tempSize; ++ii) {
- indexValues.put(new Long(tempInds[ii]), new Integer(
- (int)tempVals[ii]));
+ indexValues.put(tempInds[ii], tempVals[ii]);
}
}
tempSize = 0;
@@ -218,7 +217,7 @@
// + nlpDoc.featuresCounted[i] + ")in document " + docId);
// }
// sort the indexes in ascending order
- List indexes = new ArrayList(indexValues.keySet());
+ List<Object> indexes = new ArrayList<Object>(indexValues.keySet());
Collections.sort(indexes, new LongCompactor());
// Iterator iterator = indexes.iterator();
// n = 0;
@@ -241,7 +240,7 @@
}
/** A static class for comparing two long numbers. */
- public static class LongCompactor implements java.util.Comparator {
+ public static class LongCompactor implements Comparator<Object> {
public int compare(Object l1, Object l2) {
// return (new Long((new Long(l1.toString()).longValue()- new
// Long(l2.toString()).longValue()))).intValue();
@@ -308,8 +307,8 @@
if(indexValue.length <= 1) {
System.out.println("i=" + i + " item=" + items[i + iEndLabel]);
}
- fv.nodes[i].index = (new Integer(indexValue[0])).intValue();
- fv.nodes[i].value = (new Float(indexValue[1])).floatValue();
+ fv.nodes[i].index = new Integer(indexValue[0]);
+ fv.nodes[i].value = new Float(indexValue[1]);
}
return;
}
@@ -386,14 +385,14 @@
/** Write the FVs of one document into file. */
public void addDocFVsToFile(int index, BufferedWriter out, int[] labels) {
try {
- out.write(new Integer(index) + ConstantParameters.ITEMSEPARATOR
- + new Integer(numInstances) + ConstantParameters.ITEMSEPARATOR
+ out.write(index + ConstantParameters.ITEMSEPARATOR
+ + numInstances + ConstantParameters.ITEMSEPARATOR
+ docId);
out.newLine();
for(int i = 0; i < numInstances; ++i) {
StringBuffer line = new StringBuffer();
- line.append(new Integer(i + 1) + ConstantParameters.ITEMSEPARATOR
- + new Integer(labels[i]));
+ line.append((i + 1) + ConstantParameters.ITEMSEPARATOR
+ + labels[i]);
for(int j = 0; j < fvs[i].len; ++j)
line.append(ConstantParameters.ITEMSEPARATOR
+ fvs[i].nodes[j].index + ConstantParameters.INDEXVALUESEPARATOR
@@ -409,8 +408,8 @@
public void addDocFVsMultiLabelToFile(int index, BufferedWriter out,
LabelsOfFV[] multiLabels) {
try {
- out.write(new Integer(index) + ConstantParameters.ITEMSEPARATOR
- + new Integer(numInstances) + ConstantParameters.ITEMSEPARATOR
+ out.write(index + ConstantParameters.ITEMSEPARATOR
+ + numInstances + ConstantParameters.ITEMSEPARATOR
+ docId);
out.newLine();
for(int i = 0; i < numInstances; ++i) {
@@ -421,7 +420,7 @@
+ 0);
} else {
- line.append(new Integer(i + 1) + ConstantParameters.ITEMSEPARATOR
+ line.append((i + 1) + ConstantParameters.ITEMSEPARATOR
+ multiLabels[i].num);
for(int j = 0; j < multiLabels[i].num; ++j) {
line.append(ConstantParameters.ITEMSEPARATOR
Modified:
gate/trunk/plugins/Learning/src/gate/learning/LightWeightLearningApi.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/LightWeightLearningApi.java
2014-03-30 15:06:10 UTC (rev 17754)
+++ gate/trunk/plugins/Learning/src/gate/learning/LightWeightLearningApi.java
2014-03-30 16:43:57 UTC (rev 17755)
@@ -556,10 +556,10 @@
BufferedReader inFVs = new BomStrippingInputStreamReader(
new FileInputStream(new File(wdResults,
ConstantParameters.FILENAMEOFFeatureVectorData)), "UTF-8");
- HashMap<Integer, String> indexTerm = new HashMap<Integer, String>();
- for(Object obj : featuresList.featuresList.keySet()) {
+ Map<Integer, String> indexTerm = new HashMap<Integer, String>();
+ for(String obj : featuresList.featuresList.keySet()) {
indexTerm.put(
- new Long(featuresList.featuresList.get(obj).toString()).intValue(),
obj.toString());
+ featuresList.featuresList.get(obj).intValue(), obj);
}
for(int nd = 0; nd < numDocs; ++nd) {
String[] ts = inFVs.readLine().split(ConstantParameters.ITEMSEPARATOR);
@@ -1573,9 +1573,9 @@
surroundMode = engineSettings.surround;
// Open the mode file and read the model
Map<Integer,String> featId2Form = new HashMap<Integer,String>();
- for(Object obj : featuresList.featuresList.keySet()) {
- int k = new
Long(featuresList.featuresList.get(obj).toString()).intValue();
- featId2Form.put(k, obj.toString());
+ for(String obj : featuresList.featuresList.keySet()) {
+ int k = featuresList.featuresList.get(obj).intValue();
+ featId2Form.put(k, obj);
}
// Need some methods from MultiClassLearning
MultiClassLearning mulL = new MultiClassLearning();
Modified: gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesList.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesList.java
2014-03-30 15:06:10 UTC (rev 17754)
+++ gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesList.java
2014-03-30 16:43:57 UTC (rev 17755)
@@ -14,14 +14,14 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
/**
@@ -30,12 +30,12 @@
*/
public class NLPFeaturesList {
/** the features with ids, can be accessed by multiple threads. */
- public Hashtable featuresList = null;
+ public Map<String,Long> featuresList = null;
/**
* Document frequence of each term, useful for document or passage
* classification
*/
- public Hashtable idfFeatures = null;
+ public Map<String,Long> idfFeatures = null;
/** Total number of documents used for forming the list. */
int totalNumDocs;
/** The unique sysmbol used for the N-gram feature. */
@@ -43,8 +43,8 @@
/** Constructor, get the two hashtables. */
public NLPFeaturesList() {
- featuresList = new Hashtable();
- idfFeatures = new Hashtable();
+ featuresList = new HashMap<String,Long>();
+ idfFeatures = new HashMap<String,Long>();
totalNumDocs = 0;
}
@@ -58,12 +58,11 @@
// featuresList = new Hashtable();
String line;
if((line = in.readLine()) != null)
- totalNumDocs = (new Integer(line.substring(line.lastIndexOf("=") +
1)))
- .intValue();
+ totalNumDocs = new Integer(line.substring(line.lastIndexOf("=") +
1));
while((line = in.readLine()) != null) {
String[] st = line.split(" ");
- featuresList.put(st[0], st[1]);
- idfFeatures.put(st[0], st[2]);
+ featuresList.put(st[0], new Long(st[1]));
+ idfFeatures.put(st[0], new Long(st[2]));
}
in.close();
} catch(IOException e) {
@@ -84,12 +83,12 @@
fileFeaturesList), tcode));
// for the total number of docs
out.println("totalNumDocs=" + totalNumDocs);
- List keys = new ArrayList(featuresList.keySet());
+ List<String> keys = new ArrayList<String>(featuresList.keySet());
Collections.sort(keys);
// write the features list into the output file
- Iterator iterator = keys.iterator();
+ Iterator<String> iterator = keys.iterator();
while(iterator.hasNext()) {
- Object key = iterator.next();
+ String key = iterator.next();
out.println(key + " " + featuresList.get(key) + " "
+ idfFeatures.get(key));
//System.out.println("*"+key+ "* " + featuresList.get(key));
@@ -136,11 +135,10 @@
++size;
// features is from 1 (not zero), in the SVM-light
// format
- featuresList.put(feat, new Long(size));
- idfFeatures.put(feat, new Long(1));
+ featuresList.put(feat, size);
+ idfFeatures.put(feat, 1L);
} else {
- idfFeatures.put(feat, new Long((new Long(idfFeatures.get(feat)
- .toString())).longValue() + 1));
+ idfFeatures.put(feat, idfFeatures.get(feat) + 1);
}
} else {
String msg =
@@ -175,7 +173,7 @@
// for the total number of docs
//out.println("totalNumDocs=" + new Integer(totalNumDocs));
out.println("## The following "+nGram+"-gram were obtained from " +
totalNumDocs+ " documents or examples");
- List keys = new ArrayList(featuresList.keySet());
+ List<String> keys = new ArrayList<String>(featuresList.keySet());
//Collections.sort(keys);
int numT = keys.size();
float [] freqs = new float[numT];
Modified: gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
2014-03-30 15:06:10 UTC (rev 17754)
+++ gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
2014-03-30 16:43:57 UTC (rev 17755)
@@ -7,24 +7,21 @@
*/
package gate.learning;
+import gate.Annotation;
+import gate.AnnotationSet;
+import gate.FeatureMap;
+import gate.util.OffsetComparator;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
-import org.apache.commons.lang.ObjectUtils.Null;
-
-import gate.Annotation;
-import gate.AnnotationSet;
-import gate.FeatureMap;
-import gate.util.OffsetComparator;
-import gate.learning.Ngram;
-
/*
* Obtain the NLP (linguistic) features from the GATE annotations of one
* document.
@@ -124,22 +121,22 @@
/** Get the N-gram features from the GATE document. */
public void gatedoc2NgramFeatures(AnnotationSet annotations,
- String instanceType, java.util.List ngrams) {
+ String instanceType, List<Ngram> ngrams) {
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
if(numInstances != annotationArray.size()) {
System.out.println("!!Warning: the number of instances "
- + new Integer(numInstances) + " in the document " + docId
+ + numInstances + " in the document " + docId
+ " is not right!!!");
return;
}
int numNgrams = ngrams.size();
// For each ngram
for(int i1 = 0; i1 < numNgrams; ++i1) {
- Ngram ngram = (Ngram)ngrams.get(i1);
+ Ngram ngram = ngrams.get(i1);
String nameOfNgram = ngram.getName();
int ngramPosition = ngram.position;
String positionStr = obtainPositionStr(ngramPosition);
@@ -153,10 +150,10 @@
}
AnnotationSet [] annsArray = new AnnotationSet[consNum];
for(int j=0; j<consNum; ++j) {
- annsArray[j] = (AnnotationSet)annotations.get(typeGateNgram[j]);
+ annsArray[j] = annotations.get(typeGateNgram[j]);
}
for(int i = 0; i < numInstances; ++i) {
- Annotation annToken = (Annotation)annotationArray.get(i);
+ Annotation annToken = annotationArray.get(i);
Long tokenStartOffset = annToken.getStartNode().getOffset();
Long tokenEndOffset = annToken.getEndNode().getOffset();
//AnnotationSet annsNgramType = annotations.get(typeGateNgram,
@@ -189,26 +186,24 @@
+ NLPFeaturesList.SYMBOLNGARM);
}
}
- Hashtable ngramTerms = new Hashtable();
+ Map<String,Integer> ngramTerms = new HashMap<String,Integer>();
for(int j = 0; j < featuresNgram.length; ++j)
if(!ngramTerms.containsKey(featuresNgram[j].toString()))
- ngramTerms.put(featuresNgram[j].toString(), "1");
+ ngramTerms.put(featuresNgram[j].toString(), 1);
else ngramTerms.put(featuresNgram[j].toString(),
new Integer((new Integer(ngramTerms
.get(featuresNgram[j].toString()).toString())).intValue() + 1));
- List keys = new ArrayList(ngramTerms.keySet());
+ List<String> keys = new ArrayList<String>(ngramTerms.keySet());
Collections.sort(keys);
- Iterator iterator = keys.iterator();
+ Iterator<String> iterator = keys.iterator();
if(featuresInLine[i] == null) featuresInLine[i] = new StringBuffer();
while(iterator.hasNext()) {
Object key = iterator.next();
if(ngramPosition != 0)
this.featuresInLine[i].append(obtainFeatureNameForNGRAM(nameOfNgram, key
- .toString()
+ NLPFeaturesList.SYMBOLNGARM + ngramTerms.get(key).toString())
+ positionStr + ConstantParameters.ITEMSEPARATOR);
else
this.featuresInLine[i].append(obtainFeatureNameForNGRAM(nameOfNgram, key
- .toString()
+ NLPFeaturesList.SYMBOLNGARM + ngramTerms.get(key).toString())
+ ConstantParameters.ITEMSEPARATOR);
++featuresCounted[i];
@@ -223,7 +218,7 @@
* feature.
*/
String obtainPositionStr(int ngramPosition) {
- return "[" + (new Integer(ngramPosition)).toString() + "]";
+ return "[" + ngramPosition + "]";
}
/** Obtain the N-gram features from an annotation set. */
@@ -231,11 +226,11 @@
String gateFeature) {
int num = annsNgramType.size();
String[] feats = new String[num];
- ArrayList annotationArray = (annsNgramType == null || annsNgramType
- .isEmpty()) ? new ArrayList() : new ArrayList(annsNgramType);
+ List<Annotation> annotationArray = (annsNgramType == null || annsNgramType
+ .isEmpty()) ? new ArrayList<Annotation>() : new
ArrayList<Annotation>(annsNgramType);
Collections.sort(annotationArray, new OffsetComparator());
for(int i = 0; i < num; ++i) {
- feats[i] = (String)((Annotation)annotationArray.get(i)).getFeatures()
+ feats[i] = (String)annotationArray.get(i).getFeatures()
.get(gateFeature);
if(feats[i]==null)
feats[i] = ConstantParameters.NAMENONFEATURE;
@@ -253,13 +248,13 @@
AnnotationSet annsNgramType, AnnotationSet annsCurrent, String
gateFeature) {
int num = annsNgramType.size();
String[] feats = new String[num];
- ArrayList annotationArray = (annsNgramType == null || annsNgramType
- .isEmpty()) ? new ArrayList() : new ArrayList(annsNgramType);
+ List<Annotation> annotationArray = (annsNgramType == null || annsNgramType
+ .isEmpty()) ? new ArrayList<Annotation>() : new
ArrayList<Annotation>(annsNgramType);
Collections.sort(annotationArray, new OffsetComparator());
for(int i = 0; i < num; ++i) {
feats[i] = obtainAnnotationForTypeAndFeature(annsCurrent, gateFeature,
- ((Annotation)(annotationArray.get(i))).getStartNode().getOffset(),
- ((Annotation)(annotationArray.get(i))).getEndNode().getOffset());
+ annotationArray.get(i).getStartNode().getOffset(),
+ annotationArray.get(i).getEndNode().getOffset());
if(feats[i] != null)
feats[i] = feats[i].trim().replaceAll(ConstantParameters.ITEMSEPARATOR,
ConstantParameters.ITEMSEPREPLACEMENT);
@@ -271,13 +266,13 @@
public void gatedoc2LabelsComplete(AnnotationSet annotations,
String instanceType, String classType, String classFeature) {
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
if(numInstances != annotationArray.size()) {
System.out.println("!!Warning: the number of instances "
- + new Integer(numInstances) + " in the document " + docId
+ + numInstances + " in the document " + docId
+ " is not right!!!");
return;
}
@@ -295,7 +290,7 @@
String [] featNameArray =
featName.split(ConstantParameters.MULTILABELSEPARATOR);
boolean isStart = true;
for(int i = 0; i < numInstances; ++i) {
- Annotation annToken = (Annotation)annotationArray.get(i);
+ Annotation annToken = annotationArray.get(i);
if(annToken.overlaps(annEntity)) {
String featName0 = "";
if(isStart) {
@@ -336,17 +331,16 @@
positionArrStr[i] = obtainPositionStr(featurePosition[i]);
}
AnnotationSet anns = annotations.get(instanceType);
- ArrayList<Annotation>annotationArray = (anns == null || anns.isEmpty())
+ List<Annotation>annotationArray = (anns == null || anns.isEmpty())
? new ArrayList<Annotation>()
: new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
String[] features = new String[numTypes];
- int[] semanticTypes = new int[numTypes];
+ //int[] semanticTypes = new int[numTypes];
int numInstances0 = annotationArray.size();
AnnotationSet [] annsArray = new AnnotationSet[numTypes];
for(int j=0; j<numTypes; ++j) {
- annsArray[j] = (AnnotationSet)annotations
- .get(typesGate[j]);
+ annsArray[j] = annotations.get(typesGate[j]);
}
for(int i = 0; i < numInstances0; ++i) {
// for class
@@ -355,10 +349,10 @@
// for each attribute in different positions, get the token in
// the corresponding position
if(featurePosition[j] == 0)
- annToken = (Annotation)annotationArray.get(i);
+ annToken = annotationArray.get(i);
else if((featurePosition[j] < 0 && i + featurePosition[j] >= 0)
|| (featurePosition[j] > 0 && i + featurePosition[j] <
numInstances0))
- annToken = (Annotation)annotationArray.get(i + featurePosition[j]);
+ annToken = annotationArray.get(i + featurePosition[j]);
else continue;
if(typesGate[j].equals(instanceType)) {
@@ -366,7 +360,7 @@
Object featObject = annToken.getFeatures().get(featuresGate[j]);
if(featObject != null) {
- features[j] = (String)featObject.toString();
+ features[j] = featObject.toString();
} else {
features[j]=null;
}
@@ -409,9 +403,9 @@
}
/** Get the N-gram features from the GATE document. */
public void gatedoc2NgramFeaturesArg(AnnotationSet annotations,
- String instanceType, java.util.List ngrams, boolean[][] isArgInRel, int
initialPosition) {
+ String instanceType, List<Ngram> ngrams, boolean[][] isArgInRel, int
initialPosition) {
AnnotationSet anns = annotations.get(instanceType);
- ArrayList<Annotation>annotationArray = (anns == null || anns.isEmpty())
+ List<Annotation>annotationArray = (anns == null || anns.isEmpty())
? new ArrayList<Annotation>()
: new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
@@ -419,7 +413,7 @@
int numNgrams = ngrams.size();
// For each ngram
for(int i1 = 0; i1 < numNgrams; ++i1) {
- Ngram ngram = (Ngram)ngrams.get(i1);
+ Ngram ngram = ngrams.get(i1);
String nameOfNgram = ngram.getName();
int ngramPosition = ngram.position;
if(ngramPosition>=0) ngramPosition += initialPosition;
@@ -436,7 +430,7 @@
}
AnnotationSet [] annsArray = new AnnotationSet[consNum];
for(int j=0; j<consNum; ++j) {
- annsArray[j] = (AnnotationSet)annotations.get(typeGateNgram[j]);
+ annsArray[j] = annotations.get(typeGateNgram[j]);
}
for(int i = 0; i < numInstances0; ++i) {
Annotation annToken = annotationArray.get(i);
@@ -469,13 +463,12 @@
+ NLPFeaturesList.SYMBOLNGARM);
}
}
- Hashtable<String,Integer>ngramTerms = new Hashtable<String,Integer>();
+ Map<String,Integer>ngramTerms = new HashMap<String,Integer>();
for(int j = 0; j < featuresNgram.length; ++j)
if(!ngramTerms.containsKey(featuresNgram[j].toString()))
- ngramTerms.put(featuresNgram[j].toString(), new Integer(1));
+ ngramTerms.put(featuresNgram[j].toString(), 1);
else ngramTerms.put(featuresNgram[j].toString(),
- new Integer(ngramTerms
- .get(featuresNgram[j].toString()).intValue() + 1));
+ ngramTerms.get(featuresNgram[j].toString()) + 1);
List<String>keys = new ArrayList<String>(ngramTerms.keySet());
Collections.sort(keys);
//Iterator iterator = keys.iterator();
@@ -525,15 +518,15 @@
positionArrStr[i] = obtainPositionStr(featurePosition[i]);
}
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
String[] features = new String[numTypes];
int numInstances0 = annotationArray.size();
AnnotationSet [] annsArray = new AnnotationSet[numTypes];
for(int j=0; j<numTypes; ++j) {
- annsArray[j] = (AnnotationSet)annotations
+ annsArray[j] = annotations
.get(typesGate[j]);
}
for(int i = 0; i < numInstances0; ++i) {
@@ -543,10 +536,10 @@
// for each attribute in different positions, get the token in
// the corresponding position
if(featurePosition[j] == 0)
- annToken = (Annotation)annotationArray.get(i);
+ annToken = annotationArray.get(i);
else if((featurePosition[j] < 0 && i + featurePosition[j] >= 0)
|| (featurePosition[j] > 0 && i + featurePosition[j] <
numInstances0))
- annToken = (Annotation)annotationArray.get(i + featurePosition[j]);
+ annToken = annotationArray.get(i + featurePosition[j]);
else continue;
if(typesGate[j].equals(instanceType)) {
features[j] = (String)annToken.getFeatures().get(featuresGate[j]);//
types[i];
@@ -572,7 +565,7 @@
if(featuresInLine[ii] == null)
featuresInLine[ii] = new StringBuffer();
for(int j = 0; j < numTypes; ++j) {
- if(features[j] instanceof String) {
+ if(features[j] != null) {
++numCounted;
//if(positionNum[j]!=0)
this.featuresInLine[ii].append(features[j]
@@ -599,24 +592,24 @@
String relInstanceType, String instanceType, String relArgF, String argF) {
// Get the intance array
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
// Get the relation intance array
AnnotationSet relAnns = annotations.get(relInstanceType);
- ArrayList relAnnotationArray = (relAnns == null || relAnns.isEmpty())
- ? new ArrayList()
- : new ArrayList(relAnns);
+ List<Annotation> relAnnotationArray = (relAnns == null || relAnns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(relAnns);
Collections.sort(relAnnotationArray, new OffsetComparator());
// Assign the match
boolean[][] isArgInRel = new
boolean[annotationArray.size()][relAnnotationArray
.size()];
for(int i = 0; i < annotationArray.size(); ++i) {
- Annotation ann = (Annotation)annotationArray.get(i);
+ Annotation ann = annotationArray.get(i);
String argV = ann.getFeatures().get(argF).toString();
for(int ii = 0; ii < relAnnotationArray.size(); ++ii) {
- String argRelV = ((Annotation)relAnnotationArray.get(ii)).getFeatures()
+ String argRelV = relAnnotationArray.get(ii).getFeatures()
.get(relArgF).toString();
if(argV.equals(argRelV))
isArgInRel[i][ii] = true;
@@ -629,12 +622,12 @@
/** Get the annotation with different type from the instance. */
String obtainAnnotationForTypeAndFeature(AnnotationSet singleAnnSet,
String gateFeature, Long tokenStartOffset, Long tokenEndOffset) {
- if(singleAnnSet instanceof AnnotationSet) {
- AnnotationSet coverAnnSet = (AnnotationSet)singleAnnSet.get(
+ if(singleAnnSet != null) {
+ AnnotationSet coverAnnSet = singleAnnSet.get(
tokenStartOffset, tokenEndOffset);
- Iterator overlappingIterator = coverAnnSet.iterator();
+ Iterator<Annotation> overlappingIterator = coverAnnSet.iterator();
if(overlappingIterator.hasNext()) {
- Annotation superannotation = (Annotation)overlappingIterator.next();
+ Annotation superannotation = overlappingIterator.next();
return (String)superannotation.getFeatures().get(gateFeature);
}
}
@@ -647,10 +640,10 @@
*/
String obtainAnnotationForTypeAndFeatureRel(String arg1V, String arg2V,
AnnotationSet singleAnnSet, String gateFeature, String arg1F, String
arg2F) {
- if(singleAnnSet instanceof AnnotationSet) {
- Iterator overlappingIterator = singleAnnSet.iterator();
+ if(singleAnnSet != null) {
+ Iterator<Annotation> overlappingIterator = singleAnnSet.iterator();
if(overlappingIterator.hasNext()) {
- Annotation superannotation = (Annotation)overlappingIterator.next();
+ Annotation superannotation = overlappingIterator.next();
FeatureMap feat0 = superannotation.getFeatures();
if(arg1V.equals(feat0.get(arg1F)) && arg2V.equals(feat0.get(arg2F))) {
String feat = feat0.get(gateFeature).toString();
@@ -679,19 +672,19 @@
strPosition[i] = obtainPositionStr(featurePosition[i]);
}
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
if(numInstances != annotationArray.size()) {
System.out.println("!!Warning: the number of instances "
- + new Integer(numInstances) + " in the document " + docId
+ + numInstances + " in the document " + docId
+ " is not right!!!");
return;
}
AnnotationSet [] annsArray = new AnnotationSet[numTypes];
for(int j=0; j<numTypes; ++j) {
- annsArray[j] = (AnnotationSet)annotations
+ annsArray[j] = annotations
.get(typesGate[j]);
}
String[] features = new String[numTypes];
@@ -702,10 +695,10 @@
// for each attribute in different positions, get the token in
// the corresponding position
if(featurePosition[j] == 0)
- annToken = (Annotation)annotationArray.get(i);
+ annToken = annotationArray.get(i);
else if((featurePosition[j] < 0 && i + featurePosition[j] >= 0)
|| (featurePosition[j] > 0 && i + featurePosition[j] < numInstances))
- annToken = (Annotation)annotationArray.get(i + featurePosition[j]);
+ annToken = annotationArray.get(i + featurePosition[j]);
else continue;
FeatureMap feat = annToken.getFeatures();
String arg1Value = feat.get(arg1s[j]).toString();
@@ -731,7 +724,7 @@
int numCounted = 0;
if(featuresInLine[i] == null) featuresInLine[i] = new StringBuffer();
for(int j = 0; j < numTypes; ++j)
- if(features[j] instanceof String) {
+ if(features[j] != null) {
++numCounted;
//if(featurePosition[j]!=0)
this.featuresInLine[i].append(features[j]
@@ -755,9 +748,9 @@
String instanceType, String arg1Inst, String arg2Inst, String classType,
String classFeature, String arg1C, String arg2C) {
AnnotationSet anns = annotations.get(instanceType);
- ArrayList annotationArray = (anns == null || anns.isEmpty())
- ? new ArrayList()
- : new ArrayList(anns);
+ List<Annotation> annotationArray = (anns == null || anns.isEmpty())
+ ? new ArrayList<Annotation>()
+ : new ArrayList<Annotation>(anns);
Collections.sort(annotationArray, new OffsetComparator());
if(numInstances != annotationArray.size()) {
System.out.println("!!Warning: the number of instances "
@@ -779,7 +772,7 @@
String arg2CV = annEntity.getFeatures().get(arg2C).toString();
boolean isStart = true;
for(int i = 0; i < numInstances; ++i) {
- Annotation annToken = (Annotation)annotationArray.get(i);
+ Annotation annToken = annotationArray.get(i);
FeatureMap feats = annToken.getFeatures();
if(arg1CV.equals(feats.get(arg1Inst))
&& arg2CV.equals(feats.get(arg2Inst))) {
@@ -789,7 +782,7 @@
isStart = false;
}
if(featName0.length() > 0) {
- if(this.classNames[i] instanceof String)
+ if(this.classNames[i] != null)
this.classNames[i] += ConstantParameters.ITEMSEPARATOR
+ featName0;
else this.classNames[i] = featName0;
@@ -822,7 +815,7 @@
+ new Integer(numInstances));
out.newLine();
for(int i = 0; i < numInstances; ++i) {
- if(classNames[i] instanceof String) {
+ if(classNames[i] != null) {
int num =
classNames[i].split(ConstantParameters.ITEMSEPARATOR).length;
out.write(num + ConstantParameters.ITEMSEPARATOR + classNames[i]
+ ConstantParameters.ITEMSEPARATOR
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs