• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java IVariable类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.deri.iris.api.terms.IVariable的典型用法代码示例。如果您正苦于以下问题:Java IVariable类的具体用法?Java IVariable怎么用?Java IVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

IVariable类属于org.deri.iris.api.terms包,在下文中一共展示了IVariable类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testBounds0

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Tests whether the bound variables are correct.
 */
public void testBounds0() throws Exception {
	final String prog = "sg(?X, ?Y) :- up(?X, ?Z1), sg(?Z1, ?Z2), down(?X, ?Z1, ?Z2, ?Z3), again(?X, ?Z1, ?Z3, ?Y).\n"
					 + "?- sg('john', ?X).";
	final LeftToRightSip sip = parseProgram(prog);

	final IVariable X = TERM.createVariable("X");
	final IVariable Z1 = TERM.createVariable("Z1");
	final IVariable Z2 = TERM.createVariable("Z2");
	final IVariable Z3 = TERM.createVariable("Z3");

	final Set<IVariable> bound_up = new HashSet<IVariable>(Arrays.asList(new IVariable[]{X}));
	final Set<IVariable> bound_sg = new HashSet<IVariable>(Arrays.asList(new IVariable[]{Z1}));
	final Set<IVariable> bound_down = new HashSet<IVariable>(Arrays.asList(new IVariable[]{X, Z1, Z2}));
	final Set<IVariable> bound_again = new HashSet<IVariable>(Arrays.asList(new IVariable[]{X, Z1, Z3}));

	final ILiteral up = createLiteral("up", "X", "Z1");
	final ILiteral sg = createLiteral("sg", "Z1", "Z2");
	final ILiteral down = createLiteral("down", "X", "Z1", "Z2", "Z3");
	final ILiteral again = createLiteral("again", "X", "Z1", "Z3", "Y");

	assertEquals("Bounds of up wrong", bound_up, sip.getBoundVariables(up));
	assertEquals("Bounds of sg wrong", bound_sg, sip.getBoundVariables(sg));
	assertEquals("Bounds of down wrong", bound_down, sip.getBoundVariables(down));
	assertEquals("Bounds of again wrong", bound_again, sip.getBoundVariables(again));
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:29,
代码来源:LeftToRightSipTest.java

示例2: matchTuple

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的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

示例3: testVariables

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testVariables() {
	Set<IVariable> variables = new HashSet<IVariable>();
	IVariable x = TERM.createVariable("X");
	IVariable y = TERM.createVariable("Y");
	
	variables.add(x);
	variables.add(y);
	
	IConstructedTerm c1 = TERM.createConstruct("c1", y);
	IConstructedTerm c2 = TERM.createConstruct("c2", c1, x);
	List<ITerm> terms = new ArrayList<ITerm>();
	terms.addAll(REFERENCE);
	terms.add(c2);
	
	assertEquals(variables, BASIC.createTuple(terms).getVariables());
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:17,
代码来源:TupleTest.java

示例4: testNoInput

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testNoInput() throws Exception
{
	Configuration configuration = new Configuration();
	ITuple builtinTuple = Helper.createTuple( 3, 4, "X" );
	IBuiltinAtom builtinPredicate = new AddBuiltin( builtinTuple.toArray( new ITerm[0]) );
	
	Builtin builtin = new Builtin( new ArrayList<IVariable>(), builtinPredicate, true, 
			new IgnoreTermEquivalence(), configuration );
	
	IRelation output = builtin.process( mRelationWithOneZeroLengthTuple );
	
	assertEquals( Helper.createTerm( "X" ), builtin.getOutputVariables().get( 0 ) );

	assertEquals( 1, output.size() );
	assertEquals( Helper.createTerm( 7 ), output.get( 0 ).get( 0 ) );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:17,
代码来源:BuiltinTest.java

示例5: testUnifyGroundedTermAndVariable

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testUnifyGroundedTermAndVariable()
{
	ITerm x = Factory.TERM.createString( "x" );
	IVariable Y = Factory.TERM.createVariable( "Y" );
	
	Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
	
	assertTrue( TermMatchingAndSubstitution.unify( x, Y, variableMap ) );
	assertEquals( 1, variableMap.size() );
	assertTrue( variableMap.get( Y ).equals( x ) );

	// And the other way round
	variableMap = new HashMap<IVariable, ITerm>();
	
	assertTrue( TermMatchingAndSubstitution.unify( Y, x, variableMap ) );
	assertEquals( 1, variableMap.size() );
	assertTrue( variableMap.get( Y ).equals( x ) );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:19,
代码来源:TermMatchingAndSubstitutionTest.java

示例6: updateMemoTable

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Update the corresponding entry of the memo table which is related to
 * the selected literal.
 */
private void updateMemoTable() {
	if (this.getSelectedLiteral() == null)
		return;

	IAtom atom = this.getSelectedLiteral().getAtom();
	if (mMemoTable.get(atom) != null) {
		IRelation eval = this.getEvaluation();

		for (int i = 0; i < eval.size(); i++) {
			ITuple tuple = eval.get(i);
			Map<IVariable, ITerm> nodeVarMap = TopDownHelper
					.createVariableMapFromTupleAndQuery(
							this.getQuery(), tuple);
			ITuple nodeMemoTuple = TopDownHelper.resolveTuple(this
					.getSelectedLiteral(), nodeVarMap);

			if (!mMemoTable.get(atom).contains(nodeMemoTuple)) {
				mMemoTable.add(atom, nodeMemoTuple);
			}
		}
	}
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:27,
代码来源:OLDTEvaluator.java

示例7: testBounds1

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Tests whether the bound variables are correct.
 */
public void testBounds1() throws Exception {
	final String prog = "rsg(?X, ?Y) :- up(?X, ?X1), rsg(?Y1, ?X1), down(?Y1, ?Y).\n"
					  + "?- rsg('a', ?X).";
	final LeftToRightSip sip = parseProgram(prog);

	final IVariable X = TERM.createVariable("X");
	final IVariable X1 = TERM.createVariable("X1");
	final IVariable Y1 = TERM.createVariable("Y1");

	final Set<IVariable> bound_up = new HashSet<IVariable>(Arrays.asList(new IVariable[]{X}));
	final Set<IVariable> bound_rsg0 = new HashSet<IVariable>(Arrays.asList(new IVariable[]{X1}));
	final Set<IVariable> bound_down = new HashSet<IVariable>(Arrays.asList(new IVariable[]{Y1}));

	final ILiteral up = createLiteral("up", "X", "X1");
	final ILiteral rsg0 = createLiteral("rsg", "Y1", "X1");
	final ILiteral down = createLiteral("down", "Y1", "Y");

	assertEquals("Bounds of up wrong", bound_up, sip.getBoundVariables(up));
	assertEquals("Bounds of rsg0 wrong", bound_rsg0, sip.getBoundVariables(rsg0));
	assertEquals("Bounds of down wrong", bound_down, sip.getBoundVariables(down));
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:25,
代码来源:LeftToRightSipTest.java

示例8: getVariableMapForVariableRenaming

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Creates a variable map that will replace variable ?X with ?X1 if
 * the variable occurs in both tuples.
 *  
 * @param rule a rule
 * @param query a query
 * 
 * @return a variable map that maps the old variable names to the new ones
 * @throws RuleUnsafeException thrown if the rule contains unbound variables
 */
public static Map<IVariable, ITerm> getVariableMapForVariableRenaming(IRule rule, IQuery query) throws RuleUnsafeException {
	Map<IVariable, ITerm> variableMapForOccurCheck = new HashMap<IVariable, ITerm>();
	
	Set<IVariable> ruleVariables = getBodyVariables(rule);
				   ruleVariables.addAll(getHeadVariables(rule));
	List<IVariable> queryVariables = getVariables(query);		
	
	for ( IVariable var : queryVariables ) {
		
		if ( !ruleVariables.contains(var) )
			continue; 
		
		int i = 0;
		IVariable varRename = var;
		while (ruleVariables.contains( varRename )) {
			varRename = Factory.TERM.createVariable(var.getValue().toString() + ++i);
		}
		
		if (varRename != var)
			variableMapForOccurCheck.put(var, varRename);
	}
	
	return variableMapForOccurCheck;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:35,
代码来源:TopDownHelper.java

示例9: testForEdges0

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Tests whether the sip contains all expected edges.
 */
public void testForEdges0() throws Exception {
	final String prog = "sg(?X, ?Y) :- up(?X, ?Z1), sg(?Z1, ?Z2), flat(?Z2, ?Z3), sg(?Z3, ?Z4), down(?Z4, ?Y).\n"
					 + "?- sg('john', ?X).";
	final LeftToRightSip sip = parseProgram(prog);

	final IVariable X = TERM.createVariable("X");
	final IVariable Z1 = TERM.createVariable("Z1");
	final IVariable Z2 = TERM.createVariable("Z2");
	final IVariable Z3 = TERM.createVariable("Z3");
	final IVariable Z4 = TERM.createVariable("Z4");

	final Set<LabeledEdge<ILiteral, Set<IVariable>>> edges = new HashSet<LabeledEdge<ILiteral, Set<IVariable>>>();
	edges.add(createEdge(createLiteral("sg", "X", "Y"), createLiteral("up", "X", "Z1"), X));
	edges.add(createEdge(createLiteral("up", "X", "Z1"), createLiteral("sg", "Z1", "Z2"), Z1));
	edges.add(createEdge(createLiteral("sg", "Z1", "Z2"), createLiteral("flat", "Z2", "Z3"), Z2));
	edges.add(createEdge(createLiteral("flat", "Z2", "Z3"), createLiteral("sg", "Z3", "Z4"), Z3));
	edges.add(createEdge(createLiteral("sg", "Z3", "Z4"), createLiteral("down", "Z4", "Y"), Z4));

	assertEquals("The edge set does not match.", edges, sip.getEdges());
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:24,
代码来源:LeftToRightSipTest.java

示例10: createVariableMapFromTupleAndQuery

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的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

示例11: freezeQuery

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
private void freezeQuery(IQuery query, Map<IPredicate, IRelation> facts) {
	for (ILiteral literal : query.getLiterals()) {
		List<ITerm> terms = new Vector<ITerm>();
		// build 'frozen' Atom by actually substituting the variables
		for (ITerm term : literal.getAtom().getTuple()) {
			if (term instanceof IVariable)
				terms.add(Factory.TERM.createString( "FROZEN_VARIABLE_"+ ((IVariable) term).getValue() ) );
			else
				terms.add(term);
		}
		IAtom atom = Factory.BASIC.createAtom(literal.getAtom().getPredicate(), 
				Factory.BASIC.createTuple(terms));
		IRelation relation = facts.get( atom.getPredicate() );
		
		if( relation == null )
		{
			relation = new SimpleRelationFactory().createRelation();
			facts.put( atom.getPredicate(), relation );
		}
		
		relation.add( atom.getTuple());
	}
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:24,
代码来源:QueryContainment.java

示例12: LeftToRightSip

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Constructs a sip out of a rule.
 * @param rule the rule for which to create the sip
 * @throws IllegalArgumentException if the rule is <code>null</code>
 */
public LeftToRightSip(final IRule rule) {
	if (rule == null) {
		throw new IllegalArgumentException("The rule must not be null");
	}

	final Set<IVariable> known = new HashSet<IVariable>();
	for (final ILiteral literal : rule.getHead()) {
		if (literal.getAtom().getPredicate() instanceof AdornedPredicate) {
			final Adornment[] adornments = ((AdornedPredicate) literal.getAtom().getPredicate()).getAdornment();
			int i = 0;
			for (final ITerm term : literal.getAtom().getTuple()) {
				if (adornments[i++] == Adornment.BOUND) {
					known.addAll(getVariables(term));
				}
			}
		}
	}

	constructSip(rule, known);
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:26,
代码来源:LeftToRightSip.java

示例13: testVariable

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testVariable()
{
	String someString = "test";
	String variableName = "X";
	ITerm body = Factory.TERM.createVariable( variableName );
	ITerm relation = Factory.TERM.createString( someString );
	
	Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
	
	assertTrue( TermMatchingAndSubstitution.match( body, relation, variableMap ) );
	
	assertEquals( variableMap.size(), 1 );
	ITerm matchedTerm = variableMap.get( body );
	
	assertEquals( relation, matchedTerm );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:17,
代码来源:TermMatchingAndSubstitutionTest.java

示例14: isSimpleView

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的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

示例15: addEdge

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Updates the sip. Adds an edge with the given source, target and label
 * to the sip. If an edge with the given source and target already
 * exists, the label will be updated.
 */
private void addEdge(final ILiteral source, final ILiteral target,
		final Set<IVariable> passedTo) {
	assert source != null: "The source must not be null";
	assert target != null: "The target must not be null";
	assert passedTo != null: "The passed variables must not be null";

	final LabeledEdge<ILiteral, Set<IVariable>> edge = sipGraph.getEdge(source, target);
	if (edge != null) { // updating the edge
		edge.getLabel().addAll(passedTo);
	} else { // adding a new edge with the passings
		// adding the the literals as vertices
		sipGraph.addVertex(source);
		sipGraph.addVertex(target);

		// add the edge
		sipGraph.addEdge(source, 
				target, 
				new LabeledEdge<ILiteral, Set<IVariable>>(source, 
					target, 
					new HashSet<IVariable>(passedTo)));
	}
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:28,
代码来源:LeftToRightSip.java

示例16: getBoundVariables

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public Set<IVariable> getBoundVariables(final ILiteral literal) {
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<IVariable>emptySet();
	}

	final Set<IVariable> variables = new HashSet<IVariable>();

	for (final ILiteral predicate : Graphs.predecessorListOf(sipGraph, literal)) {
		variables.addAll(sipGraph.getEdge(predicate, literal).getLabel());
	}
	return variables;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:17,
代码来源:LeftToRightSip.java

示例17: getEdgesEnteringLiteral

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public Set<LabeledEdge<ILiteral, Set<IVariable>>> getEdgesEnteringLiteral(
		final ILiteral literal) {
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<LabeledEdge<ILiteral, Set<IVariable>>>emptySet();
	}

	final List<ILiteral> predecessors = Graphs.predecessorListOf(sipGraph, literal);
	final Set<LabeledEdge<ILiteral, Set<IVariable>>> edges = 
		new HashSet<LabeledEdge<ILiteral, Set<IVariable>>>(predecessors.size());
	for (final ILiteral predecessor : predecessors) {
		edges.add(sipGraph.getEdge(predecessor, literal));
	}
	return edges;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:19,
代码来源:LeftToRightSip.java

示例18: getAllUnlimitedVariables

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public List<IVariable> getAllUnlimitedVariables()
{
	Set<IVariable> result = new HashSet<IVariable>();
	
	List<IVariable> unlimitedHeadVariables = new ArrayList<IVariable>( mHeadVariables );
	unlimitedHeadVariables.removeAll( mLimitedVariables );

	result.addAll( unlimitedHeadVariables );
	
	List<IVariable> unlimitedBuiltinVariables = new ArrayList<IVariable>( mBuiltin );
	unlimitedBuiltinVariables.removeAll( mLimitedVariables );
	
	result.addAll( unlimitedBuiltinVariables );

	if ( ! mAllowNotLimitedVariablesInNegatedSubGoals )
	{
		List<IVariable> unlimitedNegativeOrdinaryVariables = new ArrayList<IVariable>( mNegativeOrdinary );
		unlimitedNegativeOrdinaryVariables.removeAll( mLimitedVariables );

		result.addAll( unlimitedNegativeOrdinaryVariables );
	}
	
	return new ArrayList<IVariable>( result );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:25,
代码来源:RuleValidator.java

示例19: subsums

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Given two tuples, check if one tuple sub-sums the other one. Used to 
 * check if it is necessary to add a atom to the memo table or if an equivalent
 * atom is already in the memo table. Unification is not sufficient for this task,
 * since e.g. p(?X) and p(1) are unifiable, but are likely to have different answers.
 *  
 * @param tup1 tuple one
 * @param tup2 tuple two
 *  
 * @return true if the tuples are equivalent, false if not
 * 
 * @author gigi
 */
public static boolean subsums( ITuple tup1, ITuple tup2 ) {

	Map<IVariable, ITerm> varMap = new HashMap<IVariable, ITerm>();
	
	if (tup2.getVariables().size() > tup1.getVariables().size())
		return false; // If the second tuple has more variables than the first one, the first tuple does not subsum the second one
	
	if (unify(tup1, tup2, varMap, false)) {
		
		for (ITerm mappedTerm : varMap.values()) {
			if (mappedTerm.isGround())
				return false; // unifiable, but unification mapped a variable to a ground term
		}
		
		if (varMap.isEmpty())
			return false;
		
		return true; // unifiable, only variable to variable mappings
	}
	
	return false;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:36,
代码来源:TermMatchingAndSubstitution.java

示例20: View

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Kind of copy constructor.
 * @param relation The viewed relation.
 * @param viewCriteria The view criteria.
 * @param variables The computed output variables.
 * @param simple Indicates of the view is simple (pass thorugh)
 * @param equivalentTerms The equivalent terms.
 */
public View( IRelation relation, ITuple viewCriteria, List<IVariable> variables, boolean simple, 
		IEquivalentTerms equivalentTerms, IRelationFactory relationFactory )
{
	mViewCriteria = viewCriteria;
	mVariables = variables;
	mInputRelation = relation;
	mSimple = simple;
	mRelationFactory = relationFactory;
	mEquivalentTerms = equivalentTerms;

	if( mSimple )
		mViewTuples = relation;
	else
		mViewTuples = mRelationFactory.createRelation();
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:24,
代码来源:View.java

示例21: testUnifyConstructedTerms

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testUnifyConstructedTerms()
{
	// f( ?X, y ) = f( x, ?Y )
	// => ?X = x, ?Y = y
	
	IVariable X = Factory.TERM.createVariable( "X" );
	IVariable Y = Factory.TERM.createVariable( "Y" );

	ITerm x = Factory.TERM.createString( "x" );
	ITerm y = Factory.TERM.createString( "y" );
	
	ITerm c1 = Factory.TERM.createConstruct( "f", X, y );
	ITerm c2 = Factory.TERM.createConstruct( "f", x, Y );

	Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
	
	assertTrue( TermMatchingAndSubstitution.unify( c1, c2, variableMap ) );
	assertEquals( 2, variableMap.size() );
	assertTrue( variableMap.get( X ).equals( x ) );
	assertTrue( variableMap.get( Y ).equals( y ) );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:22,
代码来源:TermMatchingAndSubstitutionTest.java

示例22: HeadSubstituter

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Constructor.
 * @param variables The variables from the rule body.
 * @param headTuple The tuple from the rule head.
 * @throws EvaluationException If unbound variables occur.
 */
public HeadSubstituter( List<IVariable> variables, ITuple headTuple, Configuration configuration ) throws EvaluationException
{
	assert variables != null;
	assert headTuple != null;
	assert configuration != null;
	
	mConfiguration = configuration;
	
	mHeadTuple = headTuple;

	// Work out the indices of variables in substitution order
	List<IVariable> variablesToSubstitute = TermMatchingAndSubstitution.getVariables( mHeadTuple, false );
	mIndices = new int[ variablesToSubstitute.size() ];
	
	int i = 0;
	for( IVariable variable : variablesToSubstitute )
	{
		int index = variables.indexOf( variable );
		if( index < 0 )
			throw new RuleUnsafeException( "Unbound variable in rule head: " + variable );
		mIndices[ i++ ] = index;
	}
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:30,
代码来源:HeadSubstituter.java

示例23: unifyCheckBinding

点赞 3

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
private static boolean unifyCheckBinding( IVariable variable, ITerm term, Map<IVariable, ITerm> variableMap, IEquivalentTerms equivalentTerms )
{
	// First version does not skip and retry
	if( ! term.isGround() && ! (term instanceof IConstructedTerm) ) // added by gigi for top-down evaluation: && ! (term instanceof IConstructedTerm), so e.g. X => f(X) is possible
		return false;
	
	ITerm existingMapping = variableMap.get( variable );
	if( existingMapping == null )
	{
		// Add a new mapping for (variable) t1 => t2
		variableMap.put( variable, term );
	}
	else
	{
		// check that the existing mapping is the same
		if( ! existingMapping.equals( term ) && 
				!equivalentTerms.areEquivalent(existingMapping, term) )
			return false;
	}
	
	return true;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:23,
代码来源:TermMatchingAndSubstitution.java

示例24: getStatementRowFilterQuery

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Selects feature vectors with:
 *  - At least one keyword with context != STATEMENT
 * @param maxComplexity The maximum complexity for the feature vector.
 * @return The Datalog query that selects which rows to data mine.
 */
public static IQuery getStatementRowFilterQuery(Integer maxComplexity) {

	IVariable complexity = Factory.TERM.createVariable("Complexity");

	IQuery query =
		Factory.BASIC.createQuery(
			Factory.BASIC.createLiteral(true,
				Factory.BASIC.createPredicate("FeatureVector", 8),
				Factory.BASIC.createTuple(
					Factory.TERM.createVariable("ID"),
					Factory.TERM.createVariable("CommitMessage"),
					Factory.TERM.createVariable("URL"),
					Factory.TERM.createVariable("BuggyCommitID"),
					Factory.TERM.createVariable("RepairedCommitID"),
					Factory.TERM.createVariable("Class"),
					Factory.TERM.createVariable("Method"),
					complexity)),
			Factory.BASIC.createLiteral(true,
				Factory.BASIC.createPredicate("KeywordChange", 7),
				Factory.BASIC.createTuple(
					Factory.TERM.createVariable("ID"),
					Factory.TERM.createVariable("KeywordType"),
					Factory.TERM.createVariable("KeywordContext"),
					Factory.TERM.createVariable("ChangeType"),
					Factory.TERM.createVariable("Package"),
					Factory.TERM.createVariable("Keyword"),
					Factory.TERM.createVariable("Count"))),
			Factory.BASIC.createLiteral(true,
				Factory.BUILTIN.createNotExactEqual(
					Factory.TERM.createVariable("KeywordContext"),
					Factory.TERM.createString(KeywordContext.STATEMENT.toString()))),
			Factory.BASIC.createLiteral(true,
				Factory.BUILTIN.createNotExactEqual(
					Factory.TERM.createVariable("ChangeType"),
					Factory.TERM.createString(ChangeType.UPDATED.toString()))));

	return query;

}
 

开发者ID:saltlab,
项目名称:BugAID,
代码行数:46,
代码来源:LearningDataSetMain.java

示例25: getBasicRowFilterQuery

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
	 * Selects feature vectors with:
	 *  - Complexity <= {@code complexity}
	 *  - Commit message != MERGE
	 * @param maxComplexity The maximum complexity for the feature vector.
	 * @return The Datalog query that selects which rows to data mine.
	 */
	public static IQuery getBasicRowFilterQuery(Integer maxComplexity) {

		IVariable complexity = Factory.TERM.createVariable("Complexity");

		IQuery query =
			Factory.BASIC.createQuery(
				Factory.BASIC.createLiteral(true,
					Factory.BASIC.createPredicate("FeatureVector", 8),
					Factory.BASIC.createTuple(
						Factory.TERM.createVariable("ID"),
						Factory.TERM.createVariable("CommitMessage"),
						Factory.TERM.createVariable("URL"),
						Factory.TERM.createVariable("BuggyCommitID"),
						Factory.TERM.createVariable("RepairedCommitID"),
						Factory.TERM.createVariable("Class"),
						Factory.TERM.createVariable("Method"),
						complexity)),
				Factory.BASIC.createLiteral(true,
					Factory.BUILTIN.createLessEqual(
						complexity,
						Factory.CONCRETE.createInt(maxComplexity))),
				Factory.BASIC.createLiteral(true,
					Factory.BUILTIN.createNotExactEqual(
						Factory.TERM.createVariable("CommitMessage"),
						Factory.TERM.createString(Type.MERGE.toString()))));
//				Factory.BASIC.createLiteral(true,
//					Factory.BUILTIN.createEqual(
//						Factory.TERM.createVariable("CommitMessage"),
//						Factory.TERM.createString(Type.BUG_FIX.toString())))

		return query;

	}
 

开发者ID:saltlab,
项目名称:BugAID,
代码行数:41,
代码来源:LearningDataSetEvaluation.java

示例26: addVariablesFromPositiveArithmeticPredicate

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Add variables from arithmetic or equality predicates
 * 
 * @param isEquality true if the predicate is equality.
 * @param variables The variable names.
 */
private void addVariablesFromPositiveArithmeticPredicate( boolean isEquality, List<IVariable> variables )
{
	mBuiltin.addAll( variables );

	if( isEquality || mAllowArithmeticPredicatesToImplyLimited )
		mArithmeticGroups.add( variables );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:14,
代码来源:RuleValidator.java

示例27: getTupleVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Retrieves the variables out of a collection of tuples.
 * @param from the tuples
 * @param to the collection where to add the variables to
 * @return the reference to <code>to</code>
 * @throws IllegalArgumentException if <code>t</code> is
 * <code>null</code>
 * @throws IllegalArgumentException if <code>to</code> is
 * <code>null</code>
 */
public static Collection<IVariable> getTupleVariables(final Collection<? extends ITuple> from, 
		final Collection<IVariable> to) {
	if (from == null) {
		throw new IllegalArgumentException("The tuple collection must not be null");
	}

	for (final ITuple tuple : from) {
		getTermVariables(tuple, to);
	}
	return to;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:22,
代码来源:VariableExtractor.java

示例28: getLiteralVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Retrieves the variables out of a collection of literals.
 * @param from the literals
 * @param to the collection where to add the variables to
 * @return the reference to <code>to</code>
 * @throws IllegalArgumentException if <code>t</code> is
 * <code>null</code>
 * @throws IllegalArgumentException if <code>to</code> is
 * <code>null</code>
 */
public static Collection<IVariable> getLiteralVariables(final Collection<? extends ILiteral> from, 
		final Collection<IVariable> to) {
	if (from == null) {
		throw new IllegalArgumentException("The literal collection must not be null");
	}

	for (final ILiteral literal : from) {
		getTupleVariables(Collections.singleton(literal.getAtom().getTuple()), to);
	}
	return to;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:22,
代码来源:VariableExtractor.java

示例29: getLiteralVariablesList

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Retrieves the variables out of a collection of literals.
 * @param t the literals
 * @return the list of variables
 * @throws IllegalArgumentException if the collection is
 * <code>null</code>
 */
public static List<IVariable> getLiteralVariablesList(final Collection<? extends ILiteral> l) {
	if (l == null) {
		throw new IllegalArgumentException("The literal collection must not be null");
	}

	return (List<IVariable>) getLiteralVariables(l, new ArrayList<IVariable>());
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:15,
代码来源:VariableExtractor.java

示例30: getTermVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Retrieves the variables out of a collection of terms.
 * @param t the terms
 * @return the list of variables
 * @throws IllegalArgumentException if the collection is
 * <code>null</code>
 */
public static Set<IVariable> getTermVariables(final Collection<? extends ITerm> t) {
	if (t == null) {
		throw new IllegalArgumentException("The term collection must not be null");
	}

	return (Set<IVariable>) getTermVariables(t, new HashSet<IVariable>());
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:15,
代码来源:VariableExtractor.java

示例31: testConstantMatch

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public void testConstantMatch()
{
	String someString = "test";
	ITerm body = Factory.TERM.createString( someString );
	ITerm relation = Factory.TERM.createString( someString );
	
	Map<IVariable, ITerm> variableMap = new HashMap<IVariable, ITerm>();
	
	assertTrue( TermMatchingAndSubstitution.match( body, relation, variableMap ) );
	
	assertEquals( variableMap.size(), 0 );
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:13,
代码来源:TermMatchingAndSubstitutionTest.java

示例32: getVariablesList

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Retrieves the variables out of a array of tuples.
 * @param t the tuples
 * @return the list of variables
 * @throws IllegalArgumentException if the collection is
 * <code>null</code>
 */
public static List<IVariable> getVariablesList(final ITuple... t) {
	if (t == null) {
		throw new IllegalArgumentException("The tuple array must not be null");
	}

	return getTupleVariablesList(Arrays.asList(t));
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:15,
代码来源:VariableExtractor.java

示例33: createVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
private void createVariables() {
	variables = new ArrayList<IVariable>();

	for (int i = 0; i < maximalArity; i++) {
		String name = variablePrefix + i;
		IVariable variable = TERM.createVariable(name);
		variables.add(variable);
	}
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:10,
代码来源:RandomProgramBuilder.java

示例34: process

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
public IRule process( IRule rule ) throws RuleUnsafeException
{
	RuleValidator validator = new RuleValidator( rule,
					mAllowUnlimitedVariablesInNegatedOrdinaryPredicates, 
					mTernaryTargetsImplyLimited );
	
	List<IVariable> unsafeVariables = validator.getAllUnlimitedVariables();
	
	if( unsafeVariables.size() > 0 )
	{
		StringBuilder buffer = new StringBuilder();
		buffer.append( rule ).append( " contains unlimited variable(s): " );
		
		boolean first = true;
		for( IVariable variable : unsafeVariables )
		{
			if( first )
				first = false;
			else
				buffer.append( ", " );
			buffer.append( variable );
		}
		
		throw new RuleUnsafeException( buffer.toString() );
	}
	
	return rule;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:29,
代码来源:StandardRuleSafetyProcessor.java

示例35: getVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
private Set<IVariable> getVariables(final IConstructedTerm t) {
	assert t != null: "The conscructed term must not be null";

	final Set<IVariable> variables = new HashSet<IVariable>();
	for (final ITerm term : t.getValue()) {
		if(term instanceof IVariable) {
			variables.add((IVariable) term);
		}
		if(term instanceof IConstructedTerm) {
			variables.addAll(getVariables((IConstructedTerm) term));
		}
	}
	return variables;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:15,
代码来源:Tuple.java

示例36: createVarList

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Creates a list of IVariables out of a list of strings.
 * 
 * @param vars
 *            the variable names
 * @return the list of correspoinding variables
 * @throws NullPointerException
 *             if the vars is null, or contains null
 */
private static List<IVariable> createVarList(final String... vars) {
	if ((vars == null) || Arrays.asList(vars).contains(null)) {
		throw new NullPointerException(
				"The vars must not be null and must not contain null");
	}
	final List<IVariable> v = new ArrayList<IVariable>(vars.length);
	for (final String var : vars) {
		v.add(TERM.createVariable(var));
	}
	return v;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:21,
代码来源:MultiplyBuiltinEvaluationTest.java

示例37: getAllVariables

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
private List<IVariable> getAllVariables(final IConstructedTerm t) {
	assert t != null: "The conscructed term must not be null";

	final List<IVariable> variables = new ArrayList<IVariable>();
	for(final ITerm term : t.getValue()){
		if (term instanceof IVariable) {
			variables.add((IVariable) term);
		}
		if (term instanceof IConstructedTerm) {
			variables.addAll(getAllVariables((IConstructedTerm) term));
		}
	}
	return variables;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:15,
代码来源:Tuple.java

示例38: evaluateQuery

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Evaluate the query
 */
public IRelation evaluateQuery(IQuery query, List<IVariable> outputVariables) throws ProgramNotStratifiedException, RuleUnsafeException, EvaluationException {
	if( query == null )
		throw new IllegalArgumentException( "SLDEvaluationStrategy.evaluateQuery() - query must not be null." ); 
	
	SLDNFEvaluator evaluator = new SLDNFEvaluator( mFacts, mRules );
	IRelation relation = evaluator.evaluate(query);
		outputVariables.addAll( evaluator.getOutputVariables() );
		
	return relation;
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:14,
代码来源:SLDNFEvaluationStrategy.java

示例39: testEvaluableBuiltinPassing

点赞 2

import org.deri.iris.api.terms.IVariable; //导入依赖的package包/类
/**
 * Checks, whether evaluable built-ins produce passings.
 */
public void testEvaluableBuiltinPassing() throws Exception {
	final String prog = "i(?X) :- e0(?X), e1(?Y), ?X < ?Y, e2(?Y)."
		+ "?- i(?X).";
	final LeftToRightSip sip = parseProgram(prog);

	final IVariable X = TERM.createVariable("X");
	final IVariable Y = TERM.createVariable("Y");
	final ILiteral e0 = createLiteral("e0", "X");
	final ILiteral e1 = createLiteral("e1", "Y");
	final ILiteral e2 = createLiteral("e2", "Y");
	final ILiteral less = BASIC.createLiteral(true, BUILTIN.createLess(X, Y));

	final Set<LabeledEdge<ILiteral, Set<IVariable>>> edges
		= new HashSet<LabeledEdge<ILiteral, Set<IVariable>>>();

	// e1(?Y) ->( [?Y] )-> LESS(?X, ?Y)
	edges.add(createEdge(e1, less, Y));
	// e0(?X) ->( [?X] )-> LESS(?X, ?Y)
	edges.add(createEdge(e0, less, X));
	// e1(?Y) ->( [?Y] )-> e2(?Y)
	edges.add(createEdge(e1, e2, Y));
	// LESS(?X, ?Y) ->( [?Y] )-> e2(?Y)
	edges.add(createEdge(less, e2, Y));

	assertEquals("The edge set does not match.", edges, sip.getEdges());
}
 

开发者ID:NICTA,
项目名称:iris-reasoner,
代码行数:30,
代码来源:LeftToRightSipTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)