Package org.mindswap.pellet

Examples of org.mindswap.pellet.EdgeList


    // FIXME instead of doing the following check set a flag when the edge is added
    // check that x has to have at least one r neighbor y
    // which is blockable and has successor x
    // (so y is an inv(r) predecessor of x)
    boolean apply = false;
    EdgeList edges = x.getRPredecessorEdges(r.getInverse());
    for (int e = 0; e < edges.size(); e++) {
      Edge edge = edges.edgeAt(e);
      Individual pred = edge.getFrom();
      if (pred.isBlockable()) {
        apply = true;
        break;
      }
    }
    if (!apply)
      return;

    if (x.getMaxCard(r) < n)
      return;

    if (x.hasDistinctRNeighborsForMin(r, n, ATermUtils.TOP, true))
      return;

    // if( n == 1 ) {
    // throw new InternalReasonerException(
    // "Functional rule should have been applied " +
    // x + " " + x.isNominal() + " " + edges);
    // }

    int guessMin = x.getMinCard(r, c);
    if (guessMin == 0)
      guessMin = 1;

    // TODO not clear what the correct ds is so be pessimistic and include everything
    DependencySet ds = x.getDepends(mc);
    edges = x.getRNeighborEdges(r);
    for (int e = 0; e < edges.size(); e++) {
      Edge edge = edges.edgeAt(e);
      ds = ds.union(edge.getDepends(), strategy.getABox().doExplanation());
    }

    GuessBranch newBranch = new GuessBranch(strategy.getABox(), strategy, x, r, guessMin, n, c, ds);
    strategy.addBranch(newBranch);
View Full Code Here


        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;
                                    edge = edges.edgeAt( 0 );
                                    y = edge.getNeighbor( x );
                                }
                            }
                        }
                        if( y != null )
View Full Code Here

    if ( s.isTop() && s.isObjectRole() ) {
          applyAllValuesTop( av, c, ds );
          return;
        }
   
    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 );
View Full Code Here

            return;
       
        if(!PelletOptions.MAINTAIN_COMPLETION_QUEUE && x.getDepends(maxCard) == null)
          return;

        EdgeList edges = x.getRNeighborEdges( r );
        for( Iterator<Edge> i = edges.iterator(); i.hasNext(); ) {
            Edge edge = i.next();
            Node neighbor = edge.getNeighbor( x );

            if( !neighbor.hasType( c ) && !neighbor.hasType( ATermUtils.negate( c ) ) ) {
                ChooseBranch newBranch = new ChooseBranch( strategy.getABox(), strategy, neighbor, c, x
View Full Code Here

     *
     * @return true if more merges are required for this maxCardinality
     */
    protected boolean applyMaxRule( Individual x, Role r, ATermAppl c, int k, DependencySet ds ) {

        EdgeList edges = x.getRNeighborEdges( r );
        // find all distinct R-neighbors of x
        Set<Node> neighbors = edges.getFilteredNeighbors( x, c );

        int n = neighbors.size();

        // if( log.isLoggable( Level.FINE ) )
        // log.fine( "Neighbors: " + n + " maxCardinality: " + k);

        // if restriction was maxCardinality 0 then having any R-neighbor
        // violates the restriction. no merge can fix this. compute the
        // 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 );
View Full Code Here

            if (PelletOptions.USE_TRACING) {
              ds = ds.union( s.getExplainSuper(r.getName()), strategy.getABox().doExplanation() ).union( r.getExplainFunctional(), strategy.getABox().doExplanation() );
            }
           
            EdgeList edges = x.getRNeighborEdges( r );

            // if there is not more than one edge then func max rule won't be triggered
            if( edges.size() <= 1 )
                continue;

            // find all distinct R-neighbors of x
            Set<Node> neighbors = edges.getFilteredNeighbors( x, c );

            // if there is not more than one neighbor then func max rule won't be triggered
            if( neighbors.size() <= 1 )
                continue;

            Node head = null;

            int edgeIndex = 0;
            int edgeCount = edges.size();

            // find the head and its corresponding dependency information.
            // since head is not necessarily the first element in the
            // neighbor list we need to first find the un-pruned node
            for( ; edgeIndex < edgeCount; edgeIndex++ ) {
                Edge edge = edges.edgeAt( edgeIndex );
                head = edge.getNeighbor( x );

                if( head.isPruned() || !neighbors.contains( head ) )
                    continue;

                // this node is included in the merge list because the edge
                // exists and the node has the qualification in its types
                ds = ds.union( edge.getDepends(), strategy.getABox().doExplanation() );
                ds = ds.union( head.getDepends( c ), strategy.getABox().doExplanation() );
                ds = ds.union( r.getExplainSubOrInv( edge.getRole() ), strategy.getABox().doExplanation() );
                break;
            }

            // now iterate through the rest of the elements in the neighbors
            // and merge them to the head node. it is possible that we will
            // switch the head at some point because of merging rules such
            // that you always merge to a nominal of higher level
            for( edgeIndex++; edgeIndex < edgeCount; edgeIndex++ ) {
                Edge edge = edges.edgeAt( edgeIndex );
                Node next = edge.getNeighbor( x );

                if( next.isPruned() || !neighbors.contains( next ) )
                    continue;
View Full Code Here

         
          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
View Full Code Here

    Individual subj = kb.getABox().getIndividual( theEdge.getFrom().getName() );
    Node obj = kb.getABox().getNode( theEdge.getTo().getName() );
    Role role = kb.getRole( theEdge.getRole().getName() );
 
    // loop over all edges for the subject
    EdgeList edges = subj.getEdgesTo( obj, role );
    for( int i = 0; i < edges.size(); i++ ) {
      Edge edge = edges.edgeAt( i );
      if( edge.getRole().equals( role ) ) {
        // get dependency set for the edge
        DependencySet ds = edge.getDepends();
 
        // clean it
View Full Code Here

        if ( s.isTop() && s.isObjectRole() ) {
          applyAllValuesTop( av, c, ds );
          return;
        }

        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( roleChain.isEmpty() )
                applyAllValues( x, s, y, c, finalDS );
View Full Code Here

    }

    protected boolean applyAllValuesPropertyChain( Individual x, ATermList chain, ATermAppl c, DependencySet ds ) {
         Role r = strategy.getABox().getRole( chain.getFirst() );
        
         EdgeList edges = x.getRNeighborEdges( r );
         if( !edges.isEmpty() ) {
             ATermAppl allRC = ATermUtils.makeAllValues( chain.getNext(), c );

             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() );
                
                 applyAllValues( x, r, y, allRC, finalDS );
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.EdgeList

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.