Example usage for org.apache.hadoop.io Text toString

List of usage examples for org.apache.hadoop.io Text toString

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text toString.

Prototype

@Override
public String toString() 

Source Link

Document

Convert text back to string

Usage

From source file:boa.datagen.SeqRepoImporter.java

License:Apache License

private static void getProcessedProjects() throws IOException {
    FileStatus[] files = fileSystem.listStatus(new Path(base + "tmprepcache/2015-08"));
    String hostname = InetAddress.getLocalHost().getHostName();
    for (int i = 0; i < files.length; i++) {
        FileStatus file = files[i];/*from   w ww.j  a  v a 2s .c o m*/
        String prefix = "projects-" + hostname + "-";
        String name = file.getPath().getName();
        int index1 = name.indexOf(prefix);
        if (index1 > -1) {
            try {
                SequenceFile.Reader r = new SequenceFile.Reader(fileSystem, file.getPath(), conf);
                final Text key = new Text();
                while (r.next(key)) {
                    processedProjectIds.add(key.toString());
                }
                r.close();
            } catch (EOFException e) {
                printError(e, "EOF Exception in " + file.getPath().getName());
                fileSystem.delete(file.getPath(), false);
            }
        }
    }
    System.out.println("Got processed projects: " + processedProjectIds.size());
}

From source file:boa.datagen.SeqSortMerge.java

License:Apache License

private static int min(Text[] keys) {
    int index = 0;
    Text min = keys[0];//from  w ww. ja  v  a 2  s  . co m
    for (int i = 1; i < keys.length; i++) {
        Text key = keys[i];
        if (!key.toString().isEmpty() && key.compareTo(min) < 0) {
            index = i;
            min = key;
        }
    }
    return index;
}

From source file:boostingPL.boosting.InstancesHelper.java

License:Open Source License

/**
 * create instances header from metadata,
 * the metadata like this:/*from   www  . j av a2s .c om*/
 * 
 *   <br/>
 *   <p>attributesNum:100</p>
 *   <p>classes:+1,-1</p>
 *   <br/>
 * 
 * @param in
 * @return
 * @throws IOException
 */
public static Instances createInstancesFromMetadata(LineReader in) throws IOException {
    int attributesNum = 0;
    ArrayList<Attribute> attInfo = null;
    List<String> classItems = null;

    Text line = new Text();
    while (in.readLine(line) > 0) {
        String sline = line.toString();
        if (sline.startsWith("attributesNum:")) {
            attributesNum = Integer.parseInt(sline.substring(14));
            attInfo = new ArrayList<Attribute>(attributesNum + 1);
            for (int i = 0; i < attributesNum; i++) {
                attInfo.add(new Attribute("attr" + i));
            }

            System.out.println("AttributeNum:" + attributesNum);
        } else if (sline.startsWith("classes:")) {
            String classes = sline.substring(8);
            String[] citems = classes.split(",");
            classItems = new ArrayList<String>(citems.length);
            for (String s : citems) {
                classItems.add(s);
            }

            System.out.println("classes:" + classes);
        }
    }

    attInfo.add(new Attribute("class", classItems));
    Instances insts = new Instances("BoostingPL-dataset", attInfo, 0);
    insts.setClassIndex(insts.numAttributes() - 1);

    return insts;
}

From source file:boostingPL.MR.AdaBoostPLMapper.java

License:Open Source License

protected void map(LongWritable key, Text value, Context context) {
    insts.add(InstancesHelper.createInstance(value.toString(), insts));
}

From source file:boostingPL.MR.AdaBoostPLTestMapper.java

License:Open Source License

protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    Instance inst = InstancesHelper.createInstance(value.toString(), insts);
    try {/*  w w  w  . ja v  a 2s.  c  o m*/
        eval.evaluateModelOnceAndRecordPrediction(boostingPL, inst);
    } catch (Exception e) {
        LOG.warn("[BoostingPL-Test]: Evalute instance error!, key = " + key.get());
        e.printStackTrace();
    }
    instanceCounter.increment(1);
    context.write(key, value);
}

