Package org.apache.mahout.math

Examples of org.apache.mahout.math.JsonVectorAdapter


  private static final Logger log = LoggerFactory.getLogger(JsonClusterAdapter.class);
 
  @Override
  public JsonElement serialize(DirichletCluster<?> src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("total", new JsonPrimitive(src.getTotalCount()));
    obj.add("modelClass", new JsonPrimitive(src.getModel().getClass().getName()));
    obj.add("modelJson", new JsonPrimitive(gson.toJson(src)));
View Full Code Here


  @Override
  public DirichletCluster<?> deserialize(JsonElement json,
                                         Type typeOfT,
                                         JsonDeserializationContext context) throws JsonParseException {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    double total = obj.get("total").getAsDouble();
    String klass = obj.get("modelClass").getAsString();
    String modelJson = obj.get("modelJson").getAsString();
View Full Code Here

 
  @Override
  public String asJsonString() {
    Type vectorType = new TypeToken<Vector>() { }.getType();
    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = gBuilder.create();
    return gson.toJson(this, this.getClass());
  }
View Full Code Here

  private static final Logger log = LoggerFactory.getLogger(JsonModelAdapter.class);
 
  @Override
  public JsonElement serialize(Model<?> src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
View Full Code Here

 
  @Override
  public Model<?> deserialize(JsonElement json, Type typeOfT,
                              JsonDeserializationContext context) throws JsonParseException {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get("class").getAsString();
    String model = obj.get("model").getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
View Full Code Here

  private static final Logger log = LoggerFactory.getLogger(JsonModelDistributionAdapter.class);

  @Override
  public JsonElement serialize(ModelDistribution<?> src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
View Full Code Here

  }

  @Override
  public ModelDistribution<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get("class").getAsString();
    String model = obj.get("model").getAsString();
View Full Code Here

  private static final Logger log = LoggerFactory.getLogger(JsonModelAdapter.class);
 
  @Override
  public JsonElement serialize(Model<?> src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
View Full Code Here

 
  @Override
  public Model<?> deserialize(JsonElement json, Type typeOfT,
                              JsonDeserializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get("class").getAsString();
    String model = obj.get("model").getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
View Full Code Here

  private static final Logger log = LoggerFactory.getLogger(JsonDistanceMeasureAdapter.class);

  @Override
  public JsonElement serialize(DistanceMeasure src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.JsonVectorAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.