Package org.mindswap.pellet

Examples of org.mindswap.pellet.Node


    for( Edge se : src.deletedEdges ) {
      final Individual s = target.getIndividual( se.getFrom().getName() );
      if( s == null )
        throw new NullPointerException();
      final Node o = target.getNode( se.getTo().getName() );
      if( o == null )
        throw new NullPointerException();

      this.newEdges.add( new DefaultEdge( se.getRole(), s, o, se.getDepends() ) );
    }

    this.deletedTypes = new HashMap<Node, Set<ATermAppl>>( src.deletedTypes.size() );

    for( Map.Entry<Node, Set<ATermAppl>> e : src.deletedTypes.entrySet() ) {
      final Node n = target.getNode( e.getKey().getName() );
      if( n == null )
        throw new NullPointerException();
      this.deletedTypes.put( n, new HashSet<ATermAppl>( e.getValue() ) );
    }

    this.newEdges = new HashSet<Edge>( src.newEdges.size() );

    for( Edge se : src.newEdges ) {
      final Individual s = target.getIndividual( se.getFrom().getName() );
      if( s == null )
        throw new NullPointerException();
      final Node o = target.getNode( se.getTo().getName() );
      if( o == null )
        throw new NullPointerException();

      this.newEdges.add( new DefaultEdge( se.getRole(), s, o, se.getDepends() ) );
    }

    this.newIndividuals = new HashSet<Individual>( src.newIndividuals.size() );

    for( Individual si : src.newIndividuals ) {
      final Individual ti = target.getIndividual( si.getName() );
      if( ti == null )
        throw new NullPointerException();

      this.newIndividuals.add( ti );
    }

    this.unprunedNodes = new HashSet<Node>( src.unprunedNodes.size() );

    for( Node sn : src.unprunedNodes ) {
      final Node tn = target.getNode( sn.getName() );
      if( tn == null )
        throw new NullPointerException();

      this.unprunedNodes.add( tn );
    }
View Full Code Here


    if( negated ) {
      ATermAppl cls = all( p, not( value( o ) ) );
      strategy.addType( node1, cls, ds );
    }
    else {
      Node node2 = abox.getNode( o );
      if (node2.isMerged()) {
        edgeDS = node2.getMergeDependency(true);
        node2 = node2.getSame();
      }   
      strategy.addEdge( node1, abox.getRole( p ), node2, edgeDS );
    }
  }
View Full Code Here

    this.iterator = iterator;
  }
 
  public boolean hasNext() {
    while ( ( next == null ) && iterator.hasNext() ) {
      Node node = iterator.next();
      if ( node.isLiteral() && node.isRootNominal() )
        next = ( Literal ) node;
    }
    return next != null;
  }
