Package org.mindswap.pellet

Examples of org.mindswap.pellet.Edge


        // (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;
                                    edge = edges.edgeAt( 0 );
View Full Code Here


          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 );
          }
         
          applyAllValues( x, r, y, allRC, finalDS );

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

    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 );
          throw new InternalReasonerException( msg, e );
        }
      } catch( DatatypeReasonerException e ) {
        final String msg = "Unexpected datatype reasoner exception: " + e.getMessage();
        log.severe( msg );
        throw new InternalReasonerException( msg, e );
      }
    }
  }
View Full Code Here

        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
                    .getDepends( maxCard ) );
                strategy.addBranch( newBranch );
View Full Code Here

        // 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 );
          ds = ds.union( subDS, strategy.getABox().doExplanation() );
                  ds = ds.union( edge.getDepends(), strategy.getABox().doExplanation() );
                  ds = ds.union( typeDS, strategy.getABox().doExplanation() );
                 
                }
            }
View Full Code Here

            // 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;

                // it is possible that there are multiple edges to the same
                // node, e.g. property p and its super property, so check if
                // we already merged this one
                if( head.isSame( next ) )
                    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( next.getDepends( c ), strategy.getABox().doExplanation() );
                ds = ds.union( r.getExplainSubOrInv( edge.getRole() ), strategy.getABox().doExplanation() );

                if( next.isDifferent( head ) ) {
                    ds = ds.union( head.getDepends( c ), strategy.getABox().doExplanation() );
                    ds = ds.union( next.getDepends( c ), strategy.getABox().doExplanation() );
                    ds = ds.union( next.getDifferenceDependency( head ), strategy.getABox().doExplanation() );
View Full Code Here

    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
        ds.removeExplain( assertion );
 
        // remove if the dependency set is empty
View Full Code Here

          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 );
            else if(y.isIndividual()) {
                ATermAppl allRC = ATermUtils.makeAllValues( roleChain, c );
View Full Code Here

         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 );

                 if( x.isMerged() || strategy.getABox().isClosed() )
                     return false;
View Full Code Here

   
    //copy edge depenedencies
    for (Edge next : edges) {
     
      //create new edge
      Edge newEdge = new DefaultEdge(next.getRole(), next.getFrom(), next.getTo(), next.getDepends());
     
      //add to edge list
      newEntry.edges.add(newEdge);
    }
   
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.Edge

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.