Package org.mindswap.pellet.utils

Examples of org.mindswap.pellet.utils.Timer


    conceptFlags = CollectionUtils.makeIdentityMap();
  }

  private void computeToldInformation() {
    Timer t = kb.timers.startTimer( "computeToldInformation" );

    toldTaxonomy = new Taxonomy<ATermAppl>( classes, ATermUtils.TOP, ATermUtils.BOTTOM );

    // compute told subsumers for each concept
    TBox tbox = kb.getTBox();
    Collection<ATermAppl> axioms = tbox.getAxioms();
    for( ATermAppl axiom : axioms ) {
      ATermAppl c1 = (ATermAppl) axiom.getArgument( 0 );
      ATermAppl c2 = (ATermAppl) axiom.getArgument( 1 );

      boolean equivalent = axiom.getAFun().equals( ATermUtils.EQCLASSFUN );
      Set<ATermAppl> explanation = tbox.getAxiomExplanation( axiom );

      boolean reverseArgs = !ATermUtils.isPrimitive( c1 ) && ATermUtils.isPrimitive( c2 );
      if( equivalent && reverseArgs ) {
              addToldRelation( c2, c1, equivalent, explanation );
            }
            else {
              addToldRelation( c1, c2, equivalent, explanation );
            }
    }

    // additional step for union classes. for example, if we have
    // C = or(A, B)
    // and both A and B subclass of D then we can conclude C is also
    // subclass of D
    for( ATermAppl c : unionClasses.keySet() ) {

      List<ATermAppl> list = new ArrayList<ATermAppl>();
      for( ATermList disj = unionClasses.get( c ); !disj.isEmpty(); disj = disj.getNext() ) {
        list.add( (ATermAppl) disj.getFirst() );
      }
      List<ATermAppl> lca = toldTaxonomy.computeLCA( list );

      for( ATermAppl d : lca ) {
        if( log.isLoggable( Level.FINER ) ) {
                  log.finer( "Union subsumption " + format( c ) + " " + format( d ) );
                }

        addToldSubsumer( c, d );
      }
    }

    // we don't need this any more so set it null and let GC claim it
    unionClasses = null;

    toldTaxonomy.assertValid();

    t.stop();
  }
View Full Code Here


  private TaxonomyNode<ATermAppl> checkSatisfiability(ATermAppl c) {
    if( log.isLoggable( Level.FINER ) ) {
          log.finer( "Satisfiable " );
        }

    Timer t = kb.timers.startTimer( "classifySat" );
    boolean isSatisfiable = kb.getABox().isSatisfiable( c, true );
    t.stop();

    if( log.isLoggable( Level.FINER ) ) {
          log.finer( (isSatisfiable
        ? "true"
        : "*****FALSE*****") + " (" + t.getLast() + "ms)" );
        }

    if( !isSatisfiable ) {
          taxonomy.addEquivalentNode( c, taxonomy.getBottom() );
        }

    if( PelletOptions.USE_CACHING ) {
      if( log.isLoggable( Level.FINER ) ) {
              log.finer( "...negation " );
            }

      t = kb.timers.startTimer( "classifySatNot" );
      ATermAppl notC = ATermUtils.makeNot( c );
      isSatisfiable = kb.getABox().isSatisfiable( notC, true );
      t.stop();

      if( !isSatisfiable ) {
              taxonomy.addEquivalentNode( c, taxonomy.getTop() );
            }

      if( log.isLoggable( Level.FINER ) ) {
              log.finer( isSatisfiable + " (" + t.getLast() + "ms)" );
            }
    }

    return taxonomy.getNode( c );
  }
