Package org.semanticweb.HermiT.model

Examples of org.semanticweb.HermiT.model.Variable


                            numberOfUnboundVariables++;
                    }
                }
                int goodness=numberOfBoundVariables*100-numberOfUnboundVariables*10;
                if (atom.getDLPredicate().getArity()==2 && numberOfUnboundVariables==1 && !m_nodeIDComparisonAtoms.isEmpty()) {
                    Variable unboundVariable=atom.getArgumentVariable(0);
                    if (m_boundVariables.contains(unboundVariable))
                        unboundVariable=atom.getArgumentVariable(1);
                    // At this point, unboundVariable must be really unbound because
                    // we have already established that numberOfUnboundVariables==1.
                    for (int compareAtomIndex=m_nodeIDComparisonAtoms.size()-1;compareAtomIndex>=0;--compareAtomIndex) {
                        Atom compareAtom=m_nodeIDComparisonAtoms.get(compareAtomIndex);
                        Variable argument0=compareAtom.getArgumentVariable(0);
                        Variable argument1=compareAtom.getArgumentVariable(1);
                        if ((m_boundVariables.contains(argument0) || unboundVariable.equals(argument0)) && (m_boundVariables.contains(argument1) || unboundVariable.equals(argument1))) {
                            goodness+=5;
                            break;
                        }
                    }
View Full Code Here


            m_variables=new ArrayList<Variable>();
            int numberOfRealAtoms=0;
            for (int bodyIndex=0;bodyIndex<getBodyLength();bodyIndex++) {
                Atom atom=getBodyAtom(bodyIndex);
                for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                    Variable variable=atom.getArgumentVariable(argumentIndex);
                    if (variable!=null && !m_variables.contains(variable) && occursInBodyAtomsAfter(variable,bodyIndex+1))
                        m_variables.add(variable);
                }
                if (!atom.getDLPredicate().equals(NodeIDLessEqualThan.INSTANCE) && !(atom.getDLPredicate() instanceof NodeIDsAscendingOrEqual))
                    numberOfRealAtoms++;
            }
            for (int dlClauseIndex=0;dlClauseIndex<getNumberOfHeads();dlClauseIndex++) {
                for (int headIndex=0;headIndex<getHeadLength(dlClauseIndex);headIndex++) {
                    Atom atom=getHeadAtom(dlClauseIndex,headIndex);
                    for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                        Variable variable=atom.getArgumentVariable(argumentIndex);
                        if (variable!=null && !m_variables.contains(variable))
                            m_variables.add(variable);
                    }
                }
            }
View Full Code Here

                variables.clear();
                for (int bodyIndex=dlClause.getBodyLength()-1;bodyIndex>=0;--bodyIndex) {
                    Atom atom=dlClause.getBodyAtom(bodyIndex);
                    bodyDLPredicates.add(atom.getDLPredicate());
                    for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                        Variable variable=atom.getArgumentVariable(argumentIndex);
                        if (variable!=null)
                            variables.add(variable);
                    }
                }
                if (variables.size()>maxNumberOfVariables)
