src/main/java/org/thegalactic/context/Context.java
public static Context random(int nbObs, int nbGrp, int nbAttrPerGrp) {
        Context ctx = new Context();
        StringBuilder name = new StringBuilder();
        // Generates Observations.
        for (int i = 1; i <= nbObs; i++) {
            ctx.addToObservations(Integer.toString(i));
        }
        // Generates Attributes.
        for (int i = 1; i <= nbGrp; i++) {
            for (int j = 1; j <= nbAttrPerGrp; j++) {
                int q = i;
                name.setLength(0);
                do {
                    int rem = q % 26;
                    q = q / 26;
                    name.append((char) (rem + 65));
                } while (q != 0);
                name.append(j);
                ctx.addToAttributes(name.toString());
            }
        }
        // Generates all requested observations.
        Random r = new Random();
        int attr = r.nextInt(nbAttrPerGrp) + 1;
        for (int i = 1; i <= nbObs; i++) {
            // i : Observation
            for (int j = 1; j <= nbGrp; j++) {
                // j : Familly
                int q = j;
                // Clear the StringBuilder
                name.setLength(0);
                do {
                    int rem = q % 26;
                    q = q / 26;
                    name.append((char) (rem + 65));
                } while (q != 0);
                name.append(attr);
                ctx.addExtentIntent(Integer.toString(i), name.toString());
                attr = r.nextInt(nbAttrPerGrp) + 1;
            }
        }
        ctx.setBitSets();
        return ctx;
    }
/**
     * Generates a partially random context.
     *
     * @param nbObs        number of observations
     * @param nbGrp        number of groups of attributes . Attributes are
     *                     grouped such that each observation has one
     *                     attribute per group.
     * @param nbAttrPerGrp number of attributes per group.
     *
     * @return randomly generated context
     */
Generates a partially random context.
@param nbObs        number of observations
@param nbGrp        number of groups of attributes . Attributes are
grouped such that each observation has one
attribute per group.
@param nbAttrPerGrp number of attributes per group.

@return randomly generated context
Generates a partially random context . @param nbObs number of observations @param nbGrp number of groups of attributes . Attributes are grouped such that each observation has one attribute per group . @param nbAttrPerGrp number of attributes per group . @return randomly generated context
public static Context random(int nbObs, int nbGrp, int nbAttrPerGrp) {
        Context ctx = new Context();
        StringBuilder name = new StringBuilder();
        for (int i = 1; i <= nbObs; i++) {
            ctx.addToObservations(Integer.toString(i));
        }
        for (int i = 1; i <= nbGrp; i++) {
            for (int j = 1; j <= nbAttrPerGrp; j++) {
                int q = i;
                name.setLength(0);
                do {
                    int rem = q % 26;
                    q = q / 26;
                    name.append((char) (rem + 65));
                } while (q != 0);
                name.append(j);
                ctx.addToAttributes(name.toString());
            }
        }
        Random r = new Random();
        int attr = r.nextInt(nbAttrPerGrp) + 1;
        for (int i = 1; i <= nbObs; i++) {
            for (int j = 1; j <= nbGrp; j++) {
                int q = j;
                name.setLength(0);
                do {
                    int rem = q % 26;
                    q = q / 26;
                    name.append((char) (rem + 65));
                } while (q != 0);
                name.append(attr);
                ctx.addExtentIntent(Integer.toString(i), name.toString());
                attr = r.nextInt(nbAttrPerGrp) + 1;
            }
        }
        ctx.setBitSets();
        return ctx;
    }
public static Context random ( int nbObs , int nbGrp , int nbAttrPerGrp ) { Context ctx = new Context ( ) ; StringBuilder name = new StringBuilder ( ) ; for ( int i = 1 ; i <= nbObs ; i ++ ) { ctx . addToObservations ( Integer . toString ( i ) ) ; } for ( int i = 1 ; i <= nbGrp ; i ++ ) { for ( int j = 1 ; j <= nbAttrPerGrp ; j ++ ) { int q = i ; name . setLength ( 0 ) ; do { int rem = q % 26 ; q = q / 26 ; name . append ( ( char ) ( rem + 65 ) ) ; } while ( q != 0 ) ; name . append ( j ) ; ctx . addToAttributes ( name . toString ( ) ) ; } } Random r = new Random ( ) ; int attr = r . nextInt ( nbAttrPerGrp ) + 1 ; for ( int i = 1 ; i <= nbObs ; i ++ ) { for ( int j = 1 ; j <= nbGrp ; j ++ ) { int q = j ; name . setLength ( 0 ) ; do { int rem = q % 26 ; q = q / 26 ; name . append ( ( char ) ( rem + 65 ) ) ; } while ( q != 0 ) ; name . append ( attr ) ; ctx . addExtentIntent ( Integer . toString ( i ) , name . toString ( ) ) ; attr = r . nextInt ( nbAttrPerGrp ) + 1 ; } } ctx . setBitSets ( ) ; return ctx ; }
Generates a partially random context.
Generates a partially random context .
// Generates Observations. // Generates Attributes. // Generates all requested observations. // i : Observation // j : Familly // Clear the StringBuilder