View Full Code Here

         * if i has only one super class j and j is a subclass of i then
         * it means i = j. There is no need to classify i since we
         * already know everything about j
         */
        ATermAppl sup = supNode.getName();
        Timer t = kb.timers.startTimer( "eqCheck" );
        boolean isEq = subsumes( c, sup );
        t.stop();
        if( isEq ) {
          if( log.isLoggable( Level.FINER ) ) {
                      log.finer( format( c ) + " = " + format( sup ) );
                    }

View Full Code Here

  }

  private Collection<TaxonomyNode<ATermAppl>> search(boolean topSearch, ATermAppl c,
      TaxonomyNode<ATermAppl> x, Set<TaxonomyNode<ATermAppl>> visited,
      List<TaxonomyNode<ATermAppl>> result) {
    Timer t = kb.timers.startTimer( "search" + (topSearch ? "Top" : "Bottom") );
   
    List<TaxonomyNode<ATermAppl>> posSucc = new ArrayList<TaxonomyNode<ATermAppl>>();
    visited.add( x );

    Collection<TaxonomyNode<ATermAppl>> list = topSearch
      ? x.getSubs()
      : x.getSupers();

    for( TaxonomyNode<ATermAppl> next : list ) {

      if( topSearch ) {
        if( subsumes( next, c ) ) {
                  posSucc.add( next );
                }
      }
      else {
        if( subsumed( next, c ) ) {
                  posSucc.add( next );
                }
      }
    }

    if( posSucc.isEmpty() ) {
      result.add( x );
    }
    else {
      for( TaxonomyNode<ATermAppl> y : posSucc ) {
        if( !visited.contains( y ) ) {
                  search( topSearch, c, y, visited, result );
                }
      }
    }

    t.stop();
   
    return result;
  }
View Full Code Here

        time = System.currentTimeMillis();
        count = kb.getABox().stats.consistencyCount;
        log.finer( "Type checking for [" + format( n ) + ", " + format( c ) + "]..." );
      }

      Timer t = kb.timers.startTimer( "classifyType" );
      isType = kb.isType( n, c );
      t.stop();
      marked.put( c, isType
        ? Boolean.TRUE
        : Boolean.FALSE );

      if( log.isLoggable( Level.FINER ) ) {
View Full Code Here

    return instances;
  }

  public void printStats() {
    Timer t1 = kb.timers.getTimer( "satisfiability" );
    Timer t2 = kb.timers.getTimer( "subClassSat" );
    StringBuilder sb = new StringBuilder( kb.getABox().getCache().toString() );
    sb.append( "sat: " );
    if( t1 != null ) {
      sb.append( t1.getCount() ).append( " " ).append( t1.getTotal() );
    }
    else {
      sb.append( "0" );
    }

    sb.append( " sub: " );
    if( t2 != null ) {
      sb.append( t2.getCount() ).append( " " ).append( t2.getTotal() );
    }
    else {
      sb.append( "0" );
    }
View Full Code Here

    // We need some timing to show the performance of the classification
    Timers timers = new Timers();

    // We classify the ontology and use a specific timer to keep track of
    // the time required for the classification
    Timer t = timers.createTimer( "First classification" );
    t.start();
    classifier.classify();
    t.stop();
       
    System.out.println( "\nClassification time: " + t.getTotal() + "ms");
    System.out.println( "Subclasses of " + pain + ": " + classifier.getSubClasses( pain, true ).getFlattened() + "\n");
   
    // Now create a new OWL axiom, subClassOf(Headache, Pain)
    OWLAxiom axiom = OWL.subClassOf( headache, pain );

    // Add the axiom to the ontology, which creates a change event
    OWL.manager.applyChange( new AddAxiom( ontology, axiom ) );

    // Now we create a second timer to keep track of the performance of the
    // second classification
    t = timers.createTimer( "Second classification" );
    t.start();
    classifier.classify();
    t.stop();
   
    System.out.println( "\nClassification time: " + t.getTotal() + "ms");
    System.out.println( "Subclasses of " + pain + ": " + classifier.getSubClasses( pain, true ).getFlattened() + "\n");

    // Remove the axiom from the ontology, which creates a change event
    OWL.manager.applyChange( new RemoveAxiom( ontology, axiom ) );

    // Now we create a third timer to keep track of the performance of the
    // third classification
    timers.startTimer( "Third classification" );
    classifier.classify();
    timers.stopTimer( "Third classification" );
   
    System.out.println( "\nClassification time: " + t.getTotal() + "ms");
    System.out.println( "Subclasses of " + pain + ": " + classifier.getSubClasses( pain, true ).getFlattened() + "\n");
   
    // Finally, print the timing. As you can see, the second classification
    // takes significantly less time, which is the characteristic of the
    // incremental classifier.
View Full Code Here

  public boolean isDynamic() {
    return true;
  }
 
  public boolean isBlocked(Individual blocked) {
    Timer t = blocked.getABox().getKB().timers.startTimer( "blocking" );
    try {
      return !blocked.isRoot() && (isIndirectlyBlocked( blocked ) || isDirectlyBlockedInt( blocked ));
    }
    finally {
      t.stop();
    }
  }
View Full Code Here

    blocked.setBlocked( isBlocked( parent ) );
    return blocked.isBlocked();
  }
 
  public boolean isDirectlyBlocked(Individual blocked) {
    Timer t = blocked.getABox().getKB().timers.startTimer( "dBlocking" )
    try {   
      return isDirectlyBlockedInt( blocked );
    }
    finally {
      t.stop();
    }
  }
