Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,13 @@ private void findErrors(Span[] references, Span[] predictions,
falseNegatives.addAll(Arrays.asList(references));
falsePositives.addAll(Arrays.asList(predictions));

for (int referenceIndex = 0; referenceIndex < references.length; referenceIndex++) {
for (Span referenceName : references) {

Span referenceName = references[referenceIndex];

for (int predictedIndex = 0; predictedIndex < predictions.length; predictedIndex++) {
if (referenceName.equals(predictions[predictedIndex])) {
for (Span prediction : predictions) {
if (referenceName.equals(prediction)) {
// got it, remove from fn and fp
falseNegatives.remove(referenceName);
falsePositives.remove(predictions[predictedIndex]);
falsePositives.remove(prediction);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void run(String[] args) {
List<Span> linkedSpans =
entityLinker.find(text.toString(), sentences, tokensBySentence, namesBySentence);

for (int i = 0; i < linkedSpans.size(); i++) {
System.out.println(linkedSpans.get(i));
for (Span linkedSpan : linkedSpans) {
System.out.println(linkedSpan);
}

perfMon.incrementCounter(document.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ protected void processRoot(Node root, List<String> sentence, List<String> tags,
List<String> target) {
if (root != null) {
TreeElement[] elements = root.getElements();
for (int i = 0; i < elements.length; i++) {
if (elements[i].isLeaf()) {
processLeaf((Leaf) elements[i], false, OTHER, sentence, tags, target);
for (TreeElement element : elements) {
if (element.isLeaf()) {
processLeaf((Leaf) element, false, OTHER, sentence, tags, target);
} else {
processNode((Node) elements[i], sentence, tags, target, null);
processNode((Node) element, sentence, tags, target, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,13 @@ public void endElement(String uri, String localName, String qName)
String txt = text.toString();
int tokenIndex = -1;
Parse p = new Parse(txt, new Span(0, txt.length()), AbstractBottomUpParser.TOP_NODE, 1,0);
for (int ci = 0; ci < cons.size(); ci++) {
Constituent con = cons.get(ci);
for (Constituent con : cons) {
String type = con.getLabel();
if (!type.equals(AbstractBottomUpParser.TOP_NODE)) {
if (AbstractBottomUpParser.TOK_NODE.equals(type)) {
tokenIndex++;
}
Parse c = new Parse(txt, con.getSpan(), type, 1,tokenIndex);
Parse c = new Parse(txt, con.getSpan(), type, 1, tokenIndex);
p.insert(c);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public String[] getContext(int index, String[] toks, String[] tags, String[] pre

// do some basic suffix analysis
String[] suffs = getSuffixes(lex);
for (int i = 0; i < suffs.length; i++) {
features.add("suf=" + suffs[i]);
for (String suff : suffs) {
features.add("suf=" + suff);
}

String[] prefs = getPrefixes(lex);
for (int i = 0; i < prefs.length; i++) {
features.add("pre=" + prefs[i]);
for (String pref : prefs) {
features.add("pre=" + pref);
}
// see if the word has any special characters
if (lex.indexOf('-') != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public String[] lemmatize(String[] toks, String[] tags) {
String[] posTags = tags.toArray(new String[tags.size()]);
String[][] allLemmas = predictLemmas(LEMMA_NUMBER, tokens, posTags);
List<List<String>> predictedLemmas = new ArrayList<>();
for (int i = 0; i < allLemmas.length; i++) {
predictedLemmas.add(Arrays.asList(allLemmas[i]));
for (String[] allLemma : allLemmas) {
predictedLemmas.add(Arrays.asList(allLemma));
}
return predictedLemmas;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ protected String[] getPredicates() throws java.io.IOException {
protected Context[] getParameters(int[][] outcomePatterns) throws java.io.IOException {
Context[] params = new Context[NUM_PREDS];
int pid = 0;
for (int i = 0; i < outcomePatterns.length; i++) {
for (int[] pattern : outcomePatterns) {
//construct outcome pattern
int[] outcomePattern = new int[outcomePatterns[i].length - 1];
System.arraycopy(outcomePatterns[i], 1, outcomePattern, 0, outcomePatterns[i].length - 1);
int[] outcomePattern = new int[pattern.length - 1];
System.arraycopy(pattern, 1, outcomePattern, 0, pattern.length - 1);

//populate parameters for each context which uses this outcome pattern.
for (int j = 0; j < outcomePatterns[i][0]; j++) {
double[] contextParameters = new double[outcomePatterns[i].length - 1];
for (int k = 1; k < outcomePatterns[i].length; k++) {
for (int j = 0; j < pattern[0]; j++) {
double[] contextParameters = new double[pattern.length - 1];
for (int k = 1; k < pattern.length; k++) {
contextParameters[k - 1] = readDouble();
}
params[pid] = new Context(outcomePattern,contextParameters);
params[pid] = new Context(outcomePattern, contextParameters);
pid++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public NaiveBayesModel(Context[] params, String[] predLabels, String[] outcomeNa

protected double[] initOutcomeTotals(String[] outcomeNames, Context[] params) {
double[] outcomeTotals = new double[outcomeNames.length];
for (int i = 0; i < params.length; ++i) {
Context context = params[i];
for (Context context : params) {
for (int j = 0; j < context.getOutcomes().length; ++j) {
int outcome = context.getOutcomes()[j];
double count = context.getParameters()[j];
Expand Down Expand Up @@ -114,8 +113,8 @@ static double[] eval(Context[] context, float[] values, double[] prior,
}
}
double total = 0;
for (int i = 0; i < outcomeTotals.length; ++i) {
total += outcomeTotals[i];
for (double outcomeTotal : outcomeTotals) {
total += outcomeTotal;
}
for (int i = 0; i < outcomeTotals.length; ++i) {
double numerator = outcomeTotals[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,19 @@ public boolean areOutcomesCompatible(String[] outcomes) {
Set<String> last = new HashSet<>();
Set<String> unit = new HashSet<>();

for (int i = 0; i < outcomes.length; i++) {
String outcome = outcomes[i];
for (String outcome : outcomes) {
if (outcome.endsWith(BilouCodec.START)) {
start.add(outcome.substring(0, outcome.length()
- BilouCodec.START.length()));
- BilouCodec.START.length()));
} else if (outcome.endsWith(BilouCodec.CONTINUE)) {
cont.add(outcome.substring(0, outcome.length()
- BilouCodec.CONTINUE.length()));
- BilouCodec.CONTINUE.length()));
} else if (outcome.endsWith(BilouCodec.LAST)) {
last.add(outcome.substring(0, outcome.length()
- BilouCodec.LAST.length()));
- BilouCodec.LAST.length()));
} else if (outcome.endsWith(BilouCodec.UNIT)) {
unit.add(outcome.substring(0, outcome.length()
- BilouCodec.UNIT.length()));
- BilouCodec.UNIT.length()));
} else if (!outcome.equals(BilouCodec.OTHER)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ public boolean areOutcomesCompatible(String[] outcomes) {
List<String> start = new ArrayList<>();
List<String> cont = new ArrayList<>();

for (int i = 0; i < outcomes.length; i++) {
String outcome = outcomes[i];
for (String outcome : outcomes) {
if (outcome.endsWith(BioCodec.START)) {
start.add(outcome.substring(0, outcome.length()
- BioCodec.START.length()));
- BioCodec.START.length()));
} else if (outcome.endsWith(BioCodec.CONTINUE)) {
cont.add(outcome.substring(0, outcome.length()
- BioCodec.CONTINUE.length()));
- BioCodec.CONTINUE.length()));
} else if (!outcome.equals(BioCodec.OTHER)) {
// got unexpected outcome
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ public void setErrorReporting(boolean errorReporting) {
*/
public static void setParents(Parse p) {
Parse[] children = p.getChildren();
for (int ci = 0; ci < children.length; ci++) {
children[ci].setParent(p);
setParents(children[ci]);
for (Parse child : children) {
child.setParent(p);
setParents(child);
}
}

Expand Down Expand Up @@ -318,19 +318,18 @@ else if (1 == derivationStage) {
nd = advanceParses(tp, Q);
}
if (nd != null) {
for (int k = 0, kl = nd.length; k < kl; k++) {
if (nd[k].complete()) {
advanceTop(nd[k]);
if (nd[k].getProb() > bestComplete) {
bestComplete = nd[k].getProb();
for (Parse parse : nd) {
if (parse.complete()) {
advanceTop(parse);
if (parse.getProb() > bestComplete) {
bestComplete = parse.getProb();
}
if (nd[k].getProb() < minComplete) {
minComplete = nd[k].getProb();
if (parse.getProb() < minComplete) {
minComplete = parse.getProb();
}
completeParses.add(nd[k]);
}
else {
ndh.add(nd[k]);
completeParses.add(parse);
} else {
ndh.add(parse);
}
}
}
Expand Down
Loading