import de.linguatools.disco.DISCO;
import de.linguatools.disco.ReturnDataBN;
import de.linguatools.disco.ReturnDataCol;
import java.io.IOException;


/*****************************************************************
 * sample code to show the use of the DISCO Java API version 1.1 *
 */
public class UseDISCOv1_1 {

    // call with: java UseDISCOv1_1.class <DISCO directory> <word>
    // (make sure that disco-1.1.jar is in the classpath)
    public static void main(String[] args) throws IOException{

        // first command line argument is path to the DISCO word space directory
        String discoDir = args[0];
        // second argument is the input word
        String word = args[1];

        // create instance of class DISCO
        DISCO disco = new DISCO();

        // retrieve the frequency of the input word
        int freq = disco.frequency(discoDir, word);
        // and print it to stdout
        System.out.println("Frequency of "+word+" is "+freq);

        // end if the word wasn't found in the index
        if(freq == 0) return;

        // retrieve the collocations for the input word
        ReturnDataCol[] collocationResult = disco.collocations(discoDir, word);
        // and print them to stdout
        System.out.println("Collocations:");
        for(int i = 0; i < collocationResult.length; i++){
            System.out.println("\t"+collocationResult[i].word+"\t"+
                    collocationResult[i].value);
        }

        // retrieve the most similar words for the input word
        ReturnDataBN simResult = disco.similarWords(discoDir, word);
        // and print the first 20 of them to stdout
        System.out.println("Most similar words:");
        for(int i = 0; i < simResult.words.length; i++){
            System.out.println("\t"+simResult.words[i]+"\t"+simResult.values[i]);
	    if( i >= 19 ) break;
        }

        // compute first order similarity between the input word and its third
        // collocation
        String thirdCollocation = collocationResult[3].word;
        float s1 = disco.firstOrderSimilarity(discoDir, word, thirdCollocation);
        // and print it to stdout
        System.out.println("first order similarity between "+word+" and "+
                thirdCollocation+" is "+s1);
    }
}