View Full Code Here

        }
  }

  public ABox(KnowledgeBase kb, ABox abox, ATermAppl extraIndividual, boolean copyIndividuals) {
    this.kb = kb;
    Timer timer = kb.timers.startTimer( "cloneABox" );


    this.rulesNotApplied = true;
    initialized = abox.initialized;
    setChanged( abox.isChanged() );
    setAnonCount( abox.getAnonCount() );
    cache = abox.cache;
    clash = abox.clash;   
    dtReasoner = abox.dtReasoner;
    doExplanation = abox.doExplanation;
    setDisjBranchStats( abox.getDisjBranchStats() );

    int extra = (extraIndividual == null)
      ? 0
      : 1;
    int nodeCount = extra + (copyIndividuals
      ? abox.nodes.size()
      : 0);

    nodes = new HashMap<ATermAppl, Node>( nodeCount );
    nodeList = new ArrayList<ATermAppl>( nodeCount );

    if( PelletOptions.TRACK_BRANCH_EFFECTS ) {
      if( copyIndividuals ) {
              branchEffects = abox.branchEffects.copy();
            }
            else {
              branchEffects = new SimpleBranchEffectTracker();
            }
    }
        else {
          branchEffects = null;
        }
   
    // copy the queue - this must be done early so that the effects of
    // adding the extra individual do not get removed
    if( PelletOptions.USE_COMPLETION_QUEUE ) {
      if( copyIndividuals ) {
        completionQueue = abox.completionQueue.copy();
        completionQueue.setABox( this );
      }
      else if( PelletOptions.USE_OPTIMIZED_BASIC_COMPLETION_QUEUE ) {
              completionQueue = new OptimizedBasicCompletionQueue( this );
            }
            else {
              completionQueue = new BasicCompletionQueue( this );
            }
    }
        else {
          completionQueue = null;
        }

    if( extraIndividual != null ) {
      Individual n = new Individual( extraIndividual, this, null );
      n.setNominalLevel( Node.BLOCKABLE );
      n.setConceptRoot( true );
      n.addType( ATermUtils.TOP, DependencySet.INDEPENDENT );
      nodes.put( extraIndividual, n );
      nodeList.add( extraIndividual );

      if( PelletOptions.COPY_ON_WRITE ) {
              sourceABox = abox;
            }
    }

    if( copyIndividuals ) {
      toBeMerged = abox.getToBeMerged();
      if( sourceABox == null ) {
        for( int i = 0; i < nodeCount - extra; i++ ) {
          ATermAppl x = abox.nodeList.get( i );
          Node node = abox.getNode( x );
          Node copy = node.copyTo( this );

          nodes.put( x, copy );
          nodeList.add( x );
        }

        for( Node node : nodes.values() ) {
          node.updateNodeReferences();
        }
      }
    }
    else {
      toBeMerged = Collections.emptyList();
      sourceABox = null;
      initialized = false;
    }

    // Copy of the incChangeTracker looks up nodes in the new ABox, so this
    // copy must follow node copying
    if( PelletOptions.USE_INCREMENTAL_CONSISTENCY ) {
      if( copyIndividuals ) {
              incChangeTracker = abox.incChangeTracker.copy( this );
            }
            else {
              incChangeTracker = new SimpleIncrementalChangeTracker();
            }
    }
        else {
          incChangeTracker = null;
        }

    assertedClashes = new HashSet<Clash>();
    for( Clash clash : abox.assertedClashes ) {
      assertedClashes.add( clash.copyTo( this ) );
    }
   
    if( extraIndividual == null || copyIndividuals ) {
      setBranch( abox.branch );
      branches = new ArrayList<Branch>( abox.branches.size() );
      for( int i = 0, n = abox.branches.size(); i < n; i++ ) {
        Branch branch = abox.branches.get( i );
        Branch copy;

        if( sourceABox == null ) {
          copy = branch.copyTo( this );
          copy.setNodeCount( branch.getNodeCount() + extra );
        }
        else {
          copy = branch;
        }
        branches.add( copy );
      }
    }
    else {
      setBranch( DependencySet.NO_BRANCH );
      branches = new ArrayList<Branch>();
    }

    timer.stop();

  }
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.utils.Timer

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.