List of usage examples for org.apache.hadoop.io Text toString
@Override
public String toString()
From source file:Assignment4_P4_MemoryConscious.MovieRatingMemConscious_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] movieInfo = value.toString().split("::"); if (!movieInfo[1].trim().toLowerCase().equals("movieid")) { // extract movieID and rating movieID = new IntWritable(Integer.parseInt(movieInfo[1])); rating = new FloatWritable(Float.parseFloat(movieInfo[2])); // push rating in sorted hashmap outSortMap.put(rating, ONE);//w ww . j a v a 2 s . com // send this fellow to combiner now, come on, do it bleeeeeedy context.write(movieID, outSortMap); } }
From source file:Assignment5_P2_DistinctIPAddress.DistinctIPAddress_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] ipInfo = value.toString().split("-"); ipaddr = new Text(ipInfo[0].trim()); context.write(ipaddr, NullWritable.get()); }
From source file:Assignment5_P3_PartitionPattern.Partition_IPAddress_By_Month_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] ipInfo = value.toString().split("-"); String timing = ipInfo[2].trim(); String[] cDate = timing.split(":"); String createDate = cDate[0].substring(1, cDate[0].length()).trim();//System.out.println("Date found : '" + createDate + "'"); Calendar cal = Calendar.getInstance(); try {/*from ww w. ja v a 2 s. c o m*/ cal.setTime(fmt.parse(createDate)); //System.out.println("Month evaluated by format : " + fmt.parse(createDate)); //System.out.println("Month evaluated by cal : " + cal.get(Calendar.MONTH)); createMonth.set(cal.get(Calendar.MONTH)); } catch (ParseException e) { e.printStackTrace(); } //System.out.println("CREATE MONTH " + createMonth); context.write(createMonth, value); }
From source file:Assignment5_P4_BinningPattern.Binning_IPAddress_By_Day_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] ipInfo = value.toString().split("-"); String timing = ipInfo[2].trim(); String createDate = timing.substring(1, timing.length()).trim();//System.out.println("Date found : '" + createDate + "'"); Calendar cal = Calendar.getInstance(); try {//www . j av a 2 s. c om cal.setTime(fmt.parse(createDate)); //System.out.println("Month evaluated by format : " + fmt.parse(createDate)); //System.out.println("Month evaluated by cal : " + cal.get(Calendar.MONTH)); createHour.set(cal.get(Calendar.HOUR_OF_DAY)); multipleOutputs.write("textualBins", NullWritable.get(), value, createHour + "-hour"); multipleOutputs.write("massaBins", NullWritable.get(), value, createHour + "-trial-by-witnessing"); } catch (ParseException e) { e.printStackTrace(); } }
From source file:Assignment5_P6_StructureToHierarchyPattern.Structure_Hierarchy_Movie_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] movieInfo = value.toString().split(","); String movieId = movieInfo[0]; //append 'T' for title identification String movieTitle = "T" + movieInfo[1]; // movieID, movieTitle context.write(new Text(movieId), new Text(movieTitle)); }
From source file:Assignment5_P6_StructureToHierarchyPattern.Structure_Hierarchy_Reducer.java
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { sb.append("<Movie>"); for (Text value : values) { if (value.toString().charAt(0) == 'T' && count < 1) { String title = value.toString().substring(1, value.toString().length()).trim(); // put it in a tag sb.append("<Title>").append(title).append("</Title>"); // in count so next time it doesnt come in count++;//from w w w . j a v a 2 s. c o m } else { String tag = value.toString().substring(1, value.toString().length()).trim(); // call genre fellow constructPropertyXml(tag); } } sb.append("</Movie>"); context.write(null, new Text(sb.toString())); }
From source file:Assignment5_P6_StructureToHierarchyPattern.Structure_Hierarchy_Tag_Mapper.java
public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] movieInfo = value.toString().split(","); String movieId = movieInfo[1]; //append 'A' for tag identification String movieTag = "A" + movieInfo[2]; // movieID, movieTag context.write(new Text(movieId), new Text(movieTag)); }
From source file:at.illecker.hama.hybrid.examples.onlinecf.OnlineCF.java
License:Apache License
@Override public boolean load(String path, boolean lazy) { this.m_isLazyLoadModel = lazy; this.m_modelPath = path; if (lazy == false) { Path dataPath = new Path(m_modelPath); Configuration conf = new Configuration(); try {/* w ww . ja v a 2 s . c om*/ FileSystem fs = dataPath.getFileSystem(conf); LinkedList<Path> files = new LinkedList<Path>(); if (!fs.exists(dataPath)) { this.m_isLazyLoadModel = false; this.m_modelPath = null; return false; } if (!fs.isFile(dataPath)) { for (int i = 0; i < 100000; i++) { Path partFile = new Path( m_modelPath + "/part-" + String.valueOf(100000 + i).substring(1, 6)); if (fs.exists(partFile)) { files.add(partFile); } else { break; } } } else { files.add(dataPath); } LOG.info("loading model from " + path); for (Path file : files) { SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); Text key = new Text(); PipesVectorWritable value = new PipesVectorWritable(); String strKey = null; Long actualKey = null; String firstSymbol = null; while (reader.next(key, value) != false) { strKey = key.toString(); firstSymbol = strKey.substring(0, 1); try { actualKey = Long.valueOf(strKey.substring(1)); } catch (Exception e) { actualKey = new Long(0); } if (firstSymbol.equals(OnlineCF.DFLT_MODEL_ITEM_DELIM)) { // LOG.info("loaded itemId: " + actualKey + " itemVector: " // + value.getVector()); m_modelItemFactorizedValues.put(actualKey, new PipesVectorWritable(value)); } else if (firstSymbol.equals(OnlineCF.DFLT_MODEL_USER_DELIM)) { // LOG.info("loaded userId: " + actualKey + " userVector: " // + value.getVector()); m_modelUserFactorizedValues.put(actualKey, new PipesVectorWritable(value)); } else { // unknown continue; } } reader.close(); } LOG.info("loaded: " + m_modelUserFactorizedValues.size() + " users, " + m_modelItemFactorizedValues.size() + " items"); // for (Long user : m_modelUserFactorizedValues.keySet()) { // LOG.info("userId: " + user + " userVector: " // + m_modelUserFactorizedValues.get(user)); // } // for (Long item : m_modelItemFactorizedValues.keySet()) { // LOG.info("itemId: " + item + " itemVector: " // + m_modelItemFactorizedValues.get(item)); // } } catch (Exception e) { e.printStackTrace(); this.m_isLazyLoadModel = false; this.m_modelPath = null; return false; } } return true; }
From source file:at.illecker.hama.hybrid.examples.summation.SummationBSP.java
License:Apache License
@Override public void bsp(BSPPeer<Text, Text, Text, DoubleWritable, DoubleWritable> peer) throws IOException, SyncException, InterruptedException { BSPJob job = new BSPJob((HamaConfiguration) peer.getConfiguration()); FileSystem fs = FileSystem.get(peer.getConfiguration()); FSDataOutputStream outStream = fs/*from w w w. ja va 2 s .c o m*/ .create(new Path(FileOutputFormat.getOutputPath(job), peer.getTaskId() + ".log")); outStream.writeChars("SummationBSP.bsp executed on CPU!\n"); double intermediateSum = 0.0; Text key = new Text(); Text value = new Text(); while (peer.readNext(key, value)) { outStream.writeChars("SummationBSP.bsp key: " + key + " value: " + value + "\n"); intermediateSum += Double.parseDouble(value.toString()); } outStream.writeChars("SummationBSP.bsp send intermediateSum: " + intermediateSum + "\n"); peer.send(m_masterTask, new DoubleWritable(intermediateSum)); peer.sync(); // Consume messages if (peer.getPeerName().equals(m_masterTask)) { outStream.writeChars("SummationBSP.bsp consume messages...\n"); double sum = 0.0; int msg_count = peer.getNumCurrentMessages(); for (int i = 0; i < msg_count; i++) { DoubleWritable msg = peer.getCurrentMessage(); outStream.writeChars("SummationBSP.bsp message: " + msg.get() + "\n"); sum += msg.get(); } outStream.writeChars("SummationBSP.bsp write Sum: " + sum + "\n"); peer.write(new Text("Sum"), new DoubleWritable(sum)); } outStream.close(); }
From source file:authordetect.input.SingleBookReader.java
private boolean containsTitleOrAuthor(Text line, int option) throws IOException { String lineString = line.toString(); String target;/* w w w. j a va 2s. com*/ if (option == 0) { target = "Author"; if (lineString.startsWith(target)) { title = lineString.split(":")[1].substring(1); return true; } else { return false; } } else { target = "Title"; if (lineString.startsWith(target)) { title = lineString.split(":")[1].substring(1); } if (lineString.startsWith("Author")) { String author = lineString.split(":")[1].substring(1); title = title.concat("_" + author); return true; } return false; } }