org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.type.TypeReference Java Examples

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.type.TypeReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EvaluationUtil.java    From Alink with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the |label, probability| map
 *
 * @param row Input row, the second field is predDetail.
 * @return the  |label, probability| map.
 */
public static TreeMap<String, Double> extractLabelProbMap(Row row) {
    TreeMap<String, Double> labelProbMap;
    final String detailStr = row.getField(1).toString();
    try {
        labelProbMap = JsonConverter.fromJson(detailStr,
            new TypeReference<TreeMap<String, Double>>() {}.getType());
    } catch (Exception e) {
        throw new RuntimeException(
            String.format("Fail to deserialize detail column %s!", detailStr));
    }
    Collection<Double> probabilities = labelProbMap.values();
    probabilities.forEach(v ->
        Preconditions.checkArgument(v <= 1.0 && v >= 0,
            String.format("Probibality in %s not in range [0, 1]!", detailStr)));
    Preconditions.checkArgument(
        Math.abs(probabilities.stream().mapToDouble(Double::doubleValue).sum() - 1.0) < PROB_SUM_EPS,
        String.format("Probability sum in %s not equal to 1.0!", detailStr));
    return labelProbMap;
}
 
Example #2
Source File: SerializedValueSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	objectMapper = new ObjectMapper();
	final SimpleModule simpleModule = new SimpleModule();
	final JavaType serializedValueWildcardType = objectMapper
		.getTypeFactory()
		.constructType(new TypeReference<SerializedValue<?>>() {
		});
	simpleModule.addSerializer(new SerializedValueSerializer(serializedValueWildcardType));
	simpleModule.addDeserializer(
		SerializedValue.class,
		new SerializedValueDeserializer(serializedValueWildcardType));
	objectMapper.registerModule(simpleModule);
}
 
Example #3
Source File: SerializedValueSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationDeserialization() throws Exception {
	final String json = objectMapper.writeValueAsString(new SerializedValue<>(new TestClass()));

	final SerializedValue<TestClass> serializedValue =
		objectMapper.readValue(json, new TypeReference<SerializedValue<TestClass>>() {
		});
	final TestClass deserializedValue =
		serializedValue.deserializeValue(ClassLoader.getSystemClassLoader());

	assertEquals("baz", deserializedValue.foo);
	assertEquals(1, deserializedValue.bar);
}
 
Example #4
Source File: SerializedValueSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	objectMapper = new ObjectMapper();
	final SimpleModule simpleModule = new SimpleModule();
	final JavaType serializedValueWildcardType = objectMapper
		.getTypeFactory()
		.constructType(new TypeReference<SerializedValue<?>>() {
		});
	simpleModule.addSerializer(new SerializedValueSerializer(serializedValueWildcardType));
	simpleModule.addDeserializer(
		SerializedValue.class,
		new SerializedValueDeserializer(serializedValueWildcardType));
	objectMapper.registerModule(simpleModule);
}
 
Example #5
Source File: JobResultSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobResultSerializer() {
	super(JobResult.class);

	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueSerializer = new SerializedValueSerializer(objectSerializedValueType);
}
 
Example #6
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobResultDeserializer() {
	super(JobResult.class);
	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueDeserializer = new SerializedValueDeserializer(objectSerializedValueType);
}
 
Example #7
Source File: AggregatedMetricsResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatedMetricsResponseBody deserialize(
	JsonParser jsonParser,
	DeserializationContext deserializationContext) throws IOException {

	return new AggregatedMetricsResponseBody(jsonParser.readValueAs(
		new TypeReference<List<AggregatedMetric>>() {
		}));
}
 
Example #8
Source File: MetricCollectionResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public MetricCollectionResponseBody deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {

	return new MetricCollectionResponseBody(jsonParser.readValueAs(
		new TypeReference<List<Metric>>() {
		}));
}
 
Example #9
Source File: DocHashCountVectorizerModelDataConverter.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Override
public DocHashCountVectorizerModelData deserializeModel(Params meta, Iterable<String> data) {
    String modelString = data.iterator().next();
    DocHashCountVectorizerModelData modelData = new DocHashCountVectorizerModelData();
    modelData.idfMap = JsonConverter.fromJson(modelString,
        new TypeReference<HashMap<Integer, Double>>() {}.getType());
    modelData.numFeatures = meta.get(DocHashCountVectorizerTrainParams.NUM_FEATURES);
    modelData.minTF = meta.get(DocHashCountVectorizerTrainParams.MIN_TF);
    modelData.featureType = meta.get(DocHashCountVectorizerTrainParams.FEATURE_TYPE).name();
    return modelData;
}
 
Example #10
Source File: LdaUtil.java    From Alink with Apache License 2.0 5 votes vote down vote up
/**
 * Transform the input SparseVector data to HashMap in the predict process.
 */
public static HashMap<String, Tuple2<Integer, Double>> setWordIdWeightPredict(List<String> list) {
    int hashMapLength = list.size();
    final Type dataTuple3Type = new TypeReference<Tuple3<String, Double, Integer>>() {
    }.getType();
    HashMap<String, Tuple2<Integer, Double>> wordIdWeight = new HashMap<>(hashMapLength);
    for (String feature : list) {
        Tuple3<String, Double, Integer> t = JsonConverter.fromJson(feature, dataTuple3Type);
        wordIdWeight.put(t.f0, Tuple2.of(t.f2, t.f1));
    }
    return wordIdWeight;
}
 
