Package org.mindswap.pellet

Examples of org.mindswap.pellet.Node


        // (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 {
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 );
          }
View Full Code Here

            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++ )
                succ.setDifferent( y[c2], finalDS );
        }
    }
View Full Code Here

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

                newBranch.tryNext();
View Full Code Here

        // 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() );
View Full Code Here

    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() )
                    pairs.add( new NodeMerge( y, x ) );
                // 2. if y is a nominal node or an ancestor of x, then Merge(x, y)
                else if( y.isNominal() )
                    pairs.add( new NodeMerge( x, y ) );
                // 3. if y is an ancestor of x, then Merge(x, y)
View Full Code Here

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

                // 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() );
                    if( r.isFunctional() )
                        strategy.getABox().setClash( Clash.functionalCardinality( x, ds, r.getName() ) );
                    else
                        strategy.getABox().setClash( Clash.maxCardinality( x, ds, r.getName(), 1 ) );

                    break;
                }

                if( x.isNominal() && head.isBlockable() && next.isBlockable()
                    && head.hasSuccessor( x ) && next.hasSuccessor( x ) ) {
                    Individual newNominal = strategy.createFreshIndividual( null, ds );

                    strategy.addEdge( x, r, newNominal, ds );

                    continue LOOP;
                }
                // always merge to a nominal (of lowest level) or an ancestor
                else if( (next.getNominalLevel() < head.getNominalLevel())
                    || (!head.isNominal() && next.hasSuccessor( x )) ) {
                    Node temp = head;
                    head = next;
                    next = temp;
                }

                if( log.isLoggable( Level.FINE ) )
View Full Code Here

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

    if( theEdge == null )
      return;
 
    // get the object
    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
        ds.removeExplain( assertion );
 
        // remove if the dependency set is empty
        if( ds.getExplain().isEmpty() ) {
          final IncrementalChangeTracker tracker = kb.getABox().getIncrementalChangeTracker();
          // need to check if the
 
          subj.removeEdge( edge );
          obj.removeInEdge( edge );
 
          // update the removed set of edges
          tracker.addDeletedEdge( edge );
 
          // add to updated individuals
View Full Code Here

    if( ds.getExplain().isEmpty() ) {
      if( DependencyIndex.log.isLoggable( Level.FINE ) )
        DependencyIndex.log.fine( "           Actually removing merge!" );
 
      // get nodes
      Node ind = kb.getABox().getNode( merge.getInd() );
      Node mergedToInd = kb.getABox().getNode( merge.getmergedIntoInd() );
 
      // check that they are actually the same - else throw error
      if( !ind.isSame( mergedToInd ) )
        throw new InternalReasonerException( " Restore merge error: " + ind
            + " not same as " + mergedToInd );
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.Node

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.