src/main/java/ch/uzh/ifi/seal/ase/cscc/RecommenderHelper.java
public void evaluateModel(String modelDir) {
        List<String> zips = IoHelper.findAllZips(eventsDir);
        int zipTotal = getNumZips(zips);
        int zipCount = 0;

        IInvertedIndex diskIndex = new DiskBasedInvertedIndex(modelDir);
        CompletionModel model = new CompletionModel(diskIndex);
        CompletionModelEvaluator eval = new CompletionModelEvaluator(model);

        for (String zip : zips) {

            if (++zipCount > zipTotal) break;

            double perc = 100 * zipCount / (double) zipTotal;

            if (CSCCConfiguration.PRINT_PROGRESS) {
                System.out.printf("## %s, processing %s...\n(%d/%d, %.1f%% done)\n", new Date(), zip, zipCount, zipTotal,
                        perc);
            }

            try (IReadingArchive ra = new ReadingArchive(new File(zip))) {

                while (ra.hasNext()) {

                    if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                        System.out.printf("."); // print '.' to indicate that a context is being processed
                    }

                    IDEEvent evt = ra.getNext(IDEEvent.class);

                    if (evt instanceof CompletionEvent) {
                        CompletionEvent event = (CompletionEvent) evt;

                        if (event.terminatedState == TerminationState.Applied && event.getLastSelectedProposal() != null) {
                            if (event.getLastSelectedProposal().getName() instanceof IMethodName) {
                                IMethodName methodName = (IMethodName) event.getLastSelectedProposal().getName();

                                IndexDocumentExtractionVisitor indexDocumentExtractionVisitor = new IndexDocumentExtractionVisitor();
                                List<IndexDocument> indexDocuments = new LinkedList<>();

                                // get all method invocations (indexDocuments) of the event
                                event.context.getSST().accept(indexDocumentExtractionVisitor, indexDocuments);

                                for (IndexDocument document : indexDocuments) {
                                    // Only evaluate for the IndexDocument that correlates with the given method call.
                                    // Note that we might find several method calls of the same given name in the same
                                    // context. Thus we can't be certain that we only get the one which was used in the
                                    // completion event.
                                    if (document.getMethodCall().equals(methodName.getName())) {
                                        if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                                            System.out.printf("'"); // print ' to indicate that an IndexDocument is being evaluated
                                        }
                                        eval.evaluate(document);
                                    }
                                }
                            }

                            /*System.out.println("completion event, out of proposals");
                            for (IProposal proposal : event.proposalCollection) {
                                System.out.println("  " + proposal.getName().getIdentifier());
                            }
                            System.out.println("selected " + event.getLastSelectedProposal().getName().getIdentifier());*/
                        }
                    }
                }
                ra.close();
                if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                    System.out.println();
                }
            }
        }

        System.out.printf("precision = %.0f%%, recall = %.0f%%\n", eval.getPrecision(), eval.getRecall());
    }
/**
     * Evaluates a learned model against the Events data set.
     * Test results are printed to the console.
     *
     * @param modelDir directory of the learned model
     */
Evaluates a learned model against the Events data set.
Test results are printed to the console.

@param modelDir directory of the learned model
Evaluates a learned model against the Events data set . Test results are printed to the console . @param modelDir directory of the learned model
public void evaluateModel(String modelDir) {
        List<String> zips = IoHelper.findAllZips(eventsDir);
        int zipTotal = getNumZips(zips);
        int zipCount = 0;
        IInvertedIndex diskIndex = new DiskBasedInvertedIndex(modelDir);
        CompletionModel model = new CompletionModel(diskIndex);
        CompletionModelEvaluator eval = new CompletionModelEvaluator(model);
        for (String zip : zips) {
            if (++zipCount > zipTotal) break;
            double perc = 100 * zipCount / (double) zipTotal;
            if (CSCCConfiguration.PRINT_PROGRESS) {
                System.out.printf("## %s, processing %s...\n(%d/%d, %.1f%% done)\n", new Date(), zip, zipCount, zipTotal,
                        perc);
            }
            try (IReadingArchive ra = new ReadingArchive(new File(zip))) {
                while (ra.hasNext()) {
                    if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                        System.out.printf("."); 
                    }
                    IDEEvent evt = ra.getNext(IDEEvent.class);
                    if (evt instanceof CompletionEvent) {
                        CompletionEvent event = (CompletionEvent) evt;
                        if (event.terminatedState == TerminationState.Applied && event.getLastSelectedProposal() != null) {
                            if (event.getLastSelectedProposal().getName() instanceof IMethodName) {
                                IMethodName methodName = (IMethodName) event.getLastSelectedProposal().getName();
                                IndexDocumentExtractionVisitor indexDocumentExtractionVisitor = new IndexDocumentExtractionVisitor();
                                List<IndexDocument> indexDocuments = new LinkedList<>();
                                event.context.getSST().accept(indexDocumentExtractionVisitor, indexDocuments);
                                for (IndexDocument document : indexDocuments) {
                                    if (document.getMethodCall().equals(methodName.getName())) {
                                        if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                                            System.out.printf("'"); 
                                        }
                                        eval.evaluate(document);
                                    }
                                }
                            }
                            /*System.out.println("completion event, out of proposals");
                            for (IProposal proposal : event.proposalCollection) {
                                System.out.println("  " + proposal.getName().getIdentifier());
                            }
                            System.out.println("selected " + event.getLastSelectedProposal().getName().getIdentifier());*/
                        }
                    }
                }
                ra.close();
                if (CSCCConfiguration.PRINT_PROGRESS_CONTEXTS) {
                    System.out.println();
                }
            }
        }
        System.out.printf("precision = %.0f%%, recall = %.0f%%\n", eval.getPrecision(), eval.getRecall());
    }