Example #11
Source File: LdaUtil.java    From Alink with Apache License 2.0 5 votes vote down vote up
/**
 * Transform the input SparseVector data to HashMap in the train process.
 */
public static HashMap<Integer, String> setWordIdWeightTrain(List<String> list) {
    int hashMapLength = list.size();
    final Type DATA_TUPLE3_TYPE = new TypeReference<Tuple3<String, Double, Integer>>() {
    }.getType();
    HashMap<Integer, String> wordIdWeight = new HashMap<>(hashMapLength);
    for (String feature : list) {
        Tuple3<String, Double, Integer> t = JsonConverter.fromJson(feature, DATA_TUPLE3_TYPE);
        wordIdWeight.put(t.f2, t.f0);
    }
    return wordIdWeight;
}
 
Example #12
Source File: SerializedValueSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationDeserialization() throws Exception {
	final String json = objectMapper.writeValueAsString(new SerializedValue<>(new TestClass()));

	final SerializedValue<TestClass> serializedValue =
		objectMapper.readValue(json, new TypeReference<SerializedValue<TestClass>>() {
		});
	final TestClass deserializedValue =
		serializedValue.deserializeValue(ClassLoader.getSystemClassLoader());

	assertEquals("baz", deserializedValue.foo);
	assertEquals(1, deserializedValue.bar);
}
 
Example #13
Source File: MetricCollectionResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public MetricCollectionResponseBody deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {

	return new MetricCollectionResponseBody(jsonParser.readValueAs(
		new TypeReference<List<Metric>>() {
		}));
}
 
Example #14
Source File: JobResultSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobResultSerializer() {
	super(JobResult.class);

	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueSerializer = new SerializedValueSerializer(objectSerializedValueType);
}
 
Example #15
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobResultDeserializer() {
	super(JobResult.class);
	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueDeserializer = new SerializedValueDeserializer(objectSerializedValueType);
}
 
Example #16
Source File: AggregatedMetricsResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatedMetricsResponseBody deserialize(
	JsonParser jsonParser,
	DeserializationContext deserializationContext) throws IOException {

	return new AggregatedMetricsResponseBody(jsonParser.readValueAs(
		new TypeReference<List<AggregatedMetric>>() {
		}));
}
 
Example #17
Source File: MetricCollectionResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public MetricCollectionResponseBody deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {

	return new MetricCollectionResponseBody(jsonParser.readValueAs(
		new TypeReference<List<Metric>>() {
		}));
}
 
Example #18
Source File: SerializedValueSerializerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationDeserialization() throws Exception {
	final String json = objectMapper.writeValueAsString(new SerializedValue<>(new TestClass()));

	final SerializedValue<TestClass> serializedValue =
		objectMapper.readValue(json, new TypeReference<SerializedValue<TestClass>>() {
		});
	final TestClass deserializedValue =
		serializedValue.deserializeValue(ClassLoader.getSystemClassLoader());

	assertEquals("baz", deserializedValue.foo);
	assertEquals(1, deserializedValue.bar);
}
 
Example #19
Source File: SerializedValueSerializerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	objectMapper = new ObjectMapper();
	final SimpleModule simpleModule = new SimpleModule();
	final JavaType serializedValueWildcardType = objectMapper
		.getTypeFactory()
		.constructType(new TypeReference<SerializedValue<?>>() {
		});
	simpleModule.addSerializer(new SerializedValueSerializer(serializedValueWildcardType));
	simpleModule.addDeserializer(
		SerializedValue.class,
		new SerializedValueDeserializer(serializedValueWildcardType));
	objectMapper.registerModule(simpleModule);
}
 
Example #20
Source File: JobResultSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public JobResultSerializer() {
	super(JobResult.class);

	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueSerializer = new SerializedValueSerializer(objectSerializedValueType);
}
 
Example #21
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public JobResultDeserializer() {
	super(JobResult.class);
	final JavaType objectSerializedValueType = TypeFactory.defaultInstance()
		.constructType(new TypeReference<SerializedValue<Object>>() {
		});
	serializedValueDeserializer = new SerializedValueDeserializer(objectSerializedValueType);
}
 
Example #22
Source File: AggregatedMetricsResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatedMetricsResponseBody deserialize(
	JsonParser jsonParser,
	DeserializationContext deserializationContext) throws IOException {

	return new AggregatedMetricsResponseBody(jsonParser.readValueAs(
		new TypeReference<List<AggregatedMetric>>() {
		}));
}
 
Example #23
Source File: SerializedValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public SerializedValueSerializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}
 
Example #24
Source File: SerializedValueDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public SerializedValueDeserializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}
 
Example #25
Source File: SerializedValueSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public SerializedValueSerializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}
 
Example #26
Source File: SerializedValueDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public SerializedValueDeserializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}
 
Example #27
Source File: SerializedValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
public SerializedValueSerializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}
 
Example #28
Source File: SerializedValueDeserializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public SerializedValueDeserializer() {
	super(TypeFactory.defaultInstance().constructType(new TypeReference<SerializedValue<Object>>() {}));
}