View Full Code Here

        public DLClauseInfo(DLClause dlClause,ExtensionManager extensionManager) {
            m_dlClause=dlClause;
            // TODO: We'll sort our the variables by names. This introduces a dependency
            // to clausification. That's ugly and should be fixed later.
            Variable X=Variable.create("X");
            Set<AtomicConcept> xConcepts=new HashSet<AtomicConcept>();
            Set<AtomicRole> x2xRoles=new HashSet<AtomicRole>();
            Set<Variable> ys=new HashSet<Variable>();
            Map<Variable,Set<AtomicConcept>> y2concepts=new HashMap<Variable, Set<AtomicConcept>>();
            Map<Variable,Set<AtomicConcept>> z2concepts=new HashMap<Variable, Set<AtomicConcept>>();
            Map<Variable,Set<AtomicRole>> x2yRoles=new HashMap<Variable, Set<AtomicRole>>();
            Map<Variable,Set<AtomicRole>> y2xRoles=new HashMap<Variable, Set<AtomicRole>>();
            // Each atom in the antecedent is of the form A(x), R(x,x), R(x,yi), R(yi,x), A(yi), or A(zj).
            for (int i=0;i<dlClause.getBodyLength();i++) {
                Atom atom=dlClause.getBodyAtom(i);
                DLPredicate predicate=atom.getDLPredicate();
                Variable var1=atom.getArgumentVariable(0);
                if (predicate instanceof AtomicConcept) {
                    if (var1==X) {
                        xConcepts.add((AtomicConcept)predicate);
                    } else if (var1.getName().startsWith("Y")) {
                        ys.add(var1);
                        if (y2concepts.containsKey(var1)) {
                            y2concepts.get(var1).add((AtomicConcept)predicate);
                        } else {
                            Set<AtomicConcept> concepts=new HashSet<AtomicConcept>();
                            concepts.add((AtomicConcept)predicate);
                            y2concepts.put(var1, concepts);
                        }
                    } else if (var1.getName().startsWith("Z")) {
                        if (z2concepts.containsKey(var1)) {
                            Set<AtomicConcept> concepts=z2concepts.get(var1);
                            concepts.add((AtomicConcept)predicate);
                        } else {
                            Set<AtomicConcept> concepts=new HashSet<AtomicConcept>();
                            concepts.add((AtomicConcept)predicate);
                            z2concepts.put(var1, concepts);
                        }
                    } else {
                        throw new IllegalStateException("Internal error: Clause premise contained variables other than X, Yi, and Zi in a concept atom. ");
                    }
                } else if (predicate instanceof AtomicRole) {
                    Variable var2=atom.getArgumentVariable(1);
                    if (var1==X) {
                        if (var2==X) {
                            x2xRoles.add((AtomicRole)atom.getDLPredicate());
                        } else if (var2.getName().startsWith("Y")) {
                            ys.add(var2);
                            if (x2yRoles.containsKey(var2)) {
                                x2yRoles.get(var2).add((AtomicRole)predicate);
                            } else {
                                Set<AtomicRole> roles=new HashSet<AtomicRole>();
                                roles.add((AtomicRole)predicate);
                                x2yRoles.put(var2,roles);
                            }
                        } else {
                            throw new IllegalStateException("Internal error: Clause premise contains a role atom with virales other than X and Yi. ");
                        }
                    } else if (var2==X) {
                        if (var1.getName().startsWith("Y")) {
                            ys.add(var1);
                            if (y2xRoles.containsKey(var1)) {
                                y2xRoles.get(var1).add((AtomicRole)predicate);
                            } else {
                                Set<AtomicRole> roles=new HashSet<AtomicRole>();
                                roles.add((AtomicRole)predicate);
                                y2xRoles.put(var1,roles);
                            }
                        } else {
                            throw new IllegalStateException("Internal error: Clause premise contains a role atom with virales other than X and Yi. ");
                        }
                    } else {
                        throw new IllegalStateException("Internal error: Clause premise contained variables other than X and Yi in a role atom. ");
                    }
                }
            }
            AtomicConcept[] noConcepts=new AtomicConcept[0];
            AtomicRole[] noRoles=new AtomicRole[0];
            Variable[] noVariables=new Variable[0];

            // Variable X
            m_xNode=null;
            m_xConcepts=xConcepts.toArray(noConcepts);
            m_x2xRoles=x2xRoles.toArray(noRoles);

            // Variable Y
            m_yVariables=ys.toArray(noVariables);
            m_yNodes=new Node[m_yVariables.length];
            m_yConstraints=new YConstraint[m_yVariables.length];
            m_x2yRetrievals=new Retrieval[x2yRoles.size()];
            m_x2yRoles=new AtomicRole[x2yRoles.size()];
            m_y2xRetrievals=new Retrieval[y2xRoles.size()];
            m_y2xRoles=new AtomicRole[y2xRoles.size()];
            int i=0;
            int num_xyRoles=0;
            for (i=0;i<m_yVariables.length;i++) {
                Variable y=m_yVariables[i];
                Set<AtomicConcept> yConcepts=y2concepts.get(y);
                Set<AtomicRole> xyRoles=x2yRoles.get(y);
                if (xyRoles!=null) {
                    assert xyRoles.size()==1;
                    assert m_y2xRetrievals.length<m_x2yRetrievals.length;
                    m_x2yRetrievals[num_xyRoles]=extensionManager.getTernaryExtensionTable().createRetrieval(new boolean[] { true,true,false },ExtensionTable.View.TOTAL);
                    m_x2yRoles[num_xyRoles]=xyRoles.iterator().next();
                    num_xyRoles++;
                }
                Set<AtomicRole> yxRoles=y2xRoles.get(y);
                if (yxRoles!=null) {
                    assert yxRoles.size()==1;
                    assert i-num_xyRoles>=0;
                    assert i-num_xyRoles<m_y2xRetrievals.length;
                    m_y2xRetrievals[i-num_xyRoles]=extensionManager.getTernaryExtensionTable().createRetrieval(new boolean[] { true,false,true },ExtensionTable.View.TOTAL);
                    m_y2xRoles[i-num_xyRoles]=yxRoles.iterator().next();
                }
                m_yConstraints[i]=new YConstraint(yConcepts!=null?yConcepts.toArray(noConcepts):noConcepts, xyRoles!=null?xyRoles.toArray(noRoles):noRoles, yxRoles!=null?yxRoles.toArray(noRoles):noRoles);
            }

            // Variable Z
            m_zVariables=z2concepts.keySet().toArray(noVariables);
            m_zNodes=new Node[m_zVariables.length];
            m_zConcepts=new AtomicConcept[m_zNodes.length][];
            for (int varIndex=0;varIndex<m_zVariables.length;varIndex++) {
                m_zConcepts[varIndex]=z2concepts.get(m_zVariables[varIndex]).toArray(noConcepts);
            }
            m_zRetrievals=new Retrieval[m_zNodes.length];
            for (i=0;i<m_zRetrievals.length;i++) {
                m_zRetrievals[i]=extensionManager.getBinaryExtensionTable().createRetrieval(new boolean[] { true,false },ExtensionTable.View.TOTAL);
            }

            // Consequences
            m_consequencesForBlockedX=new ConsequenceAtom[dlClause.getHeadLength()];
            m_consequencesForNonblockedX=new ConsequenceAtom[dlClause.getHeadLength()];
            //Each atom in the consequent is of the form B(x), >= h S.B(x), B(yi), R(x, x),
            // R(x,yi), R(yi,x), R(x,zj), R(zj,x), x==zj, or yi==yj @^x_{<=h S.B}.
            for (i=0;i<dlClause.getHeadLength();i++) {
                Atom atom=dlClause.getHeadAtom(i);
                DLPredicate predicate=atom.getDLPredicate();
                Variable var1=atom.getArgumentVariable(0);
                Variable var2=null;
                if (predicate.getArity()==2) var2=atom.getArgumentVariable(1);

                if (predicate instanceof AtomicConcept) {
                    // B(x), B(yi)
                    ArgumentType argType=ArgumentType.YVAR;
                    int argIndex=getIndexFor(m_yVariables, var1);
                    if (argIndex==-1) {
                        assert var1==X;
                        argIndex=0;
                        argType=ArgumentType.XVAR;
                    }
                    m_consequencesForBlockedX[i]=new SimpleConsequenceAtom(predicate,new ArgumentType[] { argType },new int[] { argIndex });
                    if (argType==ArgumentType.XVAR) {
                        m_consequencesForNonblockedX[i]=m_consequencesForBlockedX[i];
                    } else {
                        m_consequencesForNonblockedX[i]=new MirroredYConsequenceAtom((AtomicConcept)predicate,argIndex);
                    }
                } else if (predicate instanceof AtLeastConcept) {
                    // >= h S.B(x)
                    assert var1==X;
                    m_consequencesForBlockedX[i]=new SimpleConsequenceAtom(predicate,new ArgumentType[] { ArgumentType.XVAR },new int[] { 0 });
                    m_consequencesForNonblockedX[i]=m_consequencesForBlockedX[i];
                } else if (predicate==Equality.INSTANCE) {
                    // x==zi or y==zi or yi===yj for datatype assertions
                    if (var1==X || var2==X) {
                        // x==zi
                        if (var2==X) {
                            Variable tmp=var1;
                            var1=var2;
                            var2=tmp;
                        }
                        assert var2.getName().startsWith("Z");
                        int var2Index=getIndexFor(m_zVariables, var2);
                        assert var1==X && var2Index!=-1;
                        m_consequencesForBlockedX[i]=new SimpleConsequenceAtom(predicate,new ArgumentType[] { ArgumentType.XVAR,ArgumentType.ZVAR },new int[] { 0,var2Index });
                        m_consequencesForNonblockedX[i]=m_consequencesForBlockedX[i];
                    } else if (var1.getName().startsWith("Z") || var2.getName().startsWith("Z")) {
                        // y==zi
                        if (var2.getName().startsWith("Y")) {
                            Variable tmp=var1;
                            var1=var2;
                            var2=tmp;
                        }
                        assert var2.getName().startsWith("Z");
                        int var2Index=getIndexFor(m_zVariables, var2);
View Full Code Here

                int nextElement=addLabel();
                Atom atom=getBodyAtom(bodyAtomIndex);
                int[] bindingPositions=new int[atom.getArity()+1];
                bindingPositions[0]=m_valuesBufferManager.m_bodyDLPredicatesToIndexes.get(atom.getDLPredicate()).intValue();
                for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                    Variable variable=atom.getArgumentVariable(argumentIndex);
                    if (variable!=null && m_boundSoFar.contains(variable))
                        bindingPositions[argumentIndex+1]=m_variables.indexOf(variable);
                    else
                        bindingPositions[argumentIndex+1]=-1;
                }
View Full Code Here

                    int index=0;
                    for (int headIndex=0;headIndex<getHeadLength(dlClauseIndex);headIndex++) {
                        Atom atom=getHeadAtom(dlClauseIndex,headIndex);
                        headDLPredicates[headIndex]=atom.getDLPredicate();
                        for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                            Variable variable=atom.getArgumentVariable(argumentIndex);
                            int variableIndex=m_variables.indexOf(variable);
                            assert variableIndex!=-1;
                            copyValuesToArguments[index++]=variableIndex;
                        }
                        if (headDLPredicates[headIndex].getArity()==1) {
                            Variable variable=atom.getArgumentVariable(0);
                            copyIsCore[headIndex]=m_variables.indexOf(variable);
                        }
                        else
                            copyIsCore[headIndex]=-1;
                    }
View Full Code Here

                    m_workers.add(new CallMatchFinishedOnMonitor(m_extensionManager.m_tableauMonitor,m_dlClauseEvalautor,dlClauseIndex));
            }
        }
        protected void compileCheckUnboundVariableMatches(Atom atom,ExtensionTable.Retrieval retrieval,int jumpIndex) {
            for (int outerArgumentIndex=0;outerArgumentIndex<atom.getArity();outerArgumentIndex++) {
                Variable variable=atom.getArgumentVariable(outerArgumentIndex);
                if (variable!=null && !m_boundSoFar.contains(variable)) {
                    for (int innerArgumentIndex=outerArgumentIndex+1;innerArgumentIndex<atom.getArity();innerArgumentIndex++) {
                        if (variable.equals(atom.getArgument(innerArgumentIndex)))
                            m_workers.add(new BranchIfNotEqual(jumpIndex,retrieval.getTupleBuffer(),outerArgumentIndex+1,innerArgumentIndex+1));
                    }
                }
            }
        }
