本文整理汇总了Java中com.sri.ai.util.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于com.sri.ai.util包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSetsOfFactorsAndVariables
import com.sri.ai.util.Util; //导入依赖的package包/类
public void updateSetsOfFactorsAndVariables() {
if (this.node.isFactor()) {
FactorNode newFactor = (FactorNode) this.node;
Set<VariableNode> newVariables = new HashSet<VariableNode>();
// Util.println(model);
if (this.model==null) {
this.model=this.parent.model;
}
Util.println(this.model);
newVariables.addAll(this.model.getExploredGraph().getAsOfB(newFactor));// we look at the variables involved in the factor
newVariables.remove(this.parent.node.getValue());// we remove the parent, which is already in the variable set
this.updateSetsOfFactorsAndVariables(newFactor, newVariables);
} else{
this.updateSetsOfVariables();
}
}
示例2: getTypeOfFunctor
import com.sri.ai.util.Util; //导入依赖的package包/类
/**
* Gets a function application and its type <code>T</code>, and returns the inferred type of its functor,
* which is <code>'->'('x'(T1, ..., Tn), T)</code>, where <code>T1,...,Tn</code> are the types.
*/
public static Expression getTypeOfFunctor(Expression functionApplication, Expression functionApplicationType, Registry registry) {
Expression result;
if (functionApplication.getSyntacticFormType().equals(FunctionApplication.SYNTACTIC_FORM_TYPE)) {
List<Expression> argumentTypes = Util.mapIntoArrayList(functionApplication.getArguments(), new GetType(registry));
if (argumentTypes.contains(null)) {
result = null; // unknown type
}
else {
result = FunctionType.make(functionApplicationType, argumentTypes);
}
}
else {
throw new Error("getTypeOfFunctor applicable to function applications only, but invoked on " + functionApplication);
}
return result;
}
示例3: main
import com.sri.ai.util.Util; //导入依赖的package包/类
public static void main(String[] args) {
plot(
Util.list( // precommands
"persist",
//"set term postscript color",
//"set output 'test.ps'",
"set xlabel 'Time'",
"set ylabel 'Intensity'"
),
Util.getIteratorNullaryFunction(Util.list(10,20,30,40)), // xSeries
Util.list( // list of ySeries
new DataSeries<Integer>(
Util.list("title 'random sequence 1'", "w linespoints"),
Util.list(1,2,4,3)
),
new DataSeries<Integer>(
Util.list("title 'random sequence 2'", "w linespoints"),
Util.list(5,4,3,2)
)
)
);
}
示例4: translate
import com.sri.ai.util.Util; //导入依赖的package包/类
@Override
protected void translate(String inputIdentifier, Reader[] inputModelReaders, PrintWriter[] translatedOutputs) throws Exception {
//
// 1. Get the HOGM Model Definition and Parse It
String hogmv1Model = Util.readAll(inputModelReaders[0]);
HOGMParserWrapper parser = new HOGMParserWrapper();
ParsedHOGModel parsedModel = parser.parseModel(hogmv1Model);
FactorsAndTypes factorsAndTypes = new ExpressionFactorsAndTypes(parsedModel);
// Each additional input is treated as an evidence expression
List<Expression> evidence = new ArrayList<>();
if (inputModelReaders.length > 1) {
for (int i = 1; i < inputModelReaders.length; i++) {
evidence.add(Expressions.parse(Util.readAll(inputModelReaders[i])));
}
}
translate(inputIdentifier, factorsAndTypes, evidence, translatedOutputs);
}
示例5: testCastOrThrowError
import com.sri.ai.util.Util; //导入依赖的package包/类
@Test
public void testCastOrThrowError() {
Integer i = 10;
Object iObject = i;
Integer j = Util.castOrThrowError(Integer.class, iObject, "Got %s, which should have been an instance of %s but is instead an instance of %s");
Assert.assertEquals(i, j);
try {
Util.castOrThrowError(String.class, iObject, "Got %s, which should have been an instance of %s but is instead an instance of %s");
} catch (Error e) {
Assert.assertEquals("Got 10, which should have been an instance of String but is instead an instance of Integer", e.getMessage());
return;
}
Assert.fail("Util.castOrThrowError should have throw error when attempting to cast Integer into String but did not.");
}
示例6: applySimplifier
import com.sri.ai.util.Util; //导入依赖的package包/类
@Override
public Expression applySimplifier(Expression expression, Context context) {
// We need to override this method because INFINITY and MINUS_INFINITY
// are not Java constants.
Expression result;
if ( ! isExtensional(expression)) {
result = expression;
}
else {
// takes care of infinity arguments before deferring to super method
if (expression.getArguments().contains(INFINITY)) {
result = INFINITY;
}
else {
// remove MINUS_INFINITY if any and defer to super method
List<Expression> argumentsWithoutMinusInfinity =
Util.removeNonDestructively(expression.getArguments(), MINUS_INFINITY);
Expression expressionWithoutMinusInfinity =
expression.getArguments() == argumentsWithoutMinusInfinity?
expression : Expressions.apply(expression.getFunctor(), argumentsWithoutMinusInfinity);
result = super.apply(expressionWithoutMinusInfinity, context);
}
}
return result;
}
示例7: 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;
}
示例8: 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;
}
示例9: refineOrNull
import com.sri.ai.util.Util; //导入依赖的package包/类
@Override
protected T refineOrNull() {
T result = null;
if ( ! firstComputationDone) { // first computed value
result = computeFunction();
firstComputationDone = true;
}
else { // incremental computation
boolean hasMoreRefinedValue;
if ( ! (hasMoreRefinedValue = Util.thereExists(arguments, new HasMoreRefinedValueSinceLastTimeAtNoCost()))) {
hasMoreRefinedValue = tryToRefineSomeArgumentAccordingToRanking();
}
if (hasMoreRefinedValue) {
result = computeFunction();
}
}
return result;
}
示例10: 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));
}
示例11: 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;
}
示例12: put
import com.sri.ai.util.Util; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean put(Iterator path) {
boolean result = false;
if (path.hasNext()) {
Object nextKey = path.next();
result = result || !containsKey(nextKey);
HashMapRandomAccessTree subTree = (HashMapRandomAccessTree) Util
.getValuePossiblyCreatingIt(this, nextKey,
HashMapRandomAccessTree.class);
boolean subResult = subTree.put(path);
return result || subResult;
}
else {
valid = true; // indicates that path ending here is valid.
}
return result;
}
示例13: UnificationStepSolver
import com.sri.ai.util.Util; //导入依赖的package包/类
public UnificationStepSolver(Expression expression1, Expression expression2) {
if (expression1.equals(expression2)) { // Check for simple literal equality up front.
precomputedResult = new StepSolver.Solution<Boolean>(Boolean.TRUE);
}
else if (Expressions.isFunctionApplicationWithArguments(expression1) &&
Expressions.isFunctionApplicationWithArguments(expression2) &&
expression1.numberOfArguments() == expression2.numberOfArguments() &&
expression1.getFunctor().equals(expression2.getFunctor())) {
unificationEqualitiesToTest = Util.zipWith(
(matchingArgFrom1, matchingArgFrom2) -> Equality.make(matchingArgFrom1, matchingArgFrom2),
expression1.getArguments(), expression2.getArguments());
}
else if (Expressions.isSymbol(expression1) && Expressions.isSymbol(expression2)) {
unificationEqualitiesToTest = Arrays.asList(Equality.make(expression1, expression2));
}
else {
precomputedResult = new StepSolver.Solution<Boolean>(Boolean.FALSE);
}
if (unificationEqualitiesToTest != null) {
unknownSolutionIndexesForUnificationEqualities =
IntStream.range(0, unificationEqualitiesToTest.size())
.boxed()
.collect(Collectors.toList());
}
}
示例14: createTuplesOfVarsForTupleTypes
import com.sri.ai.util.Util; //导入依赖的package包/类
private static Map<Expression, Expression> createTuplesOfVarsForTupleTypes(QuantifiedExpression quantifiedExpression, List<Map.Entry<Expression, Expression>> indexesOfTupleType) {
Map<Expression, Expression> result = new HashMap<>();
Set<Expression> allSubExpressions = Util.addAllToSet(new SubExpressionsDepthFirstIterator(quantifiedExpression));
for (Map.Entry<Expression, Expression> entry : indexesOfTupleType) {
List<Expression> tupleVars = new ArrayList<>();
for (int i = 1; i <= entry.getValue().numberOfArguments(); i++) {
Expression proposedVar = Expressions.makeSymbol(entry.getKey().toString()+"_"+i);
Expression actualVar = Expressions.primedUntilUnique(proposedVar, expr -> !allSubExpressions.contains(expr));
tupleVars.add(actualVar);
}
result.put(entry.getKey(), Expressions.makeTuple(tupleVars));
}
return result;
}
示例15: pairsOfEquals
import com.sri.ai.util.Util; //导入依赖的package包/类
protected ArrayList<PairOf<Expression>> pairsOfEquals() {
if (pairsOfEquals == null) {
ArrayList<Expression> equalities = Util.collectToArrayList(getConstraint().getPositiveNormalizedAtoms(), e -> e.hasFunctor(EQUALITY));
PairOfElementsInListIterator<Expression> pairsOfEqualitiesIterator =
new PairOfElementsInListIterator<>(equalities);
// Function<PairOf<Expression>, PairOf<Expression>> makePairOfSecondArguments = p -> makePairOf(p.first.get(1), p.second.get(1));
// above lambda somehow not working at Ciaran's environment, replacing with seemingly identical anonymous class object below
Function<PairOf<Expression>, PairOf<Expression>> makePairOfSecondArguments = new Function<PairOf<Expression>, PairOf<Expression>>() {
@Override
public PairOf<Expression> apply(PairOf<Expression> p) {
return makePairOf(p.first.get(1), p.second.get(1));
}
};
Iterator<PairOf<Expression>> pairsOfEqualsIterator = functionIterator(pairsOfEqualitiesIterator, makePairOfSecondArguments);
pairsOfEquals = arrayListFrom(pairsOfEqualsIterator);
}
return pairsOfEquals;
}
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:23,代码来源:AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver.java