public void evaluateModel ( String modelDir ) { List < String > zips = IoHelper . findAllZips ( eventsDir ) ; int zipTotal = getNumZips ( zips ) ; int zipCount = 0 ; IInvertedIndex diskIndex = new DiskBasedInvertedIndex ( modelDir ) ; CompletionModel model = new CompletionModel ( diskIndex ) ; CompletionModelEvaluator eval = new CompletionModelEvaluator ( model ) ; for ( String zip : zips ) { if ( ++ zipCount > zipTotal ) break ; double perc = 100 * zipCount / ( double ) zipTotal ; if ( CSCCConfiguration . PRINT_PROGRESS ) { System . out . printf ( "## %s, processing %s...\n(%d/%d, %.1f%% done)\n" , new Date ( ) , zip , zipCount , zipTotal , perc ) ; } try ( IReadingArchive ra = new ReadingArchive ( new File ( zip ) ) ) { while ( ra . hasNext ( ) ) { if ( CSCCConfiguration . PRINT_PROGRESS_CONTEXTS ) { System . out . printf ( "." ) ; } IDEEvent evt = ra . getNext ( IDEEvent . class ) ; if ( evt instanceof CompletionEvent ) { CompletionEvent event = ( CompletionEvent ) evt ; if ( event . terminatedState == TerminationState . Applied && event . getLastSelectedProposal ( ) != null ) { if ( event . getLastSelectedProposal ( ) . getName ( ) instanceof IMethodName ) { IMethodName methodName = ( IMethodName ) event . getLastSelectedProposal ( ) . getName ( ) ; IndexDocumentExtractionVisitor indexDocumentExtractionVisitor = new IndexDocumentExtractionVisitor ( ) ; List < IndexDocument > indexDocuments = new LinkedList < > ( ) ; event . context . getSST ( ) . accept ( indexDocumentExtractionVisitor , indexDocuments ) ; for ( IndexDocument document : indexDocuments ) { if ( document . getMethodCall ( ) . equals ( methodName . getName ( ) ) ) { if ( CSCCConfiguration . PRINT_PROGRESS_CONTEXTS ) { System . out . printf ( "'" ) ; } eval . evaluate ( document ) ; } } } /*System.out.println("completion event, out of proposals");
                            for (IProposal proposal : event.proposalCollection) {
                                System.out.println("  " + proposal.getName().getIdentifier());
                            }
                            System.out.println("selected " + event.getLastSelectedProposal().getName().getIdentifier());*/ } } } ra . close ( ) ; if ( CSCCConfiguration . PRINT_PROGRESS_CONTEXTS ) { System . out . println ( ) ; } } } System . out . printf ( "precision = %.0f%%, recall = %.0f%%\n" , eval . getPrecision ( ) , eval . getRecall ( ) ) ; }
Evaluates a learned model against the Events data set.
Evaluates a learned model against the Events data set .
// print '.' to indicate that a context is being processed
 // get all method invocations (indexDocuments) of the event
 // Only evaluate for the IndexDocument that correlates with the given method call.
 // Note that we might find several method calls of the same given name in the same
 // context. Thus we can't be certain that we only get the one which was used in the
 // completion event.
 // print ' to indicate that an IndexDocument is being evaluated
