Fixed date evaluation and NameValue string. Also added more tests.

Conflicts:
	src/edu/stanford/nlp/sempre/tables/lambdadcs/LambdaDCSExecutorTest.java
This commit is contained in:
Panupong Pasupat 2016-08-17 19:39:38 -07:00
parent 995ef44844
commit ba59a2a083
5 changed files with 31 additions and 8 deletions

View File

@ -608,13 +608,19 @@ public class TableKnowledgeGraph extends KnowledgeGraph implements FuzzyMatchabl
return null;
}
public Value getNameValueWithOriginalString(NameValue value) {
if (value.description == null)
value = new NameValue(value.id, getOriginalString(value.id));
return value;
}
public ListValue getListValueWithOriginalStrings(ListValue answers) {
List<Value> values = new ArrayList<>();
for (Value value : answers.values) {
if (value instanceof NameValue) {
NameValue name = (NameValue) value;
if (name.description == null)
value = new NameValue(name.id, getOriginalString(((NameValue) value).id));
value = new NameValue(name.id, getOriginalString(name.id));
}
values.add(value);
}

View File

@ -23,6 +23,8 @@ public class TableValueEvaluator implements ValueEvaluator {
public boolean allowNormalizedStringMatch = true;
@Option(gloss = "When comparing number values, only consider the value and not the unit")
public boolean ignoreNumberValueUnits = true;
@Option(gloss = "Strict date evaluation (year, month, and date all have to match)")
public boolean strictDateEvaluation = false;
}
public static Options opts = new Options();
@ -113,11 +115,15 @@ public class TableValueEvaluator implements ValueEvaluator {
}
protected boolean compareDateValues(DateValue target, DateValue pred) {
// If a field in target is not blank (-1), pred must match target on that field
if (target.year != -1 && target.year != pred.year) return false;
if (target.month != -1 && target.month != pred.month) return false;
if (target.day != -1 && target.day != pred.day) return false;
return true;
if (opts.strictDateEvaluation) {
return target.equals(pred);
} else {
// If a field in target is not blank (-1), pred must match target on that field
if (target.year != -1 && target.year != pred.year) return false;
if (target.month != -1 && target.month != pred.month) return false;
if (target.day != -1 && target.day != pred.day) return false;
return true;
}
}
}

View File

@ -205,6 +205,8 @@ class LambdaDCSCoreLogic {
// Rule out binaries
if (CanonicalNames.isBinary(value) && LambdaDCSExecutor.opts.executeBinary)
throw new LambdaDCSException(Type.notUnary, "[Unary] Binary value %s", formula);
if (value instanceof NameValue && graph instanceof TableKnowledgeGraph)
value = ((TableKnowledgeGraph) graph).getNameValueWithOriginalString((NameValue) value);
// Other cases
return typeHint.applyBound(new ExplicitUnaryDenotation(value));
}

View File

@ -4,6 +4,7 @@ import java.util.*;
import fig.basic.*;
import edu.stanford.nlp.sempre.*;
import edu.stanford.nlp.sempre.corenlp.CoreNLPAnalyzer;
import edu.stanford.nlp.sempre.tables.TableKnowledgeGraph;
import org.testng.annotations.Test;
@ -253,8 +254,9 @@ public class LambdaDCSExecutorTest {
"(and (!= (and (!= fb:cell.away) fb:cell.home)) ((reverse fb:row.row.opponent) (fb:row.row.index (- (number 1) (number 1)))))",
graph, matches("(name fb:cell.derby_county)"));
}
@Test(groups = "lambdaCSV3") public void lambdaOnGraphCSV3Test() {
LanguageAnalyzer.setSingleton(new CoreNLPAnalyzer());
KnowledgeGraph graph = getKnowledgeGraph("csv3");
runFormula(executor,
"(count (fb:type.object.type fb:type.row))",
@ -262,5 +264,12 @@ public class LambdaDCSExecutorTest {
runFormula(executor,
"(count (fb:row.row.opened (fb:cell.cell.date (< (date 1926 -1 -1)))))",
graph, matches("(number 6)"));
runFormula(executor,
"(sum (- (count ((reverse fb:row.row.index) (fb:type.object.type fb:type.row))) " +
"((reverse fb:row.row.index) (fb:row.row.latitude ((reverse fb:row.row.longitude) (fb:type.object.type fb:type.row))))))",
graph, matches("(number 6)"));
runFormula(executor,
"(- (number 1926) (argmax (number 1) (number 1) ((reverse fb:cell.cell.number) (or (or (or fb:cell.1920 fb:cell.1925) fb:cell.1926) fb:cell.1946)) (reverse (lambda x (sum ((reverse fb:cell.cell.number) (fb:cell.cell.number (var x))))))))",
graph, matches("(number 6)"));
}
}

View File

@ -5,7 +5,7 @@
If the file is tab-separated, only process the first column.
"""
import sys, os, shutil, re, argparse, json
import sys, os, shutil, re, argparse, json, gzip
from codecs import open
from itertools import izip
from collections import defaultdict