You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/10/07 20:04:37 UTC

[incubator-streampipes] 02/02: Remove DomainPropertyProbalilityList

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-438
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 5d85311f665a662f7f614cb99fc05503b10719d3
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Thu Oct 7 22:04:07 2021 +0200

    Remove DomainPropertyProbalilityList
---
 .../connect/adapter/guess/SchemaGuesser.java       | 101 +---------------
 .../streampipes/connect/adapter/guess/Mock.java    |  26 ----
 .../connect/adapter/guess/SchemaGuesserTest.java   | 132 ---------------------
 .../connect/guess/DomainPropertyProbability.java   |  53 ---------
 .../guess/DomainPropertyProbabilityList.java       |  56 ---------
 .../model/connect/guess/GuessSchema.java           |  30 +----
 .../sdk/builder/adapter/GuessSchemaBuilder.java    |  10 --
 7 files changed, 4 insertions(+), 404 deletions(-)

diff --git a/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesser.java b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesser.java
index ec561bd..53be8ab 100644
--- a/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesser.java
+++ b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesser.java
@@ -18,115 +18,16 @@
 
 package org.apache.streampipes.connect.adapter.guess;
 
-import org.apache.http.client.fluent.Form;
-import org.apache.http.client.fluent.Request;
-import org.apache.streampipes.model.connect.guess.DomainPropertyProbability;
-import org.apache.streampipes.model.connect.guess.DomainPropertyProbabilityList;
 import org.apache.streampipes.model.connect.guess.GuessSchema;
-import org.apache.streampipes.model.schema.EventProperty;
-import org.apache.streampipes.model.schema.EventPropertyNested;
 import org.apache.streampipes.model.schema.EventSchema;
