Package org.mindswap.pellet

Examples of org.mindswap.pellet.Edge


      }
    }
  }

  public Edge addEdge(Individual subj, Role pred, Node obj, DependencySet ds) {
    Edge edge = subj.addEdge(pred, obj, ds);

    // add to the kb dependencies
    if (PelletOptions.USE_INCREMENTAL_DELETION) {
      abox.getKB().getDependencyIndex().addEdgeDependency(edge, ds);
    }
View Full Code Here


    if (disjoints.isEmpty()) {
      return;
    }
    EdgeList edges = subj.getEdgesTo(obj);
    for (int i = 0, n = edges.size(); i < n; i++) {
      Edge otherEdge = edges.edgeAt(i);

      if (disjoints.contains(otherEdge.getRole())) {
        ds = ds.union(otherEdge.getDepends(), abox.doExplanation());
        ds = ds.union(pred.getExplainDisjointRole(otherEdge.getRole()), abox.doExplanation());
        abox.setClash(Clash.disjointProps(subj, ds, pred.getName(), otherEdge.getRole().getName()));
        return;
      }
    }

  }
View Full Code Here

    Individual head = null;
    DependencySet headDS = null;
    // find a nominal node to use as the head
    for (int edgeIndex = 0; edgeIndex < edges.size(); edgeIndex++) {
      Edge edge = edges.edgeAt(edgeIndex);
      Individual ind = edge.getFrom();

      if (ind.isNominal() && (head == null || ind.getNominalLevel() < head.getNominalLevel())) {
        head = ind;
        headDS = edge.getDepends();
      }
    }

    // if there is no nominal in the merge list we need to create one
    if (head == null) {
      head = abox.addFreshIndividual(null, ds);
    }
    else {
      ds = ds.union(headDS, abox.doExplanation());
    }

    for (int i = 0; i < edges.size(); i++) {
      Edge edge = edges.edgeAt(i);
      Individual next = edge.getFrom();

      if (next.isPruned()) {
        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;
      }

      ds = ds.union(edge.getDepends(), abox.doExplanation());

      if (next.isDifferent(head)) {
        ds = ds.union(next.getDifferenceDependency(head), abox.doExplanation());
        if (r.isFunctional()) {
          abox.setClash(Clash.functionalCardinality(x, ds, r.getName()));
View Full Code Here

    }

    // for all edges (z, r, y) add an edge (z, r, x)
    EdgeList inEdges = y.getInEdges();
    for (int e = 0; e < inEdges.size(); e++) {
      Edge edge = inEdges.edgeAt(e);

      Individual z = edge.getFrom();
      Role r = edge.getRole();
      DependencySet finalDS = ds.union(edge.getDepends(), abox.doExplanation());

      // if y has a self edge then x should have the same self edge
      if (y.equals(z)) {
        addEdge(x, r, x, finalDS);
      }
      // if z is already a successor of x add the reverse edge
      else if (x.hasSuccessor(z)) {
        // FIXME what if there were no inverses in this expressitivity
        addEdge(x, r.getInverse(), z, finalDS);
      }
      else {
        addEdge(z, r, x, finalDS);
      }

      // only remove the edge from z and keep a copy in y for a
      // possible restore operation in the future
      z.removeEdge(edge);

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

    }

    // for all z such that y != z set x != z
    x.inheritDifferents(y, ds);

    // we want to prune y early due to an implementation issue about literals
    // if y has an outgoing edge to a literal with concrete value
    y.prune(ds);

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

    x.addAllTypes(y.getDepends(), ds);

    // for all edges (z, r, y) add an edge (z, r, x)
    EdgeList inEdges = y.getInEdges();
    for (int e = 0; e < inEdges.size(); e++) {
      Edge edge = inEdges.edgeAt(e);

      Individual z = edge.getFrom();
      Role r = edge.getRole();
      DependencySet finalDS = ds.union(edge.getDepends(), abox.doExplanation());

      addEdge(z, r, x, finalDS);

      // only remove the edge from z and keep a copy in y for a
      // possible restore operation in the future
View Full Code Here

      allValuesRule.apply( n );
    }
   
    //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 );
          }
        }
         
       
        //get out edges
        for( int j = 0; j < ind.getInEdges().size(); j++ ){
          Edge e = ind.getInEdges().edgeAt( j );
                       
          if( !e.getFrom().isPruned() && !e.getTo().isPruned() )
            applyPropertyRestrictions( e );
         
          Individual subj= e.getFrom();
          subj.applyNext[Node.ALL] = 0;
          allValuesRule.apply( subj );
        }
      }
    }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public boolean isSafe(ATermAppl c, Individual ind) {
    Edge parentEdge = getParentEdge( ind );
    Role r = parentEdge.getRole();
    Individual parent = parentEdge.getFrom();
   
    ABox abox = parent.getABox();

    if( !isParentSafe( abox.getKB(), r, parent ) )
      return false;
View Full Code Here

    return true;
  }

  protected Edge getParentEdge(Individual ind) {
    Edge result = null;
    Role role = null;
    Individual parent = ind.getParent();
    for( Edge e : ind.getInEdges() ) {
      if( e.getFrom().equals( parent ) ) {
        if( role == null ) {
View Full Code Here

        selfRule.apply(n);

        // CHW-added for inc. queue must see if this is bad
        EdgeList allEdges = n.getOutEdges();
        for (int e = 0; e < allEdges.size(); e++) {
          Edge edge = allEdges.edgeAt(e);
          if (edge.getTo().isPruned()) {
            continue;
          }

          applyPropertyRestrictions(edge);
          if (n.isMerged()) {
            break;
          }
        }

      }

      return;
    }

    if (log.isLoggable(Level.FINE)) {
      log.fine("Initialize started");
    }

    abox.setBranch(0);

    mergeList.addAll(abox.getToBeMerged());

    if (!mergeList.isEmpty()) {
      mergeAll();
    }

    Role topRole = abox.getRole(TOP_OBJECT_PROPERTY);
    Iterator<Individual> i = getInitializeIterator();
    while (i.hasNext()) {
      Individual n = i.next();

      if (n.isMerged()) {
        continue;
      }

      applyUniversalRestrictions(n);
      if (n.isMerged()) {
        continue;
      }

      selfRule.apply(n);
      if (n.isMerged()) {
        continue;
      }

      EdgeList allEdges = n.getOutEdges();
      for (int e = 0; e < allEdges.size(); e++) {
        Edge edge = allEdges.edgeAt(e);

        if (edge.getTo().isPruned()) {
          continue;
        }

        applyPropertyRestrictions(edge);
View Full Code Here

      }
    }
  }

  public void addEdge(Individual subj, Role pred, Node obj, DependencySet ds) {
    Edge edge = subj.addEdge(pred, obj, ds);

    // add to the kb dependencies
    if (PelletOptions.USE_INCREMENTAL_DELETION) {
      abox.getKB().getDependencyIndex().addEdgeDependency(edge, ds);
    }
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.