Package org.mindswap.pellet

Examples of org.mindswap.pellet.Individual


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


  }
 
  public void apply( IndividualIterator i ) {
        i.reset( nodeSelector );
        while( i.hasNext() ) {
            Individual node = i.next();
     
            if( strategy.getBlocking().isBlocked( node ) ) {
        if( PelletOptions.USE_COMPLETION_QUEUE )
          addQueueElement( node );       
      }
View Full Code Here

            if ( node.isIndividual() && !node.isPruned() && node.hasType( c ) ) {
              return;
            }
          }
         
          Individual y = strategy.createFreshIndividual( x, ds );
          strategy.addType( y, c, ds );
          return;
        }
       
        Role role = strategy.getABox().getRole( s );


        // Is there a r-neighbor that satisfies the someValuesFrom restriction
        boolean neighborFound = false;
        // Safety condition as defined in the SHOIQ algorithm.
        // An R-neighbor y of a node x is safe if
        // (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 {
                                    useExistingNode = true;
                                    edge = edges.edgeAt( 0 );
                                    y = edge.getNeighbor( x );
                                }
                            }
                        }
                        if( y != null )
                            y = y.getSame();
                    }
                }

                if( useExistingNode ) {
                    ds = ds.union( edge.getDepends(), strategy.getABox().doExplanation() );
                }
                else {
                    y = strategy.createFreshIndividual( x, ds );
                }

                if( log.isLoggable( Level.FINE ) )
                    log.fine( "SOME: " + x + " -> " + role + " -> " + y + " : " + ATermUtils.toString( c )
                        + (useExistingNode ? "" : " (*)") + " - " + ds );

                strategy.addType( y, c, ds );

                if( !useExistingRole ) {
                  if (x.isBlockable() && y.isConceptRoot())
                    strategy.addEdge( (Individual) y, role.getInverse(), x, ds );
                  else
                    strategy.addEdge( x, role, y, ds );
                }
            }
View Full Code Here

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

  void applyNominalRule(Individual y, ATermAppl nc, DependencySet ds) {
    strategy.getABox().copyOnWrite();

    ATermAppl nominal = (ATermAppl) nc.getArgument( 0 );
    // first find the individual for the given nominal
    Individual z = strategy.getABox().getIndividual( nominal );
    if( z == null ) {
      if( ATermUtils.isAnonNominal( nominal ) ) {
        z = strategy.getABox().addIndividual( nominal, ds );
      }
      else
        throw new InternalReasonerException( "Nominal " + nominal + " not found in KB!" );
    }

    // Get the value of mergedTo because of the following possibility:
    // Suppose there are three individuals like this
    // [x,{}],[y,{value(x)}],[z,{value(y)}]
    // After we merge x to y, the individual x is now represented by
    // the node y. It is too hard to update all the references of
    // value(x) so here we find the actual representative node
    // by calling getSame()
    if( z.isMerged() ) {
      ds = ds.union( z.getMergeDependency( true ), strategy.getABox().doExplanation() );

      z = z.getSame();
    }

    if( y.isSame( z ) )
      return;

    if( y.isDifferent( z ) ) {
      ds = ds.union( y.getDifferenceDependency( z ), strategy.getABox().doExplanation() );
      if( strategy.getABox().doExplanation() )
        strategy.getABox().setClash( Clash.nominal( y, ds, z.getName() ) );
      else
        strategy.getABox().setClash( Clash.nominal( y, ds ) );
      return;
    }
View Full Code Here

    // the edge could have previously been removed so return
    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 );
 
View Full Code Here

      // update the set of removed types
      tracker.addDeletedType( node, type.getType() );
 
      // add to updated individuals
      if( node instanceof Individual ) {
        Individual ind = (Individual) node;
        tracker.addUpdatedIndividual( ind );
 
        // also need to add all edge object to updated individuals -
        // this is needed to fire allValues/domain/range rules etc.
        for( Edge e : ind.getInEdges() ) {
          tracker.addUpdatedIndividual( e.getFrom() );
        }
        for( Edge e : ind.getOutEdges() ) {
          if( e.getTo() instanceof Individual )
            tracker.addUpdatedIndividual( (Individual) e.getTo() );
        }
      }
 
View Full Code Here

    assert objectNode != null;
    return objectNode;
  }
 
  public boolean activate(Edge edge) {
    Individual subject = initNode();
    Node object = initObjectNode();
    EdgeDirection dir = edgeMatches(edge);
    if (dir != null && (dir == EdgeDirection.FORWARD ? edge.getFrom() : edge.getTo()).isSame(subject) && (dir == EdgeDirection.BACKWARD ? edge.getFrom() : edge.getTo()).isSame(object)) {
      activate(WME.createEdge(edge, dir));
      return true;
View Full Code Here

  public Iterator<WME> getMatches(int argIndex, Node arg) {
    throw new UnsupportedOperationException();
  }

  public Iterator<WME> getMatches() {
    Individual subject = initNode();
    Node object = initObjectNode();
    EdgeList edges = subject.getEdgesTo(object, role);
    return toWMEs(edges, EdgeDirection.FORWARD);
  }
View Full Code Here

  }

  private boolean processIndividuals() {
    IndividualIterator i = m_KB.getABox().getIndIterator();
    while( i.hasNext() ) {
      Individual ind = i.next();
      ATermAppl nominal = ATermUtils.makeValue( ind.getName() );
      for( ATermAppl term : ind.getTypes() ) {
        if( term.equals( nominal ) )
          continue;

        if( !isEL( term ) )
          return false;
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.Individual

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.