public static <F,S> Pair<F,S> create(F f, S s) { return new Pair<F,S>( f, s ); }
public static <F,S> Pair<F,S> create(F f, S s) { return new Pair<F,S>( f, s ); }
public List<Pair<State<T>,State<T>>> findTransitions( T transition ) { List<Pair<State<T>,State<T>>> result = new ArrayList<Pair<State<T>,State<T>>>(); for( State<T> s1 : allStates ) { State<T> s2 = s1.move( transition ); if( s2 != null ) result.add( new Pair<State<T>,State<T>>( s1, s2 ) ); } return result; }
public List<Pair<State<T>,State<T>>> findTransitions( T transition ) { List<Pair<State<T>,State<T>>> result = new ArrayList<Pair<State<T>,State<T>>>(); for( State<T> s1 : allStates ) { State<T> s2 = s1.move( transition ); if( s2 != null ) result.add( new Pair<State<T>,State<T>>( s1, s2 ) ); } return result; }
public Set<Fact> run() { // Inserts empty fact to fire rules without bodies Collection<AlphaNode> savedDirties = new ArrayList<AlphaNode>( dirtyAlphas ); dirtyHistory.add( 0, new Pair<Integer, Collection<AlphaNode>>( rete.abox.getBranch(), savedDirties ) ); Collection<Fact> oldInferred = new ArrayList<Fact>( inferredFacts ); while( isDirty() ) { List<BetaNode> dirtyBetas = new ArrayList<BetaNode>(); for( AlphaNode alphaNode : dirtyAlphas ) dirtyBetas.addAll( alphaNode.getBetas() ); dirtyAlphas.clear(); processBetaNodes( dirtyBetas ); } return SetUtils.difference( inferredFacts, oldInferred ); } }
public <V> void join(IndexNode<I, V> node, int shared, Collection<Pair<J, V>> results) { if( shared > 0 ) { for( Map.Entry<I, IndexNode<I, J>> entry : children.entrySet() ) { if( entry.getKey() != null ) { IndexNode<I, V> nodeChild = node.children.get( entry.getKey() ); if( nodeChild != null ) { entry.getValue().join( nodeChild, shared - 1, results ); } IndexNode<I, V> nullNodeChild = node.children.get( null ); if( nullNodeChild != null ) { entry.getValue().join( nullNodeChild, shared - 1, results ); } } else { for( IndexNode<I, V> child : node.children.values() ) { entry.getValue().join( child, shared - 1, results ); } } } } else { for( J leaf : getAllLeaves() ) { for( V joinLeaf : node.getAllLeaves() ) { results.add( new Pair<J, V>( leaf, joinLeaf ) ); } } } }
public <V> void join(IndexNode<I, V> node, int shared, Collection<Pair<J, V>> results) { if( shared > 0 ) { for( Map.Entry<I, IndexNode<I, J>> entry : children.entrySet() ) { if( entry.getKey() != null ) { IndexNode<I, V> nodeChild = node.children.get( entry.getKey() ); if( nodeChild != null ) { entry.getValue().join( nodeChild, shared - 1, results ); } IndexNode<I, V> nullNodeChild = node.children.get( null ); if( nullNodeChild != null ) { entry.getValue().join( nullNodeChild, shared - 1, results ); } } else { for( IndexNode<I, V> child : node.children.values() ) { entry.getValue().join( child, shared - 1, results ); } } } } else { for( J leaf : getAllLeaves() ) { for( V joinLeaf : node.getAllLeaves() ) { results.add( new Pair<J, V>( leaf, joinLeaf ) ); } } } }
/** * Translate inferred rule binding into a Rule-VariableBinding pair. */ public Pair<Rule, VariableBinding> translateFact(Fact fact) { Pair<Rule, VariableBinding> partialApplication = null; if( (fact.getElements().size() >= VARSTARTPOS) && (fact.getElements().get( 0 ).equals( VARBINDING )) ) { Pair<Rule, List<AtomVariable>> ruleVarPair = ruleMap.get( fact.getElements().get( RULEPOS ) ); Rule rule = ruleVarPair.first; List<AtomVariable> vars = ruleVarPair.second; List<ATermAppl> constants = fact.getElements().subList( VARSTARTPOS, fact.getElements().size() ); if( vars.size() != constants.size() ) throw new InternalReasonerException( "Variable list doesn't match constants!" ); VariableBinding binding = new VariableBinding( abox ); for( int i = 0; i < vars.size(); i++ ) vars.get( i ).accept( new BindingSetter( binding, constants.get( i ) ) ); partialApplication = new Pair<Rule, VariableBinding>( rule, binding ); } return partialApplication; }
Pair<Rule, VariableBinding> ruleKey = new Pair<Rule, VariableBinding>( rule, binding ); if( !rulesApplied.containsKey( ruleKey ) ) {
ruleVars.add( varToVar.get( var ) ); ruleMap.put( ruleID, new Pair<Rule, List<AtomVariable>>( rule, ruleVars ) );
public void applyRuleBindings() { int total = 0; for( PartialBinding ruleBinding : partialBindings ) { Rule rule = ruleBinding.getRule(); VariableBinding initial = ruleBinding.getBinding(); for( VariableBinding binding : bindingStrategy.createGenerator( rule, initial ) ) { Pair<Rule, VariableBinding> ruleKey = new Pair<Rule, VariableBinding>( rule, binding ); if( !rulesApplied.containsKey( ruleKey ) ) { total++; if( log.isLoggable( Level.FINE ) ) { log.fine( "Rule: " + rule ); log.fine( "Binding: " + binding ); log.fine( "total:" + total ); } int branch = createDisjunctionsFromBinding( binding, rule, ruleBinding .getDependencySet() ); if( branch >= 0 ) { rulesApplied.put( ruleKey, branch ); } if( abox.isClosed() ) { return; } } } } }
private Pair<OWLClass,OWLClass> getSubClassAxiom(OWLClassExpression desc) { if( !(desc instanceof OWLObjectIntersectionOf) ) return null; OWLObjectIntersectionOf conj = (OWLObjectIntersectionOf) desc; if( conj.getOperands().size() != 2 ) return null; Iterator<OWLClassExpression> conjuncts = conj.getOperands().iterator(); OWLClassExpression c1 = conjuncts.next(); OWLClassExpression c2 = conjuncts.next(); OWLClass sub = null; OWLClass sup = null; if( !c1.isAnonymous() ) { sub = (OWLClass) c1; sup = getNegation( c2 ); } else if( !c2.isAnonymous() ) { sub = (OWLClass) c2; sup = getNegation( c2 ); } if( sup == null ) return null; return new Pair<OWLClass, OWLClass>( sub, sup ); }
/** * Return a pair of a term, and a dependency set. The dependency set will be * non-null if the atom object represented a constant which was merged to * another node. */ public Pair<ATermAppl, DependencySet> translateAtomObject(AtomObject obj) { AtomObjectTranslator translator = new AtomObjectTranslator(); obj.accept(translator); return new Pair<ATermAppl, DependencySet>(translator.getResult(), translator.getDependency()); }