Search in sources :

Example 1 with ValueTypeSerializer

use of org.apache.stanbol.enhancer.nlp.json.valuetype.ValueTypeSerializer in project stanbol by apache.

the class AnalyzedTextSerializer method writeValue.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ObjectNode writeValue(Value<?> value) {
    ObjectNode jValue;
    Class<?> valueType = value.value().getClass();
    ValueTypeSerializer vts = valueTypeSerializerRegistry.getSerializer(valueType);
    if (vts != null) {
        jValue = vts.serialize(mapper, value.value());
    //TODO assert that jValue does not define "class" and "prob"!
    } else {
        //use the default binding and the "data" field
        jValue = mapper.createObjectNode();
        jValue.put("value", mapper.valueToTree(value.value()));
    }
    jValue.put("class", valueType.getName());
    if (value.probability() != Value.UNKNOWN_PROBABILITY) {
        jValue.put("prob", value.probability());
    }
    return jValue;
}
Also used : ValueTypeSerializer(org.apache.stanbol.enhancer.nlp.json.valuetype.ValueTypeSerializer) ObjectNode(org.codehaus.jackson.node.ObjectNode)

Aggregations

ValueTypeSerializer (org.apache.stanbol.enhancer.nlp.json.valuetype.ValueTypeSerializer)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1