當前位置: 首頁>>代碼示例>>Java>>正文


Java ITuple類代碼示例

本文整理匯總了Java中org.deri.iris.api.basics.ITuple的典型用法代碼示例。如果您正苦於以下問題:Java ITuple類的具體用法?Java ITuple怎麽用?Java ITuple使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ITuple類屬於org.deri.iris.api.basics包,在下文中一共展示了ITuple類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toString

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
public static String toString(IRdbRelation relation) {
	StringBuilder builder = new StringBuilder();

	builder.append("[");

	CloseableIterator<ITuple> iterator = relation.iterator();

	int i = 0;
	while (iterator.hasNext()) {
		if (i++ > 0) {
			builder.append(", ");
		}

		ITuple tuple = iterator.next();

		if (tuple != null) {
			builder.append(tuple.toString());
		}
	}

	iterator.close();

	builder.append("]");

	return builder.toString();
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:27,代碼來源:RdbUtils.java

示例2: testBuiltin

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
public void testBuiltin() throws EvaluationException {
	ITerm date1 = Factory.CONCRETE.createDate(2010, 4, 26);
	ITerm date2 = Factory.CONCRETE.createDate(2010, 4, 26);
	ITerm date3 = Factory.CONCRETE.createDate(2010, 5, 26);
	ITerm date4 = Factory.CONCRETE.createDate(1997, 3, 12);

	DateGreaterEqualBuiltin builtin = new DateGreaterEqualBuiltin(X, Y);

	ITuple args = Factory.BASIC.createTuple(date1, date2);
	ITuple actual = builtin.evaluate(args);
	// (date1 = date2) -> null
	assertEquals(EMPTY_TUPLE, actual);

	builtin = new DateGreaterEqualBuiltin(X, Y);
	args = Factory.BASIC.createTuple(date3, date4);
	actual = builtin.evaluate(args);
	// (date3 > date4) -> iTuple()
	assertEquals(EMPTY_TUPLE, actual);

	builtin = new DateGreaterEqualBuiltin(X, Y);
	args = Factory.BASIC.createTuple(date4, date3);
	actual = builtin.evaluate(args);
	// (date4 < date3) -> null
	assertEquals(null, actual);
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:26,代碼來源:DateGreaterEqualBuiltinTest.java

示例3: addToEvaluation

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Add a tuple to this nodes evaluation
 * 
 * @param tuple
 *            the <code>ITuple</code> to add
 */
private void addToEvaluation(ITuple tuple) {
	IRelation evaluation = this.getEvaluation();
	evaluation.add(tuple);
	this.setEvaluation(evaluation);

	// If this node is a answer node, add the evaluation to the memo
	// table as well
	if (this.isAnswerNode()) {
		Map<IVariable, ITerm> memoTupleVarMap = TopDownHelper
				.createVariableMapFromTupleAndQuery(this.getQuery(),
						tuple);
		ITuple memoTuple = TopDownHelper.resolveTuple(this
				.getSelectedLiteral(), memoTupleVarMap);
		mMemoTable.add(this.getSelectedLiteral().getAtom(), memoTuple);
	}
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:23,代碼來源:OLDTEvaluator.java

示例4: createVariableMapFromTupleAndQuery

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
	 * Given a query and a tuple, create
	 * a variable map with the corresponding variable
	 * mappings for each variable in the query.
	 * 
	 * @param query the query
	 * @param branchTuple the tuple
	 * 
	 * @return a new variable map containing mappings for all 
	 * unique variables in <code>query</code>   
	 */
	public static Map<IVariable, ITerm> createVariableMapFromTupleAndQuery(IQuery query, ITuple branchTuple) {
		
		Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
		
//		assert (getVariables(query).size() == branchTuple.size()) : "Number of variables in query does not match tuple size.";
		if (getVariables(query).size() != branchTuple.size()) {
			return variableMap;
		}
		
		int i = 0;
		for (IVariable var : getVariables(query)) {
			if (branchTuple.isEmpty()) {
				variableMap.put(var, var);
			} else {
				variableMap.put(var, branchTuple.get(i++));
			}
		}
		
		return variableMap;
	}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:32,代碼來源:TopDownHelper.java

示例5: createTupleFromQueryAndVariableMap

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Given a query and a variable map, create  
 * a tuple with the corresponding terms for each variable
 * in the query.
 * 
 * @param query the query
 * @param variableMap a map containing the variable mappings
 * 
 * @return a new tuple
 */
@Deprecated
public static ITuple createTupleFromQueryAndVariableMap(IQuery query, Map<IVariable, ITerm> variableMap) {
	
	assert query.getVariables().size() == variableMap.size() : "All variables must have a mapping";
	
	List<ITerm> terms = new LinkedList<ITerm>();
	for (IVariable var : query.getVariables() ) {
		// For every Variable of the original query, get the mappings
		ITerm term = variableMap.get(var);
		terms.add(term);
	}
	
	ITuple tuple = Factory.BASIC.createTuple(terms);
	return tuple;
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:26,代碼來源:TopDownHelper.java

示例6: RdbView

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
public RdbView(Connection connection, IRdbRelation relation,
		ITuple viewCriteria, String suffix, boolean isPositive)
		throws SQLException {
	super(connection);

	this.relation = relation;
	this.viewCriteria = viewCriteria;
	this.isPositive = isPositive;
	this.suffix = suffix;

	this.universe = RdbUniverseRelation.getInstance(connection);

	createView();

	viewRelation = new SimpleRdbRelation(connection, getTableName(),
			getArity());
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:18,代碼來源:RdbView.java

示例7: testBuiltin

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
public void testBuiltin() throws EvaluationException {
	ITerm date1 = Factory.CONCRETE.createDate(2010, 4, 26);
	ITerm date2 = Factory.CONCRETE.createDate(2010, 4, 26);
	ITerm date3 = Factory.CONCRETE.createDate(2010, 5, 11);
	ITerm date4 = Factory.CONCRETE.createDate(1997, 3, 12);

	DateLessEqualBuiltin builtin = new DateLessEqualBuiltin(X, Y);
	ITuple args = Factory.BASIC.createTuple(date1, date2);
	ITuple actual = builtin.evaluate(args);
	// (date1 = date2) -> EMPTY_TUPLE
	assertEquals(EMPTY_TUPLE, actual);

	builtin = new DateLessEqualBuiltin(X, Y);
	args = Factory.BASIC.createTuple(date3, date4);
	actual = builtin.evaluate(args);
	// (date3 > date4) -> iTuple()
	assertEquals(null, actual);

	builtin = new DateLessEqualBuiltin(X, Y);
	args = Factory.BASIC.createTuple(date4, date3);
	actual = builtin.evaluate(args);
	// (date4 < date3) -> EMPTY_TUPLE
	assertEquals(EMPTY_TUPLE, actual);
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:25,代碼來源:DateLessEqualBuiltinTest.java

示例8: matchTuple

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Match a tuple to view criteria.
 * If a match occurs, return a tuple with values for each distinct variable in the view criteria.
 * @param viewCriteria The tuple from a sub-goal instance.
 * @param relation The tuple from an EDB relation.
 * @param equivalentTerms The equivalent terms.
 * @return The tuple of values for the view's variables or null if a match did not occur.
 */
public static ITuple matchTuple( ITuple viewCriteria, ITuple relation, IEquivalentTerms equivalentTerms )
{
	Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
	List<ITerm> terms = new ArrayList<ITerm>();
	
	for( int i = 0; i < viewCriteria.size(); ++i )
	{
		ITerm bodyTerm = viewCriteria.get( i );
		ITerm relationTerm = relation.get( i );
		
		if( ! matchTermOfTuple( bodyTerm, relationTerm, equivalentTerms, variableMap, terms ) )
			return null;
	}

	return Factory.BASIC.createTuple( terms );
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:25,代碼來源:TermMatchingAndSubstitution.java

示例9: next

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
@Override
public ITuple next() {
	if (isClosed) {
		throw new NoSuchElementException("Iterator has already been closed");
	}

	if (next == null) {
		prepareNext();
	}

	ITuple result = next;
	next = null;

	if (!hasNext()) {
		close();
	}

	if (result == null) {
		throw new NoSuchElementException();
	}

	return result;
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:24,代碼來源:TupleIterator.java

示例10: createFacts

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
private IFacts createFacts() {
	IFacts facts = new Facts(configuration.relationFactory);

	// Create facts.
	for (int i = 0; i < numberOfRelations; i++) {
		IPredicate predicate = relationPredicates.get(i);

		IRelation relation = facts.get(predicate);

		for (int k = 0; k < numberOfFactsPerRelation; k++) {
			List<ITerm> terms = new ArrayList<ITerm>(predicate.getArity());

			for (int j = 0; j < predicate.getArity(); j++) {
				int index = random.nextInt(maximalConstants) + 1;
				terms.add(TERM.createString(constantPrefix + index));
			}

			ITuple tuple = BASIC.createTuple(terms);
			relation.add(tuple);
		}
	}

	return facts;
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:25,代碼來源:RandomProgramBuilder.java

示例11: setUp

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
protected void setUp() throws Exception
{
	mRelation = new SimpleRelationFactory().createRelation();
	
	// f(1,2,g(2,3))
	ITuple t1 = Helper.createTuple( 1, 2, Helper.createConstructedTerm( "g", 2, 3 ) );
	mRelation.add( t1 );

	// f(1,2,g(2,1))
	ITuple t2 = Helper.createTuple( 1, 2, Helper.createConstructedTerm( "g", 2, 1 ) );
	mRelation.add( t2 );
	
	// f(X,Y,g(Y,X))
	ITuple viewCriteria = Helper.createTuple( "X", "Y", Helper.createConstructedTerm( "g", "Y", "X" ) );
	
	mView = new View( mRelation, viewCriteria, new SimpleRelationFactory() );
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:18,代碼來源:ViewTest.java

示例12: isSimpleView

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Determine of the view is simple.
 * The view is simple if no filtering occurs.
 * This only happens if every term of the view criteria is a plain variable and unique, e.g.
 * p( ?X, ?Y, ?Z ) is simple, but p(?X, ?X ) is not.
 * @param viewCriteria The vew criteria.
 * @return true, if the view is simple.
 */
public static boolean isSimpleView( ITuple viewCriteria )
{
	Set<IVariable> vars = new HashSet<IVariable>();
	
	for( ITerm term : viewCriteria )
	{
		if( term instanceof IVariable )
		{
			IVariable variable = (IVariable) term;

			if( ! vars.add( variable ) )
				return false;
		}
		else
			return false;
	}
	
	return true;
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:28,代碼來源:View.java

示例13: FirstSubgoal

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Constructor.
 * @param predicate The predicate for this literal.
 * @param relation The relation for this literal.
 * @param viewCriteria The tuple from the sub-goal in the rule.
 * @param equivalentTerms The equivalent terms.
 */
public FirstSubgoal( IPredicate predicate, IRelation relation, ITuple viewCriteria, 
		IEquivalentTerms equivalentTerms, Configuration configuration )
{
	assert predicate != null;
	assert relation != null;
	assert viewCriteria != null;
	assert configuration != null;
	
	mConfiguration = configuration;
	
	mView = new View( relation, viewCriteria, equivalentTerms, mConfiguration.relationFactory );

	mPredicate = predicate;
	mViewCriteria = viewCriteria;
	mOutputVariables = mView.variables();
	mEquivalentTerms = equivalentTerms;
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:25,代碼來源:FirstSubgoal.java

示例14: testBuiltin

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
public void testBuiltin() throws EvaluationException {
	
	ITerm term1 = Factory.CONCRETE.createXMLLiteral("XML Literal");
	ITerm term2 = Factory.CONCRETE.createXMLLiteral("XML Literal");
	ITerm term3 = Factory.CONCRETE.createXMLLiteral("blabla");
	
	ITuple arguments = Factory.BASIC.createTuple(X, Y);

	XMLLiteralEqualBuiltin builtin = new XMLLiteralEqualBuiltin(term1 ,term1);
	ITuple actualTuple = builtin.evaluate(arguments);
	assertEquals(EMPTY_TUPLE, actualTuple);
	

	builtin = new XMLLiteralEqualBuiltin(term1, term2);
	actualTuple = builtin.evaluate(arguments);
	assertEquals(EMPTY_TUPLE, actualTuple);

	builtin = new XMLLiteralEqualBuiltin(term1, term3);
	actualTuple = builtin.evaluate(arguments);
	assertEquals(null, actualTuple);
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:22,代碼來源:XMLLiteralEqualBuiltinTest.java

示例15: makeResultTuple

import org.deri.iris.api.basics.ITuple; //導入依賴的package包/類
/**
 * Transform the input tuple (from previous rule elements) and the tuple produced by the
 * built-in atom in to a tuple to pass on to the next rule element.
 * @param inputTuple The tuple produced b previous literals.
 * @param builtinOutputTuple The output of the built-in atom.
 * @return The tuple to pass on to the next rule element.
 */
protected ITuple makeResultTuple( ITuple inputTuple, ITuple builtinOutputTuple )
{
	assert builtinOutputTuple != null;
	
	if( builtinOutputTuple.size() == 0 )
		return inputTuple == null ? Factory.BASIC.createTuple() : inputTuple;
	
	ITerm[] terms = new ITerm[ ( inputTuple == null ? 0 : inputTuple.size() ) + mIndicesFromBuiltInOutputTupleToCopyToOutputRelation.length ];
	
	int index = 0;
	if( inputTuple != null )
		for( ITerm term : inputTuple )
			terms[ index++ ] = term;
	
	for( int i : mIndicesFromBuiltInOutputTupleToCopyToOutputRelation )
		terms[ index++ ] = builtinOutputTuple.get( i );

	return Factory.BASIC.createTuple( terms );
}
 
開發者ID:NICTA,項目名稱:iris-reasoner,代碼行數:27,代碼來源:Builtin.java


注:本文中的org.deri.iris.api.basics.ITuple類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。