本文整理汇总了Java中com.sri.ai.util.Util.list方法的典型用法代码示例。如果您正苦于以下问题:Java Util.list方法的具体用法?Java Util.list怎么用?Java Util.list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sri.ai.util.Util
的用法示例。
在下文中一共展示了Util.list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* Compiles an expression to a normalized (decision-tree-like) expression.
* @param inputExpression
* @param mapFromVariableNameToTypeName
* @param mapFromCategoricalTypeNameToSizeString
* @param additionalTypes
* @param solverListener if not null, invoked on solver used for compilation, before and after compilation starts; returned solver on 'before' invocation is used (it may be the same one used as argument, of course).
* @return
*/
public static Expression compile(Expression inputExpression, Theory theory, Map<String, String> mapFromVariableNameToTypeName, Map<String, String> mapFromUniquelyNamedConstantToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Collection<Type> additionalTypes, Function<MultiQuantifierEliminator, MultiQuantifierEliminator> solverListener) {
AssociativeCommutativeGroup group = new Max(); // the group actually does not matter, because we are not going to have any indices.
// The solver for the parameters above.
MultiQuantifierEliminator solver = new DefaultMultiQuantifierEliminator();
if (solverListener != null) {
solver = solverListener.apply(solver);
}
// We use the Prolog convention of small-letter initials for constants, but we need an exception for the random variables.
Predicate<Expression> isPrologConstant = new PrologConstantPredicate();
Predicate<Expression> isUniquelyNamedConstantPredicate = e -> isPrologConstant.apply(e) && ! mapFromVariableNameToTypeName.containsKey(e);
Map<String, String> mapFromSymbolNameToTypeName = new LinkedHashMap<>(mapFromVariableNameToTypeName);
mapFromSymbolNameToTypeName.putAll(mapFromUniquelyNamedConstantToTypeName);
// Solve the problem.
List<Expression> indices = Util.list(); // no indices; we want to keep all variables
Expression result = solver.solve(group, inputExpression, indices, mapFromSymbolNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes, isUniquelyNamedConstantPredicate, theory);
if (solverListener != null) {
solverListener.apply(null);
}
return result;
}
示例2: makeDefaultIntensionalUniSetFromLabelAndSubTrees
import com.sri.ai.util.Util; //导入方法依赖的package包/类
private static Expression makeDefaultIntensionalUniSetFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
if (subTreeObjects.length == 1 && subTreeObjects[0] instanceof Collection) {
subTreeObjects = ((Collection) subTreeObjects[0]).toArray();
}
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
if (subTreeExpressions.size() == 1) {
subTreeExpressions = new ArrayList<Expression>(Expressions.ensureListFromKleeneList(subTreeExpressions.get(0)));
}
Expression scopingExpression = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(
(scopingExpression == null || scopingExpression.numberOfArguments() == 0)?
Util.list()
: new ArrayList<Expression>(Expressions.ensureListFromKleeneList(scopingExpression.get(0))));
Expression conditioningSyntaxTree = subTreeExpressions.get(2);
Expression condition = conditioningSyntaxTree == null? Expressions.TRUE : conditioningSyntaxTree.get(0);
Expression result = new DefaultIntensionalUniSet(indexExpressions, subTreeExpressions.get(1), condition);
return result;
}
示例3: makeDefaultIntensionalMultiSetFromLabelAndSubTrees
import com.sri.ai.util.Util; //导入方法依赖的package包/类
private static Expression makeDefaultIntensionalMultiSetFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
if (subTreeObjects.length == 1 && subTreeObjects[0] instanceof Collection) {
subTreeObjects = ((Collection) subTreeObjects[0]).toArray();
}
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
if (subTreeExpressions.size() == 1) {
subTreeExpressions = new ArrayList<Expression>(Expressions.ensureListFromKleeneList(subTreeExpressions.get(0)));
}
Expression scopingExpression = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(
(scopingExpression == null || scopingExpression.numberOfArguments() == 0)?
Util.list()
: new ArrayList<Expression>(Expressions.ensureListFromKleeneList(scopingExpression.get(0))));
Expression conditioningSyntaxTree = subTreeExpressions.get(2);
Expression condition = conditioningSyntaxTree == null? Expressions.TRUE : conditioningSyntaxTree.get(0);
Expression result = new DefaultIntensionalMultiSet(indexExpressions, subTreeExpressions.get(1), condition);
return result;
}
示例4: testSubRangeIterator
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void testSubRangeIterator() {
SubRangeIterator<String> i;
List<String> expected;
i =
new SubRangeIterator<String>(
Util.iterator("a", "b", "c"),
1, 3);
expected = Util.list("b", "c");
assertEquals(expected, Util.listFrom(i));
i =
new SubRangeIterator<String>(
Util.iterator("a", "b", "c"),
0, 0);
expected = Collections.emptyList();
assertEquals(expected, Util.listFrom(i));
i =
new SubRangeIterator<String>(
Util.iterator("a", "b", "c"),
0, 4);
expected = Util.list("a", "b", "c");
assertEquals(expected, Util.listFrom(i));
}
示例5: makeIntensionalSet
import com.sri.ai.util.Util; //导入方法依赖的package包/类
protected Expression makeIntensionalSet(Object label, Token scope, List<AntlrGrinderParser.ExprContext> scopeargs,
AntlrGrinderParser.ExprContext head, AntlrGrinderParser.ExprContext condition) {
List<Expression> indexExpressionsList = Util.list();
if (scope != null) {
indexExpressionsList = expressionsList(scopeargs);
}
Expression headExpression = visit(head);
Expression conditionExpression = null;
if (condition != null) {
conditionExpression = Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(IntensionalSet.CONDITION_LABEL, visit(condition));
}
Expression result = null;
if (scope == null && conditionExpression == null) {
// We need to construct an extensional set in this case
if (label.equals(IntensionalSet.UNI_SET_LABEL)) {
result = ExtensionalSets.makeUniSet(headExpression);
}
else {
result = ExtensionalSets.makeMultiSet(Arrays.asList(headExpression));
}
}
else {
conditionExpression = conditionExpression == null? Expressions.TRUE : conditionExpression.get(0); // contains the "|";
result = IntensionalSet.make(label, new ExtensionalIndexExpressionsSet(indexExpressionsList), headExpression, conditionExpression);
}
return result;
}
示例6: getMultiplicands
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* Returns the list of multiplicands in a product expression,
* including a singleton list with the expression itself if it is not a product
* (since then it can be considered the only multiplicand in a "unary product").
*/
public static List<Expression> getMultiplicands(Expression expression) {
if (expression.hasFunctor("*")) {
return expression.getArguments();
}
return Util.list(expression);
}
示例7: getDisjuncts
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* If given condition is a disjunction, returns list of disjuncts.
* Otherwise, returns singleton list with condition itself.
*/
public static List<Expression> getDisjuncts(Expression condition) {
if (condition.hasFunctor(FunctorConstants.OR)) {
return condition.getArguments();
}
return Util.list(condition);
}
示例8: getConjuncts
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* If given condition is a conjunction, returns list of conjuncts.
* Otherwise, returns singleton list with condition itself.
*/
public static List<Expression> getConjuncts(Expression condition) {
if (condition.hasFunctor(FunctorConstants.AND)) {
return condition.getArguments();
}
return Util.list(condition);
}
示例9: getArgumentsOfNormalizedApplicationOf
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* If expression is an application of functor, returns its arguments.
* If not, assumes that it is equivalent to <code>functor(expression)</code>
* (a property of commutative associative functions)
* and returns its arguments, that is, a singleton collection containing expression.
*/
public static List<Expression> getArgumentsOfNormalizedApplicationOf(Object functor, Expression expression) {
if (expression.hasFunctor(functor)) {
return expression.getArguments();
}
return Util.list(expression);
}
示例10: takeFormulaAsConjunctionAndReturnConjuncts
import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
* Takes a formula and, if it is a conjunction, returns the list of conjuncts and,
* if it is not, returns the formula itself (thus considering it a 1-conjunct conjunction).
*/
public static List<Expression> takeFormulaAsConjunctionAndReturnConjuncts(Expression expression) {
if (And.isConjunction(expression)) {
return expression.getArguments();
}
else {
return Util.list(expression);
}
}
示例11: test
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void test() {
Object expected;
Object arguments[];
arguments = new Object[]{ new Dimension("x", 1, 10), new GetX() };
expected = Util.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
test(expected, arguments);
arguments = new Object[]{ new Averaging(10), new Dimension("x", 1, 10), new GetX() };
expected = Util.list(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
// averages each matrix position independently
test(expected, arguments);
arguments = new Object[]{ new Dimension("x", 1, 2), new Dimension("y", 1, 3), new XPlusY() };
expected = Util.list(Util.list(2, 3, 4), Util.list(3, 4, 5));
test(expected, arguments);
arguments = new Object[]{ new Averaging(10), new Dimension("x", 1, 2), new Dimension("y", 1, 3), new XPlusY() };
expected = Util.list(Util.list(2.0, 3.0, 4.0), Util.list(3.0, 4.0, 5.0));
// averages each matrix position independently
test(expected, arguments);
GetX getX = new GetX();
arguments = new Object[]{ new Dimension("x", 1, 5), new Summation("i", 1, 10), getX };
expected = Util.list(10.0, 20.0, 30.0, 40.0, 50.0);
test(expected, arguments);
Assert.assertEquals(5, getX.counter); // function is computed only once per value of x.
}
示例12: getImmediateSubTreesIncludingRootOneIterator
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Override
public Iterator<SyntaxTree> getImmediateSubTreesIncludingRootOneIterator() {
return new NestedIterator<SyntaxTree>(Util.list(getRootTree(), getImmediateSubTreesIterator()));
}
示例13: initialize
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Override
public void initialize() {
result = Util.list();
}
示例14: DataSeries
import com.sri.ai.util.Util; //导入方法依赖的package包/类
public DataSeries(List<T> data) {
this(Util.<String>list(), data);
}
示例15: test
import com.sri.ai.util.Util; //导入方法依赖的package包/类
@Test
public void test() {
List<String> a;
List<String> b;
LexicographicComparison<String> comparison = new LexicographicComparison<String>();
a = Util.list();
b = Util.list();
assertEquals(0, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list();
b = Util.list("orange");
assertEquals(-1, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("orange");
b = Util.list();
assertEquals(+1, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("orange");
b = Util.list("orange");
assertEquals(0, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("");
b = Util.list("orange");
assertEquals(-1, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("orange");
b = Util.list("");
assertEquals(+1, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("");
b = Util.list("");
assertEquals(0, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("", "apple");
b = Util.list("orange");
assertEquals(-1, Util.signal(comparison.compare(a.iterator(), b.iterator())));
a = Util.list("", "apple", "orange");
b = Util.list("", "apple", "orange");
assertEquals(0, Util.signal(comparison.compare(a.iterator(), b.iterator())));
}