HADOOP - Word Count Example for 1.2.1 Stable
Date : March 29 2020, 07:55 AM
this one helps. Which link have you followed? I have never seen this kind of WC. But whatever you have followed is definitely outdated since it is making use of the old API. And I doubt if you have followed it properly. This should work : public class WordCount {
/**
* The map class of WordCount.
*/
public static class TokenCounterMapper extends
Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
/**
* The reducer class of WordCount
*/
public static class TokenCounterReducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
}
}
/**
* The main entry point.
*/
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/core-site.xml"));
conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/hdfs-site.xml"));
conf.set("fs.default.name", "hdfs://localhost:9000");
conf.set("mapred.job.tracker", "localhost:9001");
Job job = new Job(conf, "WordCount");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenCounterMapper.class);
job.setReducerClass(TokenCounterReducer.class);
job.setNumReduceTasks(2);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("/inputs/demo.txt"));
FileOutputFormat.setOutputPath(job, new Path("/outputs/1111223"));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
|
Count is increasing then decreasing back to zero. Want a cumulative count
Date : March 29 2020, 07:55 AM
it fixes the issue You have return count at every for loop, you want to return only once after the for loop is done accumulating the count def checkForBubblesAbsorbed(balloon, bubbles, window):
count = 0
for bubble in bubbles:
collide = balloonBubbleCollide(balloon, bubble)
if collide == True:
count = count + 1
print(count)
# This return should be outside the for loop (you have an extra indent)
return count
cumulative_count = 0
def balloonBubbleCollide(...)
def checkForBubblesAbsorbed(...)
def somewhere(...)
cumulative_count += checkForBubblesAbsorbed(...)
|
PHP - How to get tweet count, following count, follower count and like count from Twitter REST api?
Tag : php , By : Don Changer
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Once you get the json response from Twitter, you treat it as an array and use foreach see example of a response array from Twitter Dev Doc see PHP Doc foreach $data = json_decode($follow_count, true);
<?php
$data = json_decode($follow_count, true);
print_r($data); // just checking, not needed later
foreach($data as $tweets) { // we run through the array
// here's an example of the structure and how you access it
// compare to the printed array if you need more information
$tweet = $tweets['text'];
$name = $tweets['user']['name'];
$turl = $tweets['user']['url'];
$followers = $tweets['user']['followers_count'];
$friends = $tweets['user']['friends_count'];
$likes = $tweets['user']['favourites_count'];
echo "Tweet: $tweet ($name / $turl) -> followed by : $followers -> friends: $friends -> likes: $likes<br />";
} // end of loop
?>
|
Difference between select count(*), count(0), count(100), count(Id) in SQL Server 2008?
Tag : sql , By : user104292
Date : March 29 2020, 07:55 AM
|
Badge Count is not increasing for push notification.always badge count remains 1?
Tag : ios , By : Gilmar Souza Jr.
Date : March 29 2020, 07:55 AM
|