ArrayList<StringTuple> specialChars = new ArrayList<>(); specialChars.add(new StringTuple("&", "&")); specialChars.add(new StringTuple("<", "<")); specialChars.add(new StringTuple(">", ">"));
public static void main(String[] args) { ArrayList<StringTuple> specialChars = new ArrayList<>(); specialChars.add(new StringTuple("&", "&")); specialChars.add(new StringTuple("<", "<")); specialChars.add(new StringTuple(">", ">")); System.out.println(replaceSpecialChars("Hi <Nishanth> How are &you !", specialChars)); }
@Override protected void map(Text key, Text value, Context context) throws IOException, InterruptedException { TokenStream stream = analyzer.tokenStream(key.toString(), new StringReader(value.toString())); CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class); stream.reset(); StringTuple document = new StringTuple(); while (stream.incrementToken()) { if (termAtt.length() > 0) { document.add(new String(termAtt.buffer(), 0, termAtt.length())); } } stream.end(); Closeables.close(stream, true); context.write(key, document); }
@Override protected void map(Text key, Text value, Context context) throws IOException, InterruptedException { TokenStream stream = analyzer.tokenStream(key.toString(), new StringReader(value.toString())); CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class); stream.reset(); StringTuple document = new StringTuple(); while (stream.incrementToken()) { if (termAtt.length() > 0) { document.add(new String(termAtt.buffer(), 0, termAtt.length())); } } stream.end(); Closeables.close(stream, true); context.write(key, document); }
@Override protected void map(Text key, Text value, Context context) throws IOException, InterruptedException { TokenStream stream = analyzer.tokenStream(key.toString(), new StringReader(value.toString())); CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class); stream.reset(); StringTuple document = new StringTuple(); while (stream.incrementToken()) { if (termAtt.length() > 0) { document.add(new String(termAtt.buffer(), 0, termAtt.length())); } } stream.end(); Closeables.close(stream, true); context.write(key, document); }
@Override protected void map(WritableComparable<?> key, VectorWritable value, Context context) throws IOException, InterruptedException { String keyName; Vector valVec = value.get(); if (valVec instanceof NamedVector) { keyName = ((NamedVector) valVec).getName(); } else { keyName = key.toString(); } for (NamedVector seedVector : seedVectors) { double distance = measure.distance(seedVector, valVec); if (!usesThreshold || distance <= maxDistance) { StringTuple outKey = new StringTuple(); outKey.add(seedVector.getName()); outKey.add(keyName); context.write(outKey, new DoubleWritable(distance)); } } }
@Override protected void map(WritableComparable<?> key, VectorWritable value, Context context) throws IOException, InterruptedException { String keyName; Vector valVec = value.get(); if (valVec instanceof NamedVector) { keyName = ((NamedVector) valVec).getName(); } else { keyName = key.toString(); } for (NamedVector seedVector : seedVectors) { double distance = measure.distance(seedVector, valVec); if (!usesThreshold || distance <= maxDistance) { StringTuple outKey = new StringTuple(); outKey.add(seedVector.getName()); outKey.add(keyName); context.write(outKey, new DoubleWritable(distance)); } } }
@Override protected void map(WritableComparable<?> key, VectorWritable value, Context context) throws IOException, InterruptedException { String keyName; Vector valVec = value.get(); if (valVec instanceof NamedVector) { keyName = ((NamedVector) valVec).getName(); } else { keyName = key.toString(); } for (NamedVector seedVector : seedVectors) { double distance = measure.distance(seedVector, valVec); if (!usesThreshold || distance <= maxDistance) { StringTuple outKey = new StringTuple(); outKey.add(seedVector.getName()); outKey.add(keyName); context.write(outKey, new DoubleWritable(distance)); } } }
StringTuple inputTuple = new StringTuple(); for (String i : input) { inputTuple.add(i);
StringTuple inputTuple = new StringTuple(); for (String i : input) { inputTuple.add(i);
Mapper<WritableComparable<?>, VectorWritable, StringTuple, DoubleWritable>.Context context = EasyMock.createMock(Mapper.Context.class); StringTuple tuple = new StringTuple(); tuple.add("foo"); tuple.add("123"); context.write(tuple, new DoubleWritable(Math.sqrt(2.0))); tuple = new StringTuple(); tuple.add("foo2"); tuple.add("123");