<commit_before>package oracle;

import oracle.cli.CLI;
import oracle.markov.MarkovChain;
import oracle.markov.MarkovQueue;
import processing.core.PApplet;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by mrzl on 31.03.2016.
 */
public class LacunaLabOracle extends PApplet {

    public static String markovJsonFileName = "lacuna_markov_export.json";
    private CLI cli;
    private MarkovChain markov;

    public void settings() {
        size( 640, 480 );
        //fullScreen( );
    }

    public void setup() {
        cli = new CLI( this );
        markov = new MarkovChain();
        //markov.train( loadText( "lacuna_lab_texts.txt" ) );
        loadConfiguration();
    }

    private String loadText( String fileName ) {
        String completeText = "";
        try ( Stream< String > stream = Files.lines( Paths.get( fileName ) )) {

            String s = stream.collect( Collectors.joining( ) );
            completeText += s;

        } catch (IOException e) {
            e.printStackTrace();
        }

        return completeText;
    }

    public void draw() {
        background( 0 );
        cli.draw();
    }

    public void keyPressed( ) {
        if( key == CODED ){
            switch( keyCode ) {
            }
        } else {
            switch( key ) {
                case BACKSPACE:
                    cli.backspace();
                    break;
                case ENTER:
                    MarkovQueue queue = new MarkovQueue( 1 );
                    String [] inputWords = cli.getLastLine().getText().split( " " );
                    queue.addFirst( inputWords[ 0 ] );
                    cli.finish( markov.generateSentence( queue ) );
                    break;
                case TAB:
                case DELETE:
                    break;
                case ESC:
                    cli.reset( );
                    break;
                case 'e':
                    // export markov chain to json
                    saveConfiguration( );
                case 'l':
                    // load markov chain from json
                    loadConfiguration();
                default:
                    cli.type( key );
                    break;
            }
        }
    }

    private void saveConfiguration() {
        try {
            markov.saveToFile( markovJsonFileName );
        } catch ( IOException e ) {
            e.printStackTrace( );
        }<commit_msg>only using lowercase text from now on<commit_after>package oracle;

import oracle.cli.CLI;
import oracle.markov.MarkovChain;
import oracle.markov.MarkovChain2;
import oracle.markov.MarkovQueue;
import processing.core.PApplet;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by mrzl on 31.03.2016.
 */
public class LacunaLabOracle extends PApplet {

    public static String markovJsonFileName = "lacuna_markov_export.json";
    private CLI cli;
    private MarkovChain markov;

    public void settings() {
        size( 640, 480 );
        //fullScreen( );
    }

    public void setup() {
        cli = new CLI( this );
        markov = new MarkovChain( 1 );
        //markov.train( loadText( "lacuna_lab_texts.txt" ) );
        loadConfiguration();
    }

    private String loadText( String fileName ) {
        String completeText = "";
        try ( Stream< String > stream = Files.lines( Paths.get( fileName ) )) {

            String s = stream.collect( Collectors.joining( ) );
            completeText += s;

        } catch (IOException e) {
            e.printStackTrace();
        }

        return completeText.toLowerCase();
    }

    public void draw() {
        background( 0 );
        cli.draw();
    }

    public void keyPressed( ) {
        if( key == CODED ){
            switch( keyCode ) {
            }
        } else {
            switch( key ) {
                case BACKSPACE:
                    cli.backspace();
                    break;
                case ENTER:
                    String [] inputWords = cli.getLastLine().getText().toLowerCase().split( " " );
                    MarkovQueue queue = new MarkovQueue( 1 );

                    for( String s : inputWords ) {
                        queue.push( s );
                    }

                    String result = markov.generateSentence( queue );
                    if( result.equals( inputWords[ 0 ] + " " )) {
                        result = "oracle: no associations. try again";
                    }
                    cli.finish( result );
                    break;
                case TAB:
                case DELETE:
                    break;
                case ESC:
                    cli.reset( );
                    break;
                case 'e':
                    // export markov chain to json
                    //saveConfiguration( );
                case 'l':
                    // load markov chain from json
                    //loadConfiguration();
                default:
                    cli.type( key );
                    break;
            }
        }
    }

    private void saveConfiguration() {
        try {
            markov.saveToFile( markovJsonFileName );
        } catch ( IOException e ) {
            e.printStackTrace( );
        }
{'fraction_non_alphanumeric': 0.09823040808956301, 'fraction_numerical': 0.0065005417118093175, 'mean_word_length': 1.3721627408993575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120469', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1389, 'n_words': 359}