当前位置: 首页>>代码示例>>Java>>正文


Java Util.collect方法代码示例

本文整理汇总了Java中com.sri.ai.util.Util.collect方法的典型用法代码示例。如果您正苦于以下问题:Java Util.collect方法的具体用法?Java Util.collect怎么用?Java Util.collect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sri.ai.util.Util的用法示例。


在下文中一共展示了Util.collect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: simplify

import com.sri.ai.util.Util; //导入方法依赖的package包/类
public static Expression simplify(Expression disjunction) {
	Expression result = disjunction;
	if (disjunction.getArguments().contains(Expressions.TRUE)) {
		result = Expressions.TRUE;
	}
	else {
		LinkedHashSet<Expression> distinctArgumentsNotEqualToFalse = new LinkedHashSet<Expression>();
		Util.collect(disjunction.getArguments(), distinctArgumentsNotEqualToFalse, e -> ! e.equals(Expressions.FALSE));
		if (distinctArgumentsNotEqualToFalse.size() != disjunction.getArguments().size()) {
			if (distinctArgumentsNotEqualToFalse.size() == 0) {
				result = Expressions.FALSE;
			}
			else if (distinctArgumentsNotEqualToFalse.size() == 1) {
				result = Util.getFirst(distinctArgumentsNotEqualToFalse);
			}
			else if (distinctArgumentsNotEqualToFalse.size() != disjunction.numberOfArguments()) {
				result = Expressions.apply(FunctorConstants.OR, distinctArgumentsNotEqualToFalse);
			}
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:Or.java

示例2: simplify

import com.sri.ai.util.Util; //导入方法依赖的package包/类
public static Expression simplify(Expression conjunction) {
	Expression result = conjunction;
	if (conjunction.getArguments().contains(Expressions.FALSE)) {
		result = Expressions.FALSE;
	}
	else {
		LinkedHashSet<Expression> distinctArgumentsNotEqualToTrue = new LinkedHashSet<Expression>();
		Util.collect(conjunction.getArguments(), distinctArgumentsNotEqualToTrue, e -> ! e.equals(Expressions.TRUE));
		if (distinctArgumentsNotEqualToTrue.size() != conjunction.getArguments().size()) {
			if (distinctArgumentsNotEqualToTrue.size() == 0) {
				result = Expressions.TRUE;
			}
			else if (distinctArgumentsNotEqualToTrue.size() == 1) {
				result = Util.getFirst(distinctArgumentsNotEqualToTrue);
			}
			else if (distinctArgumentsNotEqualToTrue.size() != conjunction.numberOfArguments()) {
				result = Expressions.apply(FunctorConstants.AND, distinctArgumentsNotEqualToTrue);
			}
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:And.java

示例3: simplify

import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
 * Returns FALSE if given disequality has equal arguments, TRUE if they contain distinct constants,
 * and the disequality itself otherwise.
 */
public static Expression simplify(Expression disequality, Context context) {
	Expression result;
	if (disequality.get(0).equals(disequality.get(1))) {
		result = Expressions.FALSE;
	}
	else {
		Set<Expression> constants = new LinkedHashSet<Expression>();
		Set<Expression> nonConstants = new LinkedHashSet<Expression>();
		Util.collect(disequality.getArguments(), constants, context.getIsUniquelyNamedConstantPredicate(), nonConstants);
		if (constants.size() > 1) {
			result = Expressions.TRUE;
		}
		else if (constants.size() == 1 && constants.contains(Expressions.FALSE)) {
			result = And.make(new ArrayList<Expression>(nonConstants));
		}
		else if (constants.size() == 1 && constants.contains(Expressions.TRUE)) {
			ArrayList<Expression> negatedNonConstants = Util.mapIntoArrayList(nonConstants, e -> Not.make(e));
			result = And.make(new ArrayList<Expression>(negatedNonConstants));
		}
		else {
			result = disequality;
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:30,代码来源:Disequality.java

示例4: simplify

import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
 * Returns TRUE if given equality has all-equal arguments, FALSE if they contain distinct constants,
 * and the equality itself otherwise.
 * Note that this is much faster than eliminating duplicates as well, which requires constructing another equality.
 */
public static Expression simplify(Expression equality, Context context) {
	Expression result;
	if (Util.allEqual(equality.getArguments())) {
		result = Expressions.TRUE;
	}
	else {
		Set<Expression> constants = new LinkedHashSet<Expression>();
		Set<Expression> nonConstants = new LinkedHashSet<Expression>();
		Util.collect(equality.getArguments(), constants, context.getIsUniquelyNamedConstantPredicate(), nonConstants);
		if (constants.size() > 1) {
			result = Expressions.FALSE;
		}
		else if (constants.size() == 1 && constants.contains(Expressions.TRUE)) {
			result = And.make(new ArrayList<Expression>(nonConstants));
		}
		else if (constants.size() == 1 && constants.contains(Expressions.FALSE)) {
			ArrayList<Expression> negatedNonConstants = Util.mapIntoArrayList(nonConstants, e -> Not.make(e));
			result = And.make(new ArrayList<Expression>(negatedNonConstants));
		}
		else {
			result = equality;
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:31,代码来源:Equality.java

示例5: getSubExpressionsSatisfying

import com.sri.ai.util.Util; //导入方法依赖的package包/类
/**
 * A static method returning selected sub-expressions
 * in a given expressions, according to a given predicate.
 */
public static LinkedHashSet<Expression> getSubExpressionsSatisfying(Expression expression, Predicate<Expression> predicate) {
	LinkedHashSet<Expression> results = new LinkedHashSet<Expression>();
	Util.collect(new SubExpressionsDepthFirstIterator(expression), results, predicate);
	return results;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:10,代码来源:Expressions.java


注:本文中的com.sri.ai.util.Util.collect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。