Package org.mindswap.pellet

Examples of org.mindswap.pellet.DependencySet


        }
        node.applyNext[Node.ATOM] = size;
    }
   
    protected void applyUnfoldingRule( Individual node, ATermAppl c ) {
      DependencySet ds = node.getDepends( c );
       
        if(!PelletOptions.MAINTAIN_COMPLETION_QUEUE && ds == null)
      return;            
       
        Iterator<Unfolding> unfoldingList = strategy.getTBox().unfold( c );

        while( unfoldingList.hasNext() ) {
      Unfolding unfolding = unfoldingList.next();
          ATermAppl unfoldingCondition = unfolding.getCondition();
          DependencySet finalDS = node.getDepends( unfoldingCondition );
         
          if( finalDS == null )
            continue;
         
      Set<ATermAppl> unfoldingDS = unfolding.getExplanation()
          finalDS = finalDS.union( ds, strategy.getABox().doExplanation() );
          finalDS = finalDS.union( unfoldingDS, strategy.getABox().doExplanation() );
         
      ATermAppl unfoldedConcept = unfolding.getResult();           
         
            if( log.isLoggable( Level.FINE ) && !node.hasType( unfoldedConcept ) )
                log.fine( "UNF : " + node + ", " + ATermUtils.toString(c) + " -> " + ATermUtils.toString( unfoldedConcept ) + " - " + finalDS );
View Full Code Here


        // someValuesFrom is now in the form not(all(p. not(c)))
        ATermAppl a = (ATermAppl) sv.getArgument( 0 );
        ATermAppl s = (ATermAppl) a.getArgument( 0 );
        ATermAppl c = (ATermAppl) a.getArgument( 1 );

        DependencySet ds = x.getDepends( sv );

       
        if(!PelletOptions.MAINTAIN_COMPLETION_QUEUE && ds == null)
      return;
       
        c = ATermUtils.negate( c );
       
        // Special rule to optimize topObjectProperty
        if ( s.equals( ATermUtils.TOP_OBJECT_PROPERTY ) ) {
          if ( ATermUtils.isNominal( c ) )
            return;
         
          for ( Node node : strategy.getABox().getNodes() ) {
            if ( node.isIndividual() && !node.isPruned() && node.hasType( c ) ) {
              return;
            }
          }
         
          Individual y = strategy.createFreshIndividual( x, ds );
          strategy.addType( y, c, ds );
          return;
        }
       
        Role role = strategy.getABox().getRole( s );


        // Is there a r-neighbor that satisfies the someValuesFrom restriction
        boolean neighborFound = false;
        // Safety condition as defined in the SHOIQ algorithm.
        // An R-neighbor y of a node x is safe if
        // (i) x is blockable or if
        // (ii) x is a nominal node and y is not blocked.
        boolean neighborSafe = x.isBlockable();
        // y is going to be the node we create, and edge its connection to the
        // current node
        Node y = null;
        Edge edge = null;

        // edges contains all the edges going into of coming out from the node
        // And labeled with the role R
        EdgeList edges = x.getRNeighborEdges( role );
        // We examine all those edges one by one and check if the neighbor has
        // type C, in which case we set neighborFound to true
        for( Iterator<Edge> i = edges.iterator(); i.hasNext(); ) {
            edge = i.next();

            y = edge.getNeighbor( x );           
           
            if( PelletOptions.USE_COMPLETION_QUEUE && y.isPruned() ){
                y = null;
                continue;
            }              
           
            if( y.hasType( c ) ) {
              neighborFound = neighborSafe || y.isLiteral() || !strategy.getBlocking().isBlocked( (Individual) y );
                if( neighborFound ) {
                    break;
                }
            }
        }

        // If we have found a R-neighbor with type C, continue, do nothing
        if( neighborFound )
            return;

        // If not, we have to create it
        // If the role is a datatype property...
        if( role.isDatatypeRole() ) {
            Literal literal = (Literal) y;
      if( ATermUtils.isNominal( c ) && !PelletOptions.USE_PSEUDO_NOMINALS ) {
        strategy.getABox().copyOnWrite();

        final ATermAppl input = (ATermAppl) c.getArgument( 0 );
        ATermAppl canonical;
        if( input.getArgument( ATermUtils.LIT_URI_INDEX ).equals( ATermUtils.NO_DATATYPE ) ) {
          canonical = input;
        }
        else {
          try {
            canonical = strategy.getABox().getDatatypeReasoner().getCanonicalRepresentation( input );
          } catch( InvalidLiteralException e ) {
            final String msg = "Invalid literal encountered in nominal when attempting to apply some values rule: "
                + e.getMessage();
            throw new InternalReasonerException( msg, e );
          } catch( UnrecognizedDatatypeException e ) {
            final String msg = "Unrecognized datatype for literal encountered in nominal when attempting to apply some values rule: "
                + e.getMessage();
            throw new InternalReasonerException( msg, e );
          }
        }
        literal = strategy.getABox().addLiteral( canonical );
      }
            else {
                if( !role.isFunctional() || literal == null ) {
                    literal = strategy.getABox().addLiteral( ds );
                }
                else {
                  ds = ds.union( role.getExplainFunctional(), strategy.getABox().doExplanation()  );
                  ds = ds.union( edge.getDepends(), strategy.getABox().doExplanation()  );
                }
                strategy.addType( literal, c, ds );
            }
           
            if( log.isLoggable( Level.FINE ) )
                log.fine( "SOME: " + x + " -> " + s + " -> " + literal + " : " + ATermUtils.toString( c ) + " - " + ds );
           
            strategy. addEdge( x, role, literal, ds );
        }
        // If it is an object property
        else {
            if( ATermUtils.isNominal( c ) && !PelletOptions.USE_PSEUDO_NOMINALS ) {
                strategy.getABox().copyOnWrite();

                ATermAppl value = (ATermAppl) c.getArgument( 0 );
                y = strategy.getABox().getIndividual( value );

                if( log.isLoggable( Level.FINE ) )
                    log.fine( "VAL : " + x + " -> " + ATermUtils.toString( s ) + " -> " + y + " - " + ds );

                if( y == null ) {
                    if( ATermUtils.isAnonNominal( value ) ) {
                        y = strategy.getABox().addIndividual( value, ds );
                    }
                    else if( ATermUtils.isLiteral( value ) )
                        throw new InternalReasonerException( "Object Property " + role
                            + " is used with a hasValue restriction "
                            + "where the value is a literal: " + ATermUtils.toString( value ) );
                    else
                        throw new InternalReasonerException( "Nominal " + c
                            + " is not found in the KB!" );
                }

                if( y.isMerged() ) {
                    ds = ds.union( y.getMergeDependency( true ), strategy.getABox().doExplanation() );

                    y = y.getSame();
                }

                strategy.addEdge( x, role, y, ds );
            }
            else {
                boolean useExistingNode = false;
                boolean useExistingRole = false;
                DependencySet maxCardDS = role.isFunctional()
          ? role.getExplainFunctional()
          : x.hasMax1( role );
                if( maxCardDS != null ) {
                    ds = ds.union( maxCardDS, strategy.getABox().doExplanation() );

                    // if there is an r-neighbor and we can have at most one r then
                    // we should reuse that node and edge. there is no way that neighbor
                    // is not safe (a node is unsafe only if it is blockable and has
                    // a nominal successor which is not possible if there is a cardinality
                    // restriction on the property)
                    if( edge != null ) {
                        useExistingRole = useExistingNode = true;                      
                    }
                    else {
                        // this is the tricky part. we need some merges to happen
                        // under following conditions:
                        // 1) if r is functional and there is a p-neighbor where
                        // p is superproperty of r then we need to reuse that
                        // p neighbor for the some values restriction (no
                        // need to check subproperties because functionality of r
                        // precents having two or more successors for subproperties)
                        // 2) if r is not functional, i.e. max(r, 1) is in the types,
                        // then having a p neighbor (where p is subproperty of r)
                        // means we need to reuse that p-neighbor
                        // In either case if there are more than one such value we also
                        // need to merge them together
                        Set<Role> fs = role.isFunctional() ? role.getFunctionalSupers() : role
                            .getSubRoles();
                       
                        for( Iterator<Role> it = fs.iterator(); it.hasNext(); ) {
                            Role f = it.next();
                            edges = x.getRNeighborEdges( f );
                            if( !edges.isEmpty() ) {
                                if( useExistingNode ) {
                                  DependencySet fds = DependencySet.INDEPENDENT;
                                  if (PelletOptions.USE_TRACING) {
                                    if (role.isFunctional()) {
                                      fds = role.getExplainSuper(f.getName());
                                    } else {
                                      fds = role.getExplainSub(f.getName());
                                    }
                                  }
                                    Edge otherEdge = edges.edgeAt( 0 );
                                    Node otherNode = otherEdge.getNeighbor( x );
                                    DependencySet d = ds.union( edge.getDepends(), strategy.getABox().doExplanation() ).union(
                                        otherEdge.getDepends(), strategy.getABox().doExplanation() ).union(fds, strategy.getABox().doExplanation());
                                    strategy.mergeTo( y, otherNode, d );
                                }
                                else {
                                    useExistingNode = true;
View Full Code Here

   
    EdgeList edges = x.getRNeighborEdges( s );
    for( int e = 0; e < edges.size(); e++ ) {
      Edge edgeToY = edges.edgeAt( e );
      Node y = edgeToY.getNeighbor( x );
      DependencySet finalDS = ds.union( edgeToY.getDepends(), strategy.getABox().doExplanation() );
      if( strategy.getABox().doExplanation() ) {
        Role edgeRole = edgeToY.getRole();
        DependencySet subDS = s.getExplainSubOrInv( edgeRole );
        finalDS = finalDS.union( subDS.getExplain(), true );
      }
     
      applyAllValues( x, s, y, c, finalDS );

      if( x.isMerged() )
        return;
    }

    if( !s.isSimple() ) {
      for( Role r : s.getTransitiveSubRoles() ) {
        ATermAppl allRC = ATermUtils.makeAllValues( r.getName(), c );

        edges = x.getRNeighborEdges( r );
        for( int e = 0; e < edges.size(); e++ ) {
          Edge edgeToY = edges.edgeAt( e );
          Node y = edgeToY.getNeighbor( x );
          DependencySet finalDS = ds.union( edgeToY.getDepends(), strategy.getABox().doExplanation() );
          if( strategy.getABox().doExplanation() ) {
            finalDS = finalDS.union( r.getExplainTransitive().getExplain(), true );
            finalDS = finalDS.union( s.getExplainSubOrInv( edgeToY.getRole() ), true );
          }
         
          applyAllValues( x, r, y, allRC, finalDS );

          if( x.isMerged() )
View Full Code Here

              applyAllValuesTop( av, c, ds );
              continue;
            }
     
      if( pred.isSubRoleOf( s ) ) {
        DependencySet finalDS = ds.unionsubj.getDepends( av ), strategy.getABox().doExplanation() );
        if( strategy.getABox().doExplanation() )
          finalDS = finalDS.union( s.getExplainSubOrInv( pred ).getExplain(), true );
               
        applyAllValues( subj, s, obj, c, finalDS );

        if( s.isTransitive() ) {
          ATermAppl allRC = ATermUtils.makeAllValues( s.getName(), c );
          finalDS = ds.union( subj.getDepends( av ), strategy.getABox().doExplanation() );
          if( strategy.getABox().doExplanation() )
            finalDS = finalDS.unions.getExplainTransitive().getExplain(), true );
         
          applyAllValues( subj, s, obj, allRC, finalDS );
        }
      }
View Full Code Here

  public void apply(Individual ind) {
    Set<Literal> nodes = new HashSet<Literal>();
    LinkedList<Literal> pending = new LinkedList<Literal>();
    Map<Literal, Set<Literal>> ne = new HashMap<Literal, Set<Literal>>();
    DependencySet ds = DependencySet.EMPTY;
    boolean nePresent = false;
    for( Iterator<Edge> it = ind.getOutEdges().iterator(); it.hasNext(); ) {
      final Edge e = it.next();
      final Role r = e.getRole();
      if( !r.isDatatypeRole() )
        continue;

      ds = ds.union( e.getDepends(), strategy.getABox().doExplanation() );

      final Literal l = (Literal) e.getTo();
      pending.add( l );

      Set<Literal> disj = ne.get( l );

      for( Role s : r.getDisjointRoles() ) {
        for( Edge f : ind.getOutEdges().getEdges( s ) ) {
          final Literal k = (Literal) f.getTo();
          if( disj == null ) {
            disj = new HashSet<Literal>();
            ne.put( l, disj );
            nePresent = true;
          }
          disj.add( k );
        }
      }
    }
   
    while (!pending.isEmpty()) {
      final Literal l = pending.removeFirst();
      if( !nodes.add( l ) )
        continue;

      Set<Literal> disj = ne.get( l );

      for( Node n : l.getDifferents() ) {
        if( n.isLiteral() ) {
          final Literal k = (Literal) n;
          pending.add( k );
          if( disj == null ) {
            disj = new HashSet<Literal>();
            ne.put( l, disj );
            nePresent = true;
          }
          disj.add( k );
          ds = ds.union( l.getDifferenceDependency( n ), strategy.getABox().doExplanation() );
        }
        else {
          throw new IllegalStateException();
        }
      }
    }

    /*
     * This satisfiability check is only needed if an inequality is present
     * because if no inequalities are present, the check is a repetition of
     * the satisfiability check performed during Literal.addType
     * (checkClash)
     */
    if( nePresent ) {
      try {
        if( !strategy.getABox().getDatatypeReasoner().isSatisfiable( nodes, ne ) ) {
          for( Node n : nodes ) {
            for( DependencySet typeDep : n.getDepends().values() )
              ds = ds.union( typeDep, strategy.getABox().doExplanation() );
          }
          /*
           * TODO: More descriptive clash
           */
          strategy.getABox().setClash( Clash.unexplained( ind, ds ) );
        }
      } catch( InvalidLiteralException e ) {
        final String msg = "Invalid literal encountered during satisfiability check: "
            + e.getMessage();
        if( PelletOptions.INVALID_LITERAL_AS_INCONSISTENCY ) {
          log.fine( msg );
          for( Node n : nodes ) {
            for( DependencySet typeDep : n.getDepends().values() )
              ds = ds.union( typeDep, strategy.getABox().doExplanation() );
          }
          strategy.getABox().setClash( Clash.invalidLiteral( ind, ds ) );
        }
        else {
          log.severe( msg );
View Full Code Here

        // FIXME make sure all neighbors are safe
        if( x.hasDistinctRNeighborsForMin( r, n, c ) )
            return;

        DependencySet ds = x.getDepends( mc );
       
        if(!PelletOptions.MAINTAIN_COMPLETION_QUEUE && ds == null)
      return;


        if( log.isLoggable( Level.FINE ) )
            log.fine( "MIN : " + x + " -> " + r + " -> anon"
                + (n == 1 ? "" : (strategy.getABox().getAnonCount() + 1) + " - anon") + (strategy.getABox().getAnonCount() + n) + " "
                + ATermUtils.toString( c ) + " " + ds );

        Node[] y = new Node[n];
        for( int c1 = 0; c1 < n; c1++ ) {
          strategy.checkTimer();
            if( r.isDatatypeRole() )
                y[c1] = strategy.getABox().addLiteral( ds );
            else {
                y[c1] = strategy.createFreshIndividual( x, ds );
            }
            Node succ = y[c1];
            DependencySet finalDS = ds;

            strategy.addEdge( x, r, succ, ds );
            if( succ.isPruned() ) {
                finalDS = finalDS.union( succ.getMergeDependency( true ), strategy.getABox().doExplanation() );
                succ = succ.getMergedTo();
            }

            strategy.addType( succ, c, finalDS );
            for( int c2 = 0; c2 < c1; c2++ )
View Full Code Here

        Role r = strategy.getABox().getRole( max.getArgument( 0 ) );
        int n = ((ATermInt) max.getArgument( 1 )).getInt() - 1;
        ATermAppl c = (ATermAppl) max.getArgument( 2 );

        DependencySet ds = x.getDepends( mc );

        if(!PelletOptions.MAINTAIN_COMPLETION_QUEUE && ds == null)
            return;
           
       
        if( n == 1 ) {
            applyFunctionalMaxRule( x, r, c, ds );
            if( strategy.getABox().isClosed() )
                return;
        }
        else {
            boolean hasMore = true;
           
            while( hasMore ) {
                hasMore = applyMaxRule( x, r, c, n, ds );

                if( strategy.getABox().isClosed() )
                    return;

                if( x.isMerged() ) {
                    return;
                }

                if( hasMore ) {
                    // subsequent merges depend on the previous merge
                    ds = ds.union( new DependencySet( strategy.getABox().getBranches().size() ), strategy.getABox().doExplanation() );
                }
            }
        }  
    }
View Full Code Here

        // dependency and return
        if( k == 0 && n > 0 ) {
            for( int e = 0; e < edges.size(); e++ ) {
                Edge edge = edges.edgeAt( e );
                Node neighbor = edge.getNeighbor( x );
                DependencySet typeDS = neighbor.getDepends( c );
                if( typeDS != null ) {
                  Role edgeRole = edge.getRole();
            DependencySet subDS = r.getExplainSubOrInv( edgeRole );
          ds = ds.union( subDS, strategy.getABox().doExplanation() );
                  ds = ds.union( edge.getDepends(), strategy.getABox().doExplanation() );
                  ds = ds.union( typeDS, strategy.getABox().doExplanation() );
                 
                }
            }

            strategy.getABox().setClash( Clash.maxCardinality( x, ds, r.getName(), 0 ) );
            return false;
        }

        // if there are less than n neighbors than max rule won't be triggered
        // return false because no more merge required for this role
        if( n <= k )
            return false;       
       
        // create the pairs to be merged
        List<NodeMerge> mergePairs = new ArrayList<NodeMerge>();
        DependencySet differenceDS = findMergeNodes( neighbors, x, mergePairs );
        ds = ds.union( differenceDS, strategy.getABox().doExplanation() );

        // if no pairs were found, i.e. all were defined to be different from
        // each other, then it means this max cardinality restriction is
        // violated. dependency of this clash is on all the neighbors plus the
        // dependency of the restriction type
        if( mergePairs.size() == 0 ) {
            DependencySet dsEdges = x.hasDistinctRNeighborsForMax( r, k + 1, c );
            if( dsEdges == null ) {
              if( log.isLoggable( Level.FINE ) )
                  log.fine( "Cannot determine the exact clash dependency for " + x );
                strategy.getABox().setClash( Clash.maxCardinality( x, ds ) );
                return false;
View Full Code Here

        return n > k + 1;
    }
   

    DependencySet findMergeNodes( Set<Node> neighbors, Individual node, List<NodeMerge> pairs ) {
        DependencySet ds = DependencySet.INDEPENDENT;

        List<Node> nodes = new ArrayList<Node>( neighbors );
        for( int i = 0; i < nodes.size(); i++ ) {
            Node y = nodes.get( i );
            for( int j = i + 1; j < nodes.size(); j++ ) {
                Node x = nodes.get( j );

                if( y.isDifferent( x ) ) {
                  ds = ds.union( y.getDifferenceDependency( x ), strategy.getABox().doExplanation() );
                    continue;
                }

                // 1. if x is a nominal node (of lower level), then Merge(y, x)
                if( x.getNominalLevel() < y.getNominalLevel() )
View Full Code Here

  private void restoreBranchAdd(ATermAppl assertion, BranchAddDependency branch) {
    if( DependencyIndex.log.isLoggable( Level.FINE ) )
      DependencyIndex.log.fine( "    Removing branch add? " + branch.getBranch() );
 
    // get merge dependency
    DependencySet ds = branch.getBranch().getTermDepends();
 
    // remove the dependency
    ds.removeExplain( assertion );
 
    // undo merge if empty
    if( ds.getExplain().isEmpty() ) {
      if( DependencyIndex.log.isLoggable( Level.FINE ) )
        DependencyIndex.log.fine( "           Actually removing branch!" );
 
      Collection<ATermAppl> allEffects = PelletOptions.TRACK_BRANCH_EFFECTS
        ? kb.getABox().getBranchEffectTracker().getAll( branch.getBranch().getBranch() )
        : kb.getABox().getNodeNames();
 
      List<IntSet> updatedList = new ArrayList<IntSet>();
 
      for( ATermAppl a : allEffects ) {
 
        // get the actual node
        Node node = kb.getABox().getNode( a );
 
        // update type dependencies
        Map<ATermAppl,DependencySet> types = node.getDepends();
 
        for( Entry<ATermAppl,DependencySet> entry : types.entrySet() ) {
          // get ds for type
          DependencySet tDS = entry.getValue();
 
          // DependencySet.copy() does not create a new bitset object,
          // so we need to track which bitsets have been
          // updated, so we do not process the same bitset multiple
          // times
          boolean exit = false;
          for( int i = 0; i < updatedList.size(); i++ ) {
            if( updatedList.get( i ) == tDS.getDepends() )
              exit = true;
          }
 
          if( exit )
            continue;
 
          updatedList.add( tDS.getDepends() );
 
          // update branch if necessary
          if( tDS.getBranch() > branch.getBranch().getBranch() ) {
            tDS = tDS.copy( tDS.getBranch() - 1 );
          }
 
          for( int i = branch.getBranch().getBranch(); i <= kb.getABox().getBranches().size(); i++ ) {
            // update dependency set
            if( tDS.contains( i ) ) {
              tDS.remove( i );
              tDS.add( i - 1 );
            }
          }
         
          entry.setValue( tDS );
        }
 
        // update edge depdencies
        EdgeList edges = node.getInEdges();
        for( Edge edge: edges ) {
          DependencySet tDS = edge.getDepends();
 
          // DependencySet.copy() does not create a new bitset object,
          // so we need to track which bitsets have been
          // updated, so we do not process the same bitset multiple
          // times
          boolean exit = false;
          for( int i = 0; i < updatedList.size(); i++ ) {
            if( updatedList.get( i ) == tDS.getDepends() )
              exit = true;
          }
 
          if( exit )
            continue;
 
          updatedList.add( tDS.getDepends() );
 
          // update branch if necessary
          if( tDS.getBranch() > branch.getBranch().getBranch() )
            tDS = tDS.copy( edge.getDepends().getBranch() - 1 );
 
          for( int i = branch.getBranch().getBranch(); i <= kb.getABox().getBranches().size(); i++ ) {
            // update dependency set
            if( tDS.contains( i ) ) {
              tDS.remove( i );
              tDS.add( i - 1 );
            }
          }
         
          edge.setDepends( tDS );
        }
 
        // //TODO:The following code update outedges as well - after
        // testing is seems that this is un-necessary
        // if(node instanceof Individual){
        // Individual ind = (Individual)node;
        //         
        // //update edge depdencies
        // //update type dependencies
        // edges = ind.getInEdges();
        // for(Iterator eIt = edges.iterator(); eIt.hasNext();){
        // //get next type
        // Edge edge = (Edge)eIt.next();
        //           
        // //update branch if necessary
        // if(edge.getDepends().branch > branch.getBranch().branch)
        // edge.getDepends().branch--;
        //
        // for(int i = branch.getBranch().branch; i <=
        // kb.getABox().getBranches().size(); i++){
        // //update dependency set
        // if(edge.getDepends().contains(i)){
        // edge.getDepends().remove(i);
        // edge.getDepends().add(i-1);
        // }
        // }
        // }
        // }
      }
 
      if( PelletOptions.TRACK_BRANCH_EFFECTS )
        kb.getABox().getBranchEffectTracker().remove( branch.getBranch().getBranch() + 1 );
 
      // !!!!!!!!!!!!!!!! Next update kb.getABox() branches !!!!!!!!!!!!!!
      // remove the branch from branches
      List<Branch> branches = kb.getABox().getBranches();
 
      // decrease branch id for each branch after the branch we're
      // removing
      // also need to change the dependency set for each label
      for( int i = branch.getBranch().getBranch(); i < branches.size(); i++ ) {
        // cast for ease
        Branch br = branches.get( i );
       
        DependencySet tDS = br.getTermDepends();
       
        // update the term depends in the branch
        if( tDS.getBranch() > branch.getBranch().getBranch() )
          tDS = tDS.copy( tDS.getBranch() - 1 );
 
        for( int j = branch.getBranch().getBranch(); j < kb.getABox().getBranches().size(); j++ ) {
          if( tDS.contains( j ) ) {
            tDS.remove( j );
            tDS.add( j - 1 );
          }
        }
 
        // also need to decrement the branch number
        br.setBranch( br.getBranch() - 1 );
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.DependencySet

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.