Revision: 19740
http://sourceforge.net/p/gate/code/19740
Author: markagreenwood
Date: 2016-11-15 17:25:30 +0000 (Tue, 15 Nov 2016)
Log Message:
-----------
some minor performance improvements
Modified Paths:
--------------
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcher.java
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcherHelper.java
Modified:
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcher.java
===================================================================
---
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcher.java
2016-11-15 16:02:46 UTC (rev 19739)
+++
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcher.java
2016-11-15 17:25:30 UTC (rev 19740)
@@ -50,7 +50,6 @@
import gate.Annotation;
import gate.AnnotationSet;
import gate.Resource;
-import gate.creole.ANNIEConstants;
import gate.creole.AbstractLanguageAnalyser;
import gate.creole.ExecutionException;
import gate.creole.ResourceInstantiationException;
@@ -64,7 +63,7 @@
import gate.util.OffsetComparator;
import gate.util.Out;
@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 implements
ANNIEConstants {
+public class OrthoMatcher extends AbstractLanguageAnalyser {
private static final long serialVersionUID = -6258229350677707465L;
@@ -166,10 +165,10 @@
protected Annotation shortAnnot;
protected Annotation longAnnot;
- protected ArrayList<Annotation> tokensLongAnnot;
- protected ArrayList<Annotation> tokensShortAnnot;
+ protected List<Annotation> tokensLongAnnot;
+ protected List<Annotation> tokensShortAnnot;
- protected ArrayList<Annotation> normalizedTokensLongAnnot,
normalizedTokensShortAnnot;
+ protected List<Annotation> normalizedTokensLongAnnot,
normalizedTokensShortAnnot;
/**
* URL to the file containing the definition for this orthomatcher
@@ -588,12 +587,11 @@
else
newType = matchedAnnot.getType();
- Integer newID = new Integer(-1);
+ Integer newID;
try {
newID = nameAllAnnots.add(
unknown.getStartNode().getOffset(),
- new Long(unknown.getStartNode().getOffset().longValue()
- + stringEnd),
+ unknown.getStartNode().getOffset() + stringEnd,
newType,
unknown.getFeatures()
);
@@ -770,10 +768,10 @@
longerPrevious = false;
}//if
- tokensLongAnnot = (ArrayList<Annotation>) tokensMap.get(longAnnot.getId());
- normalizedTokensLongAnnot = (ArrayList<Annotation>)
normalizedTokensMap.get(longAnnot.getId());
- tokensShortAnnot = (ArrayList<Annotation>)
tokensMap.get(shortAnnot.getId());
- normalizedTokensShortAnnot = (ArrayList<Annotation>)
normalizedTokensMap.get(shortAnnot.getId());
+ tokensLongAnnot = tokensMap.get(longAnnot.getId());
+ normalizedTokensLongAnnot = normalizedTokensMap.get(longAnnot.getId());
+ tokensShortAnnot = tokensMap.get(shortAnnot.getId());
+ normalizedTokensShortAnnot = normalizedTokensMap.get(shortAnnot.getId());
@SuppressWarnings("unchecked")
List<Integer> matchesList = (List<Integer>) prevAnnot.getFeatures().
@@ -856,10 +854,10 @@
longerPrevious = false;
}//if
- tokensLongAnnot = (ArrayList<Annotation>)
tokensMap.get(longAnnot.getId());
- normalizedTokensLongAnnot = (ArrayList<Annotation>)
normalizedTokensMap.get(longAnnot.getId());
- tokensShortAnnot = (ArrayList<Annotation>)
tokensMap.get(shortAnnot.getId());
- normalizedTokensShortAnnot = (ArrayList<Annotation>)
normalizedTokensMap.get(shortAnnot.getId());
+ tokensLongAnnot = tokensMap.get(longAnnot.getId());
+ normalizedTokensLongAnnot = normalizedTokensMap.get(longAnnot.getId());
+ tokensShortAnnot = tokensMap.get(shortAnnot.getId());
+ normalizedTokensShortAnnot =
normalizedTokensMap.get(shortAnnot.getId());
matchedAll = apply_rules_namematch(prevAnnot.getType(),
shortName,longName,prevAnnot,newAnnot,
longerPrevious);
@@ -902,7 +900,7 @@
static Pattern periodPat = Pattern.compile("[\\.]+");
protected void normalizePersonName (Annotation annot) throws
ExecutionException {
- ArrayList<Annotation> tokens = (ArrayList<Annotation>)
normalizedTokensMap.get(annot.getId());
+ List<Annotation> tokens = normalizedTokensMap.get(annot.getId());
for (int i = tokens.size() - 1; i >= 0; i--) {
String tokenString = ((String)
tokens.get(i).getFeatures().get(TOKEN_STRING_FEATURE_NAME));
String kind = (String)
tokens.get(i).getFeatures().get(TOKEN_KIND_FEATURE_NAME);
@@ -917,7 +915,7 @@
}
}
- ArrayList<Annotation> normalizedTokens = new ArrayList<Annotation>(tokens);
+ List<Annotation> normalizedTokens = new ArrayList<Annotation>(tokens);
for (int j = normalizedTokens.size() - 1; j >= 0;j--) {
if (normalizedTokens.get(j).getFeatures().containsKey("ortho_stop")) {
// log.debug("Now removing " +
normalizedTokens.get(j).getFeatures().get(TOKEN_STRING_FEATURE_NAME));
@@ -931,7 +929,7 @@
/** return an organization without a designator and starting The*/
protected String normalizeOrganizationName (String annotString, Annotation
annot){
- ArrayList<Annotation> tokens = (ArrayList<Annotation>)
tokensMap.get(annot.getId());
+ List<Annotation> tokens = tokensMap.get(annot.getId());
//strip starting The first
if ( ((String) tokens.get(0).getFeatures().get(TOKEN_STRING_FEATURE_NAME))
@@ -1236,17 +1234,17 @@
}
public Boolean getExtLists() {
- return new Boolean(extLists);
+ return extLists;
}
/** Are we running in a case-sensitive mode?*/
public Boolean getCaseSensitive() {
- return new Boolean(caseSensitive);
+ return caseSensitive;
}
/** Return whether or not we're processing the Unknown annots*/
public Boolean getProcessUnknown() {
- return new Boolean(matchingUnknowns);
+ return matchingUnknowns;
}
@@ -1282,7 +1280,7 @@
* returns true if it detects a middle name which indicates that the name
string contains a nickname or a
* compound last name
*/
- private boolean detectBadMiddleTokens(ArrayList<Annotation> tokArray) {
+ private boolean detectBadMiddleTokens(List<Annotation> tokArray) {
for (int j = 1;j < tokArray.size() - 1;j++) {
String currentToken = (String)
tokArray.get(j).getFeatures().get(TOKEN_STRING_FEATURE_NAME);
Matcher matcher =
badMiddleTokens.matcher(currentToken.toLowerCase().trim());
Modified:
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcherHelper.java
===================================================================
---
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcherHelper.java
2016-11-15 16:02:46 UTC (rev 19739)
+++
gate/branches/sawdust2/plugins/ANNIE/src/main/java/gate/creole/orthomatcher/OrthoMatcherHelper.java
2016-11-15 17:25:30 UTC (rev 19740)
@@ -100,9 +100,9 @@
if (rulesUsedTable!=null) {
log.debug("Saving table of used orthomatcher rules:");
- String table="";
+ StringBuilder table=new StringBuilder();
- for(int i=0;i<rulesUsedTable.length;i++) table+="Rule: "+i+" fired:
"+rulesUsedTable[i]+"\r\n";
+ for(int i=0;i<rulesUsedTable.length;i++) table.append("Rule:
").append(i).append(" fired: ").append(rulesUsedTable[i]).append("\r\n");
log.debug(table);
log.debug("End of table of used Orthomatcher rules");
@@ -150,14 +150,14 @@
Arrays.sort(temp);
//decode from temp
- String result="";
+ StringBuilder result=new StringBuilder();
for(int n: temp) {
int a = n / ceil;
int b = n % ceil;
- result=result+a+":"+b+", ";
+ result.append(a).append(":").append(b).append(", ");
}
- return result;
+ return result.toString();
}
else return input;//we do not need to sort a single pair
}
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