Don't use schema restriction for protograph link suggest because it's not a "soft" restriction (so if the user wants a property that doesn't belong to the type, there is no way to get it).
More expression functions and controls. git-svn-id: http://google-refine.googlecode.com/svn/trunk@122 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
5e9be8c258
commit
4ed7b45e41
@ -11,18 +11,24 @@ import com.metaweb.gridworks.expr.Scanner.TokenType;
|
||||
import com.metaweb.gridworks.expr.controls.ForEach;
|
||||
import com.metaweb.gridworks.expr.controls.ForNonBlank;
|
||||
import com.metaweb.gridworks.expr.controls.If;
|
||||
import com.metaweb.gridworks.expr.controls.With;
|
||||
import com.metaweb.gridworks.expr.functions.And;
|
||||
import com.metaweb.gridworks.expr.functions.EndsWith;
|
||||
import com.metaweb.gridworks.expr.functions.Get;
|
||||
import com.metaweb.gridworks.expr.functions.IndexOf;
|
||||
import com.metaweb.gridworks.expr.functions.IsBlank;
|
||||
import com.metaweb.gridworks.expr.functions.IsNotBlank;
|
||||
import com.metaweb.gridworks.expr.functions.IsNotNull;
|
||||
import com.metaweb.gridworks.expr.functions.IsNull;
|
||||
import com.metaweb.gridworks.expr.functions.Join;
|
||||
import com.metaweb.gridworks.expr.functions.LastIndexOf;
|
||||
import com.metaweb.gridworks.expr.functions.Length;
|
||||
import com.metaweb.gridworks.expr.functions.Not;
|
||||
import com.metaweb.gridworks.expr.functions.Or;
|
||||
import com.metaweb.gridworks.expr.functions.Replace;
|
||||
import com.metaweb.gridworks.expr.functions.Slice;
|
||||
import com.metaweb.gridworks.expr.functions.Split;
|
||||
import com.metaweb.gridworks.expr.functions.StartsWith;
|
||||
import com.metaweb.gridworks.expr.functions.ToLowercase;
|
||||
import com.metaweb.gridworks.expr.functions.ToTitlecase;
|
||||
import com.metaweb.gridworks.expr.functions.ToUppercase;
|
||||
@ -47,6 +53,12 @@ public class Parser {
|
||||
functionTable.put("split", new Split());
|
||||
functionTable.put("length", new Length());
|
||||
|
||||
functionTable.put("indexOf", new IndexOf());
|
||||
functionTable.put("lastIndexOf", new LastIndexOf());
|
||||
functionTable.put("startsWith", new StartsWith());
|
||||
functionTable.put("endsWith", new EndsWith());
|
||||
functionTable.put("join", new Join());
|
||||
|
||||
functionTable.put("and", new And());
|
||||
functionTable.put("or", new Or());
|
||||
functionTable.put("not", new Not());
|
||||
@ -56,6 +68,7 @@ public class Parser {
|
||||
functionTable.put("isNotBlank", new IsNotBlank());
|
||||
|
||||
controlTable.put("if", new If());
|
||||
controlTable.put("with", new With());
|
||||
controlTable.put("forEach", new ForEach());
|
||||
controlTable.put("forNonBlank", new ForNonBlank());
|
||||
}
|
||||
|
@ -39,7 +39,11 @@ public class ForEach implements Control {
|
||||
|
||||
return results.toArray();
|
||||
} finally {
|
||||
bindings.put(name, oldValue);
|
||||
if (oldValue != null) {
|
||||
bindings.put(name, oldValue);
|
||||
} else {
|
||||
bindings.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
src/main/java/com/metaweb/gridworks/expr/controls/With.java
Normal file
36
src/main/java/com/metaweb/gridworks/expr/controls/With.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.metaweb.gridworks.expr.controls;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Control;
|
||||
import com.metaweb.gridworks.expr.Evaluable;
|
||||
import com.metaweb.gridworks.expr.VariableExpr;
|
||||
|
||||
public class With implements Control {
|
||||
|
||||
public Object call(Properties bindings, Evaluable[] args) {
|
||||
if (args.length >= 3) {
|
||||
Object o = args[0].evaluate(bindings);
|
||||
Evaluable var = args[1];
|
||||
String name = (var instanceof VariableExpr) ? ((VariableExpr) var).getName() :
|
||||
((String) var.evaluate(bindings));
|
||||
|
||||
if (o != null) {
|
||||
Object oldValue = bindings.get(name);
|
||||
try {
|
||||
bindings.put(name, o);
|
||||
|
||||
return args[2].evaluate(bindings);
|
||||
} finally {
|
||||
if (oldValue != null) {
|
||||
bindings.put(name, oldValue);
|
||||
} else {
|
||||
bindings.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class EndsWith implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).endsWith((String) s2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class IndexOf implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).indexOf((String) s2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
36
src/main/java/com/metaweb/gridworks/expr/functions/Join.java
Normal file
36
src/main/java/com/metaweb/gridworks/expr/functions/Join.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class Join implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object v = args[0];
|
||||
Object s = args[1];
|
||||
|
||||
if (v != null && v.getClass().isArray() &&
|
||||
s != null && s instanceof String) {
|
||||
|
||||
Object[] a = (Object[]) v;
|
||||
String separator = (String) s;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Object o : a) {
|
||||
if (o != null) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(separator);
|
||||
}
|
||||
sb.append(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class LastIndexOf implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).lastIndexOf((String) s2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.metaweb.gridworks.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.expr.Function;
|
||||
|
||||
public class StartsWith implements Function {
|
||||
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 2) {
|
||||
Object s1 = args[0];
|
||||
Object s2 = args[1];
|
||||
if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) {
|
||||
return ((String) s1).startsWith((String) s2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -223,8 +223,10 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
|
||||
List<CellChange> cellChanges = new ArrayList<CellChange>(_entries.size());
|
||||
List<String> values = new ArrayList<String>(valueToEntries.keySet());
|
||||
for (int i = 0; i < values.size(); i += 10) {
|
||||
recon(valueToEntries, values, i, Math.min(i + 10, values.size()), cellChanges);
|
||||
|
||||
final int batchSize = 20;
|
||||
for (int i = 0; i < values.size(); i += batchSize) {
|
||||
recon(valueToEntries, values, i, Math.min(i + batchSize, values.size()), cellChanges);
|
||||
|
||||
_progress = i * 100 / values.size();
|
||||
|
||||
@ -270,10 +272,10 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
jsonWriter.object();
|
||||
|
||||
jsonWriter.key("query"); jsonWriter.value(values.get(from + i));
|
||||
jsonWriter.key("limit"); jsonWriter.value(5);
|
||||
jsonWriter.key("limit"); jsonWriter.value(3);
|
||||
jsonWriter.key("type"); jsonWriter.value(_typeID);
|
||||
jsonWriter.key("type_strict"); jsonWriter.value("should");
|
||||
jsonWriter.key("indent"); jsonWriter.value(1);
|
||||
//jsonWriter.key("indent"); jsonWriter.value(1);
|
||||
jsonWriter.key("type_exclude"); jsonWriter.value("/common/image");
|
||||
jsonWriter.key("domain_exclude"); jsonWriter.value("/freebase");
|
||||
|
||||
@ -352,6 +354,8 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
cellChanges.add(cellChange);
|
||||
}
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
protected Recon createRecon(String text, JSONArray results) {
|
||||
|
@ -299,13 +299,16 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
|
||||
type : '/type/property'
|
||||
};
|
||||
if (this._link.target != null && "type" in this._link.target && this._link.target.type != null) {
|
||||
/*
|
||||
suggestOptions.mql_filter = [{
|
||||
"/type/property/expected_type" : {
|
||||
id: this._link.target.type.id
|
||||
}
|
||||
}];
|
||||
*/
|
||||
} else {
|
||||
var sourceTypeID = this._parentUINode.getExpectedType();
|
||||
/*
|
||||
if (sourceTypeID != null) {
|
||||
suggestOptions.mql_filter = [{
|
||||
"/type/property/schema" : {
|
||||
@ -313,6 +316,7 @@ SchemaAlignmentDialog.UILink.prototype._showPropertySuggestPopup = function(elmt
|
||||
}
|
||||
}];
|
||||
}
|
||||
*/
|
||||
}
|
||||
input.suggest(suggestOptions).bind("fb-select", function(e, data) { commitProperty(data); });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user