From source file:boostingPL.MR.AdaBoostPLTestReducer.java

License:Open Source License

protected void reduce(LongWritable key, Iterable<Text> value, Context context)
        throws IOException, InterruptedException {
    for (Text t : value) {
        Instance inst = InstancesHelper.createInstance(t.toString(), insts);
        try {//from  w  w  w  .ja  v  a2  s  . co m
            eval.evaluateModelOnceAndRecordPrediction(boostingPL, inst);
        } catch (Exception e) {
            LOG.warn("[BoostingPL-Test]: Evalute instance error!, key = " + key.get());
            e.printStackTrace();
        }
    }
}

From source file:br.com.lassal.mrunit.example.mapreduce.SMSCDRMapper.java

/**
 * Returns the SMS status code and its count
 *//*from w  w w. j  a  v  a2 s.c om*/

protected void map(LongWritable key, Text value, Context context)
        throws java.io.IOException, InterruptedException {

    //655209;1;796764372490213;804422938115889;6 is the Sample record format
    String[] line = value.toString().split(";");
    // If record is of SMS CDR
    if (Integer.parseInt(line[1]) == 1) {
        status.set(line[4]);
        context.write(status, addOne);
        context.write(new Text("Z"), addOne);
    }
}

From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenIncrementalCounterMapper.java

protected void map(LongWritable key, Text value, Context context)
        throws java.io.IOException, InterruptedException {

    // obter o tempo da propriedade do Hadoop de tempo de execuo
    long tempoLimite = 9 * 60 * 1000; // minutos * segundos * milesimos

    NQueenCountRecord record = NQueenCountRecord.parse(value.toString(),
            NQueenIncrementalCounterMapper.QTD_POSICOES_PRESOLUCAO);

    if (!record.hasPredicate()) {
        this.mapeiaInicioSolucao(record.getNQueensSize(), context);
    } else {//w ww  .  ja  va2 s .  c o m
        this.resolveNQueens(record, tempoLimite, context);
    }
}

From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenIncrementalCounterReducer.java

protected void reduce(Text key, Iterable<Text> values, Context context)
        throws java.io.IOException, InterruptedException {
    BigInteger partialCounter = BigInteger.valueOf(0);
    String lastResult = "";

    for (Text value : values) {
        NQueenCountRecord record = NQueenCountRecord.parse(value.toString(),
                NQueenIncrementalCounterMapper.QTD_POSICOES_PRESOLUCAO);

        if (record.isBranchSolved()) {
            if (record.getPartialSolutionText().compareTo(lastResult) > 0) {
                lastResult = record.getPartialSolutionText();
            }/*w w w .ja va2 s  . c o  m*/
            partialCounter = partialCounter.add(record.getSolutionsCount());
        } else {
            context.write(NullWritable.get(), value);
        }
    }

    if (partialCounter.compareTo(BigInteger.valueOf(0)) > 0) {
        String sumValue = key.toString() + "=" + partialCounter.toString() + ";";
        context.write(NullWritable.get(), new Text(sumValue));
    }
}

From source file:br.com.lassal.nqueens.grid.mapreduce.NQueenIncrementalCounterResultMapper.java

protected void map(LongWritable key, Text value, Context context)
        throws java.io.IOException, InterruptedException {

    NQueenCountRecord record = NQueenCountRecord.parse(value.toString(), 1);

    if (record.isBranchSolved()) {
        Text outKey = new Text(record.getPredicate());
        Text outValue = new Text(record.getSolutionsCount().toString());
        context.write(outKey, outValue);
    } else {/*w  w  w  .  j  a  va  2 s  .c o  m*/
        Text outKey = new Text(record.getPredicate());
        Text outValue = new Text(NQueenIncrementalCounterResultMapper.PARTIAL_SOLUTION_ID);
        context.write(outKey, outValue);

        if (record.getSolutionsCount().compareTo(BigInteger.ZERO) > 0) {
            outValue = new Text(record.getSolutionsCount().toString());
            context.write(outKey, outValue);
        }
    }
}