View Full Code Here

                }
            }
        }
        protected void compileGenerateBindings(ExtensionTable.Retrieval retrieval,Atom atom) {
            for (int argumentIndex=0;argumentIndex<atom.getArity();argumentIndex++) {
                Variable variable=atom.getArgumentVariable(argumentIndex);
                if (variable!=null && !m_boundSoFar.contains(variable)) {
                    int variableIndex=m_variables.indexOf(variable);
                    if (variableIndex!=-1) {
                        m_workers.add(new CopyValues(retrieval.getTupleBuffer(),argumentIndex+1,m_valuesBufferManager.m_valuesBuffer,variableIndex));
                        m_boundSoFar.add(variable);
View Full Code Here

        public void visit(SWRLClassAtom atom) {
            if (atom.getPredicate().isAnonymous()) {
                throw new IllegalStateException("Internal error: SWRL rule class atoms should be normalized to contain only named classes, but this class atom has a complex concept: "+atom.getPredicate());
            }
            atom.getArgument().accept(this);
            Variable var=m_lastVariable;
            m_DLSafeVars.add(var);
            m_lastAtom=Atom.create(AtomicConcept.create(atom.getPredicate().asOWLClass().getIRI().toString()),m_lastVariable);
        }
View Full Code Here

        public void visit(SWRLObjectPropertyAtom atom) {
            if (atom.getPredicate().isAnonymous()) {
                throw new IllegalStateException("Internal error: object properties in SWRL rule object property atoms should be normalized to contain only named properties, but this atom has an (anonymous) object property expression: "+atom.getPredicate());
            }
            atom.getFirstArgument().accept(this);
            Variable var1=m_lastVariable;
            m_DLSafeVars.add(var1);
            atom.getSecondArgument().accept(this);
            Variable var2=m_lastVariable;
            m_DLSafeVars.add(var2);
            m_lastAtom=getRoleAtom(atom.getPredicate().asOWLObjectProperty(),var1,var2);
        }
View Full Code Here

TOP

Related Classes of org.semanticweb.HermiT.model.Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.