Reduce memory churn in RDRPOSTagger

This commit is contained in:
Viktor Lofgren 2023-01-30 09:25:57 +01:00
parent 618582dc74
commit 1f646e4f68
3 changed files with 15 additions and 6 deletions

View File

@ -36,4 +36,13 @@ public class FWObject
context = new String[13];
}
}
public void reset(boolean check) {
if (check) {
System.arraycopy(contextPrototype, 0, context, 0, 13);
}
else {
Arrays.fill(context, null);
}
}
}

View File

@ -103,8 +103,10 @@ public class RDRPOSTagger
var initialTags = InitialTagger.EnInitTagger4Sentence(FREQDICT, sentence);
String[] tags = new String[initialTags.length];
FWObject object = new FWObject(true);
for (int i = 0; i < initialTags.length; i++) {
FWObject object = Utils.getObject(sentence, initialTags, initialTags.length, i);
Utils.getObject(object, sentence, initialTags, initialTags.length, i);
tags[i] = findFiredNode(object).conclusion;
}

View File

@ -123,9 +123,9 @@ public class Utils
return condition;
}
public static FWObject getObject(String[] words, String[] tags, int size, int index)
public static FWObject getObject(FWObject object, String[] words, String[] tags, int size, int index)
{
FWObject object = new FWObject(true);
object.reset(true);
if (index > 1) {
object.context[4] = words[index-2];
@ -175,9 +175,7 @@ public class Utils
else
return "<T>";
}
String conclusion = str.substring(str.indexOf("\"") + 1,
str.length() - 1);
return conclusion;
return str.substring(str.indexOf("\"") + 1, str.length() - 1);
}
public static void main(String[] args)