View Full Code Here

    //process new edges
    for(Iterator<Edge> it = getNewEdgeIterator(); it.hasNext();){
      Edge edge = it.next();
     
      Individual subj = edge.getFrom();
      Node obj = edge.getTo();
      if(subj.isMerged())
        subj.getSame();
      if(subj.isPruned())
        continue;

      if(obj.isMerged())
        obj.getSame();
      if(obj.isPruned())
        continue;

      Role pred = edge.getRole();       
      DependencySet ds = edge.getDepends();

      applyDomainRange(subj, pred, obj, ds);
      if (subj.isPruned() || obj.isPruned()) {
        return;
      }
      applyFunctionality(subj, pred, obj);
      if (subj.isPruned() || obj.isPruned()) {
        return;
      }

      if (pred.isObjectRole()) {
        Individual o = (Individual) obj;
        checkReflexivitySymmetry(subj, pred, o, ds);
        checkReflexivitySymmetry(o, pred.getInverse(), subj, ds);
      }
     
      //if the KB has cardinality restrictions, then we need to apply the guessing rule
          if(abox.getKB().getExpressivity().hasCardinality()){
            //update the queue so the max rule will be fired
              updateQueueAddEdge(subj, pred, obj);
          }
    }
   
    
    //merge again if necessary
    if (!mergeList.isEmpty())
      mergeAll();
   
    //set appropriate branch
    abox.setBranch(abox.getBranches().size() + 1);

    // we will also need to add stuff to the queue in the event of a
    // deletion   
     
    //Handle removed edges
    Iterator<Edge> i = getRemovedEdgeIterator();
    while( i.hasNext() ){       
      Edge e = i.next();
      Individual subj = e.getFrom();
      Node obj = e.getTo();
     
      subj = subj.getSame();
     
      subj.applyNext[Node.SOME] = 0;
      subj.applyNext[Node.MIN] = 0;
      QueueElement qe = new QueueElement( subj );
      abox.getCompletionQueue().add( qe, NodeSelector.EXISTENTIAL );
      abox.getCompletionQueue().add( qe, NodeSelector.MIN_NUMBER );
     
     
      obj = obj.getSame();
      if(obj instanceof Individual){
        Individual objInd = (Individual)obj;
        objInd.applyNext[Node.SOME] = 0;
        objInd.applyNext[Node.MIN] = 0;
        qe = new QueueElement( objInd );
        abox.getCompletionQueue().add( qe, NodeSelector.EXISTENTIAL );
        abox.getCompletionQueue().add( qe, NodeSelector.MIN_NUMBER );
      }               
    }

   
   
   
    //Handle removed types
    Iterator<Map.Entry<Node,Set<ATermAppl>>> it = getRemovedTypeIterator();
    while( it.hasNext() ){
      Node node = it.next().getKey();
     
      if( node.isIndividual() ){
        Individual ind = (Individual)node;

        //readd the conjunctions
        readdConjunctions( ind );
       
        //it could be the case that the type can be added from unfolding, a forAll application on a self loop, or the disjunction rule
        ind.applyNext[Node.ATOM] = 0;
        ind.applyNext[Node.ALL] = 0;
        ind.applyNext[Node.OR] = 0;

        QueueElement qe = new QueueElement( ind );
        abox.getCompletionQueue().add( qe, NodeSelector.ATOM );
        abox.getCompletionQueue().add( qe, NodeSelector.DISJUNCTION );

        //fire the all rule as the is no explicit call to it
        allValuesRule.apply( ind );
       
        //get out edges and check domains, some values and min values
        for( int j = 0; j < ind.getOutEdges().size(); j++ ){
          Edge e = ind.getOutEdges().edgeAt( j );
                       
          if( e.getFrom().isPruned() || e.getTo().isPruned() )
            continue;
                       
              Role pred = e.getRole();
              Node obj = e.getTo();
              DependencySet ds = e.getDepends();
         
              for( ATermAppl domain : pred.getDomains() ) {             
                if( requiredAddType( ind, domain ) ) {
              if( !PelletOptions.USE_TRACING )
                addType( ind, domain, ds.union( DependencySet.EMPTY, abox.doExplanation() ) );
              else        
                addType( ind, domain, ds.union( pred.getExplainDomain( domain ), abox.doExplanation() ) );
                }
              }

              //it could be the case that this label prevented the firing of the all values, some, or min rules of the neighbor
          if( obj instanceof Individual ){
            Individual objInd = (Individual)obj;
            objInd.applyNext[Node.ALL] = 0;
            objInd.applyNext[Node.SOME] = 0;
            objInd.applyNext[Node.MIN] = 0;
            QueueElement qeObj = new QueueElement( objInd );
            abox.getCompletionQueue().add( qeObj, NodeSelector.EXISTENTIAL );
            abox.getCompletionQueue().add( qeObj, NodeSelector.MIN_NUMBER );
           
            //apply the all values rule
            allValuesRule.apply( ind );
          }
        }
      }
       
     
      //get out edges
      for( int j = 0; j < node.getInEdges().size(); j++ ){
        Edge e = node.getInEdges().edgeAt( j );
                     
        if( e.getFrom().isPruned() || e.getTo().isPruned() )
          continue;
       
        Individual subj = e.getFrom();
              Role pred = e.getRole();              
              DependencySet ds = e.getDepends();
       
            for( ATermAppl range : pred.getRanges() ) {
              if( requiredAddType( node, range ) ) {
            if( !PelletOptions.USE_TRACING )
              addType( node, range, ds.union( DependencySet.EMPTY, abox.doExplanation() ) );
            else        
              addType( node, range, ds.union( pred.getExplainRange( range ), abox.doExplanation() ) );
              }
            }

            //it could be the case that this label prevented the firing of the all values, some, or min rules of the neighbor
        subj.applyNext[Node.ALL] = 0;
        subj.applyNext[Node.SOME] = 0;
        subj.applyNext[Node.MIN] = 0;
        QueueElement qe = new QueueElement( subj );
        abox.getCompletionQueue().add( qe, NodeSelector.EXISTENTIAL );
        abox.getCompletionQueue().add( qe, NodeSelector.MIN_NUMBER );

        allValuesRule.apply( subj );
      }
    }
   
   
    //due to unmerging nodes, edges can actually be added
    i = getNewEdgeIterator();
    while( i.hasNext() ){       
      applyPropertyRestrictions( i.next() );       
    }
   
   
    //due to unmerging any node that was pruned could need rules applied to it. This is because these rules
    //would have been originally applied to the node that the pruned node was merged into. 
    for(Iterator<Node> nodeIt = getUnPrunedIterator(); nodeIt.hasNext(); ) {
      Node n = nodeIt.next();
     
      if( n.isIndividual() ) {
        Individual ind = (Individual) n;
       
        //reset type pointers
        for( int j = 0; j < Node.TYPES; j++ )
          ind.applyNext[j] = 0;
       
        //add to all queues
        abox.getCompletionQueue().add( new QueueElement( ind ) );
       
        allValuesRule.apply( ind );
       
        //get out edges
        for( int j = 0; j < ind.getOutEdges().size(); j++ ){
          Edge e = ind.getOutEdges().edgeAt( j );
                       
          if( !e.getFrom().isPruned() && !e.getTo().isPruned() )
            applyPropertyRestrictions( e );
         
          Node obj = e.getTo();
          if( obj instanceof Individual ){
            Individual objInd = (Individual)obj;
            objInd.applyNext[Node.ALL] = 0;
            allValuesRule.apply( objInd );
          }
View Full Code Here

    for( Iterator<Map.Entry<Node, Set<ATermAppl>>> it = tracker.deletedTypes(); it
        .hasNext(); ) {

      Map.Entry<Node, Set<ATermAppl>> entry = it.next();
      Node node = entry.getKey();
      Set<ATermAppl> types = entry.getValue();
     
      // find the edges which the all values rule needs to be
      // re-applied to
      EdgeList av = findAllValues( node, types );
     
      //apply the all values rules
      for(int i = 0; i < av.size(); i++){
        Edge e = av.edgeAt( i );           
        allValuesRule.applyAllValues( e.getFrom(), e.getRole(), e.getTo(), e.getDepends() );
      }
    }
   
    for( Iterator<Node> i = tracker.unprunedNodes(); i.hasNext(); ) {
      Node node = i.next();
     
      if( node instanceof Individual ){
        Individual ind = (Individual)node;
        //reset type pointers
        for( int j = 0; j < Node.TYPES; j++ )
          ind.applyNext[j] = 0;
       
        //add to all queues
        abox.getCompletionQueue().add( new QueueElement( ind ) );
       
        allValuesRule.apply( ind );
       
        //get out edges
        for( int j = 0; j < ind.getOutEdges().size(); j++ ){
          Edge e = ind.getOutEdges().edgeAt( j );
         
          Node obj = e.getTo();
          if( obj instanceof Individual ){
            Individual objInd = (Individual)obj;
            objInd.applyNext[Node.ALL] = 0;
            allValuesRule.apply( objInd );
          }
View Full Code Here

      Individual ind = (Individual)node;     
     
      //handle in edges
      for(int i = 0; i < ind.getOutEdges().size(); i++){
        Edge e = ind.getOutEdges().edgeAt( i );
        Node to = e.getTo();
       
        Role inv = e.getRole().getInverse();
       
        if(inv != null && to instanceof Individual)
          edges.addEdgeList( findAllValues( ind, (Individual)to, removedTypes, new DefaultEdge( inv, (Individual)to, ind, e.getDepends() ) ) ) ;
View Full Code Here

    mayNeedExpanding.remove( 0 );

    EdgeList sortedSuccessors = x.getOutEdges().sort();
    if( PelletOptions.SEARCH_TYPE == PelletOptions.DEPTH_FIRST ) {
      for( Edge edge : sortedSuccessors ) {
        Node succ = edge.getTo();
        if( !succ.isLiteral() && !succ.equals( x ) ) {
          mayNeedExpanding.add( (Individual) succ );
        }
      }
    }
    else {
      for( int i = sortedSuccessors.size() - 1; i >= 0; i-- ) {
        Edge edge = sortedSuccessors.edgeAt( i );
        Node succ = edge.getTo();
        if( !succ.isLiteral() && !succ.equals( x ) ) {
          mayNeedExpanding.add( (Individual) succ );
        }
      }
    }
  }
View Full Code Here

  public void restore(Branch br) {
     Timer timer = timers.startTimer("restore");

    abox.stats.globalRestores++;
   
    Node clashNode = abox.getClash().getNode();
    List<ATermAppl> clashPath = clashNode.getPath();
    clashPath.add( clashNode.getName() );

    abox.setBranch( br.getBranch() );
    abox.setClash( null );
        // Setting the anonCount to the value at the time of branch creation is incorrect
        // when SMART_RESTORE option is turned on. If we create an anon node after branch
        // creation but node depends on an earlier branch restore operation will not remove
        // the node. But setting anonCount to a smaller number may mean the anonCount will
        // be incremented to that value and creating a fresh anon node will actually reuse
        // the not-removed node. The only advantage of setting anonCount to a smaller value
        // is to keep the name of anon nodes smaller to make debugging easier. For this reason,
        // the above line is not removed and under special circumstances may be uncommented
        // to help debugging only with the intent that it will be commented again after
        // debugging is complete 
    // abox.setAnonCount( br.getAnonCount() );

    mergeList.clear();

    List<ATermAppl> nodeList = abox.getNodeNames();

    if( log.isLoggable( Level.FINE ) ) {
      log.fine( "RESTORE: Branch " + br.getBranch() );
      if( br.getNodeCount() < nodeList.size() )
        log.fine( "Remove nodes " + nodeList.subList( br.getNodeCount(), nodeList.size() ) );
    }
    for( int i = 0; i < nodeList.size(); i++ ) {
      ATermAppl x = nodeList.get( i );

      Node node = abox.getNode( x );
      if( i >= br.getNodeCount() ) {
        abox.removeNode( x );
        ATermAppl c = cachedNodes.remove( node );
        if( c != null && PelletOptions.USE_ADVANCED_CACHING ) {
          if( clashPath.contains( x ) ) {
            if( log.isLoggable( Level.FINEST ) )
              log.finest( "+++ Cache unsat concept " + c );
            abox.getCache().putSat( c, false );
          }
          else if( log.isLoggable( Level.FINEST ) )
            log.finest( "--- Do not cache concept " + c + " " + x + " "
                + clashNode + " " + clashPath );
        }
      }
      else {
        node.restore( br.getBranch() );

        // FIXME should we look at the clash path or clash node
        if( node.equals( clashNode ) ) {
          cachedNodes.remove( node );
        }
      }
    }
    nodeList.subList( br.getNodeCount(), nodeList.size() ).clear();
View Full Code Here

    mergingAll = true;
    while (!merging && !mergeList.isEmpty() && !abox.isClosed()) {
      NodeMerge merge = mergeList.remove(0);

      Node y = abox.getNode(merge.getSource());
      Node z = abox.getNode(merge.getTarget());
      DependencySet ds = merge.getDepends();

      if (y.isMerged()) {
        ds = ds.union(y.getMergeDependency(true), abox.doExplanation());
        y = y.getSame();
      }

      if (z.isMerged()) {
        ds = ds.union(z.getMergeDependency(true), abox.doExplanation());
        z = z.getSame();
      }

      if (y.isPruned() || z.isPruned()) {
        continue;
      }

      mergeTo(y, z, ds);
    }
View Full Code Here

    // for all edges (y, r, z) where z is a nominal add an edge (x, r, z)
    EdgeList outEdges = y.getOutEdges();
    for (int e = 0; e < outEdges.size(); e++) {
      Edge edge = outEdges.edgeAt(e);
      Node z = edge.getTo();

      if (z.isNominal() && !y.equals(z)) {
        Role r = edge.getRole();
        DependencySet finalDS = ds.union(edge.getDepends(), abox.doExplanation());

        addEdge(x, r, z, finalDS);

        // add to effected list
        if (abox.getBranch() >= 0 && PelletOptions.TRACK_BRANCH_EFFECTS) {
          abox.getBranchEffectTracker().add(abox.getBranch(), z.getName());
        }

        // do not remove edge here because prune will take care of that
      }
    }
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.