-import org.apache.streampipes.serializers.json.GsonSerializer;
-
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
 
 public class SchemaGuesser {
 
-    public static int port = 80;
-
-    public static GuessSchema guessSchma(EventSchema eventSchema, List<Map<String, Object>> nElements) {
+    public static GuessSchema guessSchma(EventSchema eventSchema) {
         GuessSchema result = new GuessSchema();
 
-//        List<DomainPropertyProbabilityList> allDomainPropertyProbabilities = getDomainPropertyProbabitlyList(eventSchema.getEventProperties(), nElements, new ArrayList<>());
-
         result.setEventSchema(eventSchema);
-        result.setPropertyProbabilityList(new ArrayList<>());
-
-
-        return result;
-    }
-
-    private static List<DomainPropertyProbabilityList> getDomainPropertyProbabitlyList(List<EventProperty> eventProperties,
-                                                                                List<Map<String, Object>> nEventsParsed,
-                                                                                List<String> keys) {
-
-        List<DomainPropertyProbabilityList> result = new ArrayList<>();
-        for (EventProperty ep : eventProperties) {
-            if (ep instanceof EventPropertyNested) {
-                List<EventProperty> li = ((EventPropertyNested) ep).getEventProperties();
-                keys.add(ep.getRuntimeName());
-                result.addAll(getDomainPropertyProbabitlyList(li, nEventsParsed, keys));
-            } else {
-                List<Object> tmp = new ArrayList<>();
-                for (Map<String, Object> event : nEventsParsed) {
-                    Map<String, Object> subEvent = event;
-                    for (String k : keys) {
-                        subEvent = (Map<String, Object>) subEvent.get(k);
-                    }
-
-                    if (subEvent != null) {
-                        tmp.add(subEvent.get(ep.getRuntimeName()));
-                    }
-                }
-
-                DomainPropertyProbabilityList resultList = getDomainPropertyProbability(tmp.toArray());
-                resultList.setRuntimeName(ep.getRuntimeName());
-                result.add(resultList);
-            }
-
-        }
 
         return result;
     }
-
-    /**
-     * TODO replace this method, change python API to variables of DomainPropertyProbabilityList
-     * @param objects
-     * @return
-     */
-    public static PropertyGuessResults requestProbabilitiesObject(Object[] objects) {
-
-        String probabilitiesJsonString = requestProbabilitiesString(objects);
-        PropertyGuessResults res = GsonSerializer.getGsonWithIds().fromJson(probabilitiesJsonString,
-                PropertyGuessResults.class);
-        return res;
-    }
-
-    public static String requestProbabilitiesString(Object[] objects) {
-        String httpRequestBody = GsonSerializer.getGsonWithIds()
-                    .toJson(objects);
-
-        String httpResp = "{\"result\": []}";
-
-        try {
-            httpResp = Request.Post("http://localhost:" + port +"/predict")
-                        .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
-                        .bodyForm(Form.form().add("X", httpRequestBody).build()).execute().returnContent().asString();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-
-
-        return httpResp;
-    }
-
-    public static DomainPropertyProbabilityList getDomainPropertyProbability(Object[] sampleData) {
-        PropertyGuessResults pgr = requestProbabilitiesObject(sampleData);
-
-        DomainPropertyProbabilityList result = new DomainPropertyProbabilityList();
-
-
-        for (PropertyGuesses pg : pgr.getResult()) {
-            Double d = pg.getProbability();
-            result.addDomainPropertyProbability(new DomainPropertyProbability(pg.getClazz(), d.toString()));
-        }
-
-
-        return result;
-    }
-
 }
diff --git a/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/Mock.java b/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/Mock.java
deleted file mode 100644
index c72b4ac..0000000
--- a/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/Mock.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.connect.adapter.guess;
-
-public class Mock {
-    public static int PORT = 8042;
-
-    public static String HOST = "http://localhost:" + PORT;
-
-}
diff --git a/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesserTest.java b/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesserTest.java
deleted file mode 100644
index d8e2660..0000000
--- a/streampipes-connect/src/test/java/org/apache/streampipes/connect/adapter/guess/SchemaGuesserTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.connect.adapter.guess;
-
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class SchemaGuesserTest {
-
-    @Rule
-    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(Mock.PORT));
-
-    @Before
-    public void setPort() {
-        SchemaGuesser.port = Mock.PORT;
-    }
-
-    @Test
-    public void requestProbabilitiesStringTest() {
-
-        String expected = "{\"result\": []}";
-
-        stubFor(post(urlEqualTo("/predict"))
-                .willReturn(aResponse()
-                        .withStatus(200)
-                        .withBody(expected)));
-
-        SchemaGuesser schemaGuesser = new SchemaGuesser();
-
-        Double[] data = {1.1, 2.0};
-        String result = schemaGuesser.requestProbabilitiesString(data);
-
-        assertEquals(expected, result);
-
-    }
-
-    @Test
-    public void requestProbabilitiesStringEndpointNotAvailableTest() {
-
-        String expected = "{\"result\": []}";
-
-        stubFor(post(urlEqualTo("/predict"))
-                .willReturn(aResponse()
-                        .withStatus(404)));
-
-        SchemaGuesser schemaGuesser = new SchemaGuesser();
-
-        Double[] data = {1.1, 2.0};
-        String result = schemaGuesser.requestProbabilitiesString(data);
-
-        assertEquals(expected, result);
-
-    }
-
-//    @Test
-//    public void getDomainPropertyProbabilityTest() {
-//
-//        String payload = "{\n" +
-//                "  \"result\": [\n" +
-//                "    {\n" +
-//                "      \"class\": \"one\", \n" +
-//                "      \"probability\": 1.1\n" +
-//                "    }]}";
-//
-//        stubFor(post(urlEqualTo("/predict"))
-//                .willReturn(aResponse()
-//                        .withStatus(200)
-//                        .withBody(payload)));
-//
-//
-//        String[] data = {"a"};
-//        DomainPropertyProbabilityList result = SchemaGuesser.getDomainPropertyProbability(data);
-//
-//        assertNotNull(result.getList());
-//        assertEquals(1, result.getList().size());
-//        assertEquals("one", result.getList().get(0).getDomainProperty());
-//        assertEquals("1.1", result.getList().get(0).getProbability());
-//    }
-
-    @Test
-    public void requestProbabilitiesObjectTest() {
-
-        String payload = "{\n" +
-                "  \"result\": [\n" +
-                "    {\n" +
-                "      \"class\": \"one\", \n" +
-                "      \"probability\": 1\n" +
-                "    }]}";
-
-        stubFor(post(urlEqualTo("/predict"))
-                        .willReturn(aResponse()
-                        .withStatus(200)
-                        .withBody(payload)
-                                ));
-
-
-        SchemaGuesser schemaGuesser = new SchemaGuesser();
-
-        Double[] data = {1.1};
-        PropertyGuessResults result = schemaGuesser.requestProbabilitiesObject(data);
-
-        assertNotNull(result.getResult());
-        assertEquals(1, result.getResult().length);
-        assertEquals("one", result.getResult()[0].getClazz());
-        assertEquals(1, result.getResult()[0].getProbability(), 0.0);
-    }
-
-
-}
\ No newline at end of file
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbability.java b/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbability.java
deleted file mode 100644
index 17d04af..0000000
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbability.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.model.connect.guess;
-
-import org.apache.streampipes.model.base.UnnamedStreamPipesEntity;
-
-public class DomainPropertyProbability extends UnnamedStreamPipesEntity {
-
-    private String domainProperty;
-
-    private String probability;
-
-    public DomainPropertyProbability() {
-        super();
-    }
-
-    public DomainPropertyProbability(String domainProperty,  String probability) {
-        this.domainProperty = domainProperty;
-        this.probability = probability;
-    }
-
-    public String getDomainProperty() {
-        return domainProperty;
-    }
-
-    public void setDomainProperty(String domainProperty) {
-        this.domainProperty = domainProperty;
-    }
-
-    public String getProbability() {
-        return probability;
-    }
-
-    public void setProbability(String probability) {
-        this.probability = probability;
-    }
-}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbabilityList.java b/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbabilityList.java
deleted file mode 100644
index 9727ae1..0000000
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/DomainPropertyProbabilityList.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.model.connect.guess;
-
-import org.apache.streampipes.model.base.UnnamedStreamPipesEntity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class DomainPropertyProbabilityList extends UnnamedStreamPipesEntity {
-
-    private String runtimeName;
-
-    private List<DomainPropertyProbability> list;
-
-    public DomainPropertyProbabilityList() {
-        super();
-        list = new ArrayList<>();
-    }
-
-    public List<DomainPropertyProbability> getList() {
-        return list;
-    }
-
-    public void setList(List<DomainPropertyProbability> list) {
-        this.list = list;
-    }
-
-    public String getRuntimeName() {
-        return runtimeName;
-    }
-
-    public void setRuntimeName(String runtimeName) {
-        this.runtimeName = runtimeName;
-    }
-
-    public void addDomainPropertyProbability(DomainPropertyProbability property) {
-        this.list.add(property);
-    }
-}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/GuessSchema.java b/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/GuessSchema.java
index c4610d3..4bda9da 100644
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/GuessSchema.java
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/connect/guess/GuessSchema.java
@@ -22,36 +22,19 @@ import org.apache.streampipes.model.base.UnnamedStreamPipesEntity;
 import org.apache.streampipes.model.schema.EventSchema;
 import org.apache.streampipes.model.shared.annotation.TsModel;
 
-import java.util.ArrayList;
-import java.util.List;
-
 @TsModel
 public class GuessSchema extends UnnamedStreamPipesEntity {
 
     public EventSchema eventSchema;
 
-    public List<DomainPropertyProbabilityList> propertyProbabilityList;
-
     public GuessSchema() {
         super();
-        this.propertyProbabilityList = new ArrayList<>();
-
-
     }
 
-    public GuessSchema(EventSchema schema, List<DomainPropertyProbabilityList> propertyProbabilityList) {
-        super();
-        this.eventSchema = schema;
-        this.propertyProbabilityList = propertyProbabilityList;
+    public GuessSchema(GuessSchema other) {
+        super(other);
+        this.eventSchema = other.getEventSchema() != null ? new EventSchema(other.getEventSchema()) : null;
     }
-
-	public GuessSchema(GuessSchema other) {
-		super(other);
-		this.eventSchema = other.getEventSchema() != null ? new EventSchema(other.getEventSchema()) : null;
-	}
-
-
-
     public EventSchema getEventSchema() {
         return eventSchema;
     }
@@ -60,11 +43,4 @@ public class GuessSchema extends UnnamedStreamPipesEntity {
         this.eventSchema = eventSchema;
     }
 
-    public List<DomainPropertyProbabilityList> getPropertyProbabilityList() {
-        return propertyProbabilityList;
-    }
-
-    public void setPropertyProbabilityList(List<DomainPropertyProbabilityList> propertyProbabilityList) {
-        this.propertyProbabilityList = propertyProbabilityList;
-    }
 }
diff --git a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/adapter/GuessSchemaBuilder.java b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/adapter/GuessSchemaBuilder.java
index 798dabe..91e0da1 100644
--- a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/adapter/GuessSchemaBuilder.java
+++ b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/adapter/GuessSchemaBuilder.java
@@ -17,7 +17,6 @@
  */
 package org.apache.streampipes.sdk.builder.adapter;
 
-import org.apache.streampipes.model.connect.guess.DomainPropertyProbabilityList;
 import org.apache.streampipes.model.connect.guess.GuessSchema;
 import org.apache.streampipes.model.schema.EventProperty;
 import org.apache.streampipes.model.schema.EventSchema;
@@ -28,11 +27,9 @@ import java.util.List;
 public class GuessSchemaBuilder {
 
   private List<EventProperty> eventProperties;
-  private List<DomainPropertyProbabilityList> domainPropertyProbabilitiesList;
 
   private GuessSchemaBuilder() {
     this.eventProperties = new ArrayList<>();
-    this.domainPropertyProbabilitiesList = new ArrayList<>();
   }
 
   /**
@@ -48,12 +45,6 @@ public class GuessSchemaBuilder {
     return this;
   }
 
-  public GuessSchemaBuilder domainPropertyProbability(DomainPropertyProbabilityList domainPropertyProbabilityList) {
-    this.domainPropertyProbabilitiesList.add(domainPropertyProbabilityList);
-
-    return this;
-  }
-
   public GuessSchema build() {
     GuessSchema guessSchema = new GuessSchema();
     EventSchema eventSchema = new EventSchema();
@@ -65,7 +56,6 @@ public class GuessSchemaBuilder {
     eventSchema.setEventProperties(eventProperties);
 
     guessSchema.setEventSchema(eventSchema);
-    guessSchema.setPropertyProbabilityList(domainPropertyProbabilitiesList);
 
     return guessSchema;
   }