You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2021/05/27 19:28:44 UTC
[incubator-streampipes] branch dev updated: [STREAMPIPES-377]
Remove obsolete code from storage-rdf4j module and corresponding REST
interfaces
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 53010ee [STREAMPIPES-377] Remove obsolete code from storage-rdf4j module and corresponding REST interfaces
53010ee is described below
commit 53010ee8c7340517a3fcc798f91cf8875a5ceb98
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Thu May 27 21:28:24 2021 +0200
[STREAMPIPES-377] Remove obsolete code from storage-rdf4j module and corresponding REST interfaces
---
.../backend/StreamPipesResourceConfig.java | 2 -
.../model/client/messages/AutocompleteItem.java | 52 ---
.../model/client/messages/AutocompleteResult.java | 51 ---
.../apache/streampipes/rest/impl/AutoComplete.java | 46 +-
.../streampipes/rest/impl/OntologyContext.java | 75 ----
.../streampipes/rest/impl/OntologyKnowledge.java | 270 ------------
.../streampipes/storage/api/ITripleStorage.java | 2 -
.../storage/management/StorageManager.java | 14 +-
.../streampipes/storage/Rdf4JStorageManager.java | 38 +-
.../storage/rdf4j/config/Rdf4JConfig.java | 4 -
.../rdf4j/filter/BackgroundKnowledgeFilter.java | 84 ----
.../streampipes/storage/rdf4j/filter/Filter.java | 15 +-
.../rdf4j/impl/BackgroundKnowledgeStorageImpl.java | 467 ---------------------
.../storage/rdf4j/impl/ContextStorageImpl.java | 131 ------
.../rdf4j/ontology/ClassHierarchyExecutor.java | 116 -----
.../rdf4j/ontology/ConceptUpdateExecutor.java | 52 ---
.../rdf4j/ontology/InstanceUpdateExecutor.java | 51 ---
.../rdf4j/ontology/PropertyUpdateExecutor.java | 48 ---
.../storage/rdf4j/ontology/QueryExecutor.java | 62 ---
.../storage/rdf4j/ontology/RangeQueryExecutor.java | 149 -------
.../storage/rdf4j/ontology/UpdateExecutor.java | 37 --
.../storage/rdf4j/sparql/QueryBuilder.java | 294 +------------
.../rdf4j/util/BackgroundKnowledgeUtils.java | 92 ----
23 files changed, 22 insertions(+), 2130 deletions(-)
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
index f2fd784..eabd8fc 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
@@ -66,8 +66,6 @@ public class StreamPipesResourceConfig extends ResourceConfig {
register(LabelResource.class);
register(MeasurementUnitResource.class);
register(Notification.class);
- register(OntologyContext.class);
- register(OntologyKnowledge.class);
register(OntologyMeasurementUnit.class);
register(OntologyPipelineElement.class);
register(PipelineCanvasMetadataCache.class);
diff --git a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteItem.java b/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteItem.java
deleted file mode 100644
index 612eacb..0000000
--- a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteItem.java
+++ /dev/null
@@ -1,52 +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.client.messages;
-
-public class AutocompleteItem {
-
- private String label;
- private String value;
-
-
- public AutocompleteItem(String label, String value) {
- super();
- this.label = label;
- this.value = value;
- }
-
-
- public String getLabel() {
- return label;
- }
-
-
- public void setLabel(String label) {
- this.label = label;
- }
-
-
- public String getValue() {
- return value;
- }
-
-
- public void setValue(String value) {
- this.value = value;
- }
-}
diff --git a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteResult.java b/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteResult.java
deleted file mode 100644
index 33765fd..0000000
--- a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/messages/AutocompleteResult.java
+++ /dev/null
@@ -1,51 +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.client.messages;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class AutocompleteResult {
-
- List<AutocompleteItem> result;
-
- public AutocompleteResult(List<AutocompleteItem> result)
- {
- this.result = result;
- }
-
- public AutocompleteResult()
- {
- this.result = new ArrayList<>();
- }
-
- public List<AutocompleteItem> getResult() {
- return result;
- }
-
- public void setResult(List<AutocompleteItem> result) {
- this.result = result;
- }
-
- public void add(AutocompleteItem item)
- {
- this.result.add(item);
- }
-
-}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java
index 172f0a0..7253fd6 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java
@@ -18,20 +18,12 @@
package org.apache.streampipes.rest.impl;
-import org.apache.streampipes.model.client.messages.AutocompleteItem;
-import org.apache.streampipes.model.client.messages.AutocompleteResult;
-import org.apache.streampipes.model.client.ontology.OntologyQuery;
-import org.apache.streampipes.storage.management.StorageManager;
-import org.apache.streampipes.storage.rdf4j.ontology.QueryExecutor;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
import org.apache.streampipes.vocabulary.SemanticTypeRegistry;
-import org.eclipse.rdf4j.query.BindingSet;
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.TupleQueryResult;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import javax.ws.rs.*;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -39,36 +31,6 @@ import javax.ws.rs.core.Response;
public class AutoComplete extends AbstractRestResource {
@GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getItem(@QueryParam("propertyName") String propertyName, @QueryParam("term") String term) {
- AutocompleteResult result = new AutocompleteResult();
- String query = QueryBuilder.getAutocompleteSuggestion(propertyName);
-
- try {
- TupleQueryResult queryResult = new QueryExecutor(StorageManager.INSTANCE.getRepository()).executeQuery(query);
- while (queryResult.hasNext()) {
- BindingSet set = queryResult.next();
- AutocompleteItem item = new AutocompleteItem(set.getValue("label").stringValue(), set.getValue("value").stringValue());
- if (item.getLabel().startsWith(term)) result.add(item);
- }
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
-
- e.printStackTrace();
- }
- return ok(result);
- }
-
- @POST
- @Path("/domain")
- @Produces(MediaType.APPLICATION_JSON)
- public Response getOntologyQueryResult(OntologyQuery ontologyQuery) {
- return ok(StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage().getOntologyResult(ontologyQuery));
- }
-
- @GET
@Path("semantic-type")
@Produces(MediaType.APPLICATION_JSON)
public Response getSemanticTypes(@QueryParam("text") String text) {
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyContext.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyContext.java
deleted file mode 100644
index 7557bcd..0000000
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyContext.java
+++ /dev/null
@@ -1,75 +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.rest.impl;
-
-import org.apache.streampipes.model.client.ontology.Context;
-import org.apache.streampipes.model.message.Notifications;
-import org.apache.streampipes.storage.management.StorageManager;
-import org.glassfish.jersey.media.multipart.FormDataParam;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.InputStream;
-
-@Path("/v2/contexts")
-public class OntologyContext extends AbstractRestResource {
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getAvailableContexts() {
- return ok(StorageManager
- .INSTANCE
- .getContextStorage()
- .getAvailableContexts());
- }
-
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.MULTIPART_FORM_DATA)
- public Response addContext(@FormDataParam("file") InputStream inputFile, @FormDataParam("context") Context contextInfo) {
-
- contextInfo.setInputStream(inputFile);
-
- boolean success = StorageManager
- .INSTANCE
- .getContextStorage()
- .addContext(contextInfo);
- if (success) {
- return ok(Notifications.success("Context successfully added."));
- }
- else {
- return ok(Notifications.error("Could not add context."));
- }
- }
-
- @DELETE
- @Path("/{contextId}")
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteContext(@PathParam("contextId") String contextId) {
- boolean success = StorageManager.INSTANCE.getContextStorage().deleteContext(contextId);
- if (success) {
- return ok(Notifications.success("Context successfully deleted."));
- }
- else {
- return ok(Notifications.error("Could not delete context."));
- }
- }
-
-}
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyKnowledge.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyKnowledge.java
deleted file mode 100644
index 8e05645..0000000
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/OntologyKnowledge.java
+++ /dev/null
@@ -1,270 +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.rest.impl;
-
-import org.apache.streampipes.model.client.ontology.*;
-import org.apache.streampipes.model.message.Notifications;
-import org.apache.streampipes.storage.management.StorageManager;
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.repository.RepositoryException;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("/v2/ontology")
-public class OntologyKnowledge extends AbstractRestResource {
-
- @Path("/types")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getTypeHiearchy() {
- try {
- return ok(StorageManager.INSTANCE.getBackgroundKnowledgeStorage().getClassHierarchy());
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- return null;
- }
-
- }
-
- @Path("/properties")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getPropertyHierarchy() {
- try {
- return ok(StorageManager.INSTANCE.getBackgroundKnowledgeStorage().getPropertyHierarchy());
- } catch (RepositoryException | MalformedQueryException
- | QueryEvaluationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- @Path("/properties/{propertyId}")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getProperty(@PathParam("propertyId") String propertyId) {
- try {
- return ok(StorageManager.INSTANCE.getBackgroundKnowledgeStorage().getProperty(propertyId));
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- return ok(Notifications.error("Could not load details"));
- }
- }
-
- @Path("/types/{typeId}")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getType(@PathParam("typeId") String typeId) {
- try {
- return ok(StorageManager.INSTANCE.getBackgroundKnowledgeStorage().getConcept(typeId));
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return ok(typeId);
- }
-
- @Path("/namespaces")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getNamespaces() {
- try {
- return ok(StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .getNamespaces());
- } catch (RepositoryException e) {
- e.printStackTrace();
- return ok(Notifications.error("Could not connect to Sesame storage"));
- }
- }
-
- @Path("/namespaces")
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- public Response addNamespace(Namespace namespace) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .addNamespace(namespace);
- if (success) {
- return ok(Notifications.success("Namespace successfully added."));
- }
- else {
- return ok(Notifications.error("Could not add namespace. "));
- }
- }
-
- @Path("/namespaces/{prefix}")
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteNamespace(@PathParam("prefix") String prefix) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .deleteNamespace(prefix);
- if (success) {
- return ok(Notifications.success("Namespace successfully removed."));
- }
- else {
- return ok(Notifications.error("Could not remove namespace. "));
- }
- }
-
- @Path("/properties")
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- public Response addProperty(Resource elementData) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .addProperty(elementData);
- if (success) {
- return ok(Notifications.success("Property successfully added."));
- }
- else {
- return ok(Notifications.error("Could not add property. "));
- }
- }
-
- @Path("/types")
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- public Response addType(Resource elementData) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .addConcept(elementData);
- if (success) {
- return ok(Notifications.success("Concept successfully added."));
- }
- else {
- return ok(Notifications.error("Could not add concept. "));
- }
- }
-
- @Path("/instances")
- @POST
- @Produces(MediaType.APPLICATION_JSON)
- public Response addInstance(Resource elementData) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .addIndividual(elementData);
- if (success) {
- return ok(Notifications.success("Instance successfully added."));
- }
- else {
- return ok(Notifications.error("Could not add instance. "));
- }
- }
-
- @Path("/properties/{propertyId}")
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateProperty(@PathParam("propertyId") String propertyId, Property propertyData) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .updateProperty(propertyData);
- if (success) {
- return ok(Notifications.success("Property successfully updated."));
- }
- else {
- return ok(Notifications.error("Could not update property. "));
- }
-
- }
-
- @Path("/types/{typeId}")
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateType(@PathParam("typeId") String typeId, Concept concept) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .updateConcept(concept);
- if (success) {
- return ok(Notifications.success("Concept successfully updated."));
- }
- else {
- return ok(Notifications.error("Could not update concept. "));
- }
- }
-
- @Path("/instances/{instanceId}")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Response getInstance(@PathParam("instanceId") String instanceId) {
- try {
- return ok(StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .getInstance(instanceId));
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- return ok(Notifications.error("Instance not found"));
- }
- }
-
- @Path("/instances/{instanceId}")
- @PUT
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateInstance(@PathParam("instanceId") String instanceId, Instance instance) {
- boolean success = StorageManager
- .INSTANCE
- .getBackgroundKnowledgeStorage()
- .updateInstance(instance);
- if (success) return ok(Notifications.success("Instance successfully updated."));
- else return ok(Notifications.error("Could not update instance. "));
- }
-
- @Path("/properties/{propertyId}")
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteProperty(@PathParam("propertyId") String propertyId) {
- boolean success = StorageManager.INSTANCE.getBackgroundKnowledgeStorage().deleteResource(propertyId);
- if (success) return ok(Notifications.success("Property successfully deleted."));
- else return ok(Notifications.error("Could not delete property. "));
- }
-
- @Path("/types/{typeId}")
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteType(@PathParam("typeId") String typeId) {
- boolean success = StorageManager.INSTANCE.getBackgroundKnowledgeStorage().deleteResource(typeId);
- if (success) return ok(Notifications.success("Concept successfully deleted."));
- else return ok(Notifications.error("Could not delete concept. "));
- }
-
- @Path("/instances/{instanceId}")
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteInstance(@PathParam("instanceId") String instanceId) {
- boolean success = StorageManager.INSTANCE.getBackgroundKnowledgeStorage().deleteResource(instanceId);
- if (success) return ok(Notifications.success("Instance successfully deleted."));
- else return ok(Notifications.error("Could not delete instance. "));
- }
-
-}
diff --git a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ITripleStorage.java b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ITripleStorage.java
index 35b8166..242b6c0 100644
--- a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ITripleStorage.java
+++ b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ITripleStorage.java
@@ -27,6 +27,4 @@ public interface ITripleStorage {
IPipelineElementDescriptionStorageCache getPipelineElementStorage();
- IOntologyContextStorage getContextStorage();
-
}
diff --git a/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java b/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java
index 8fbe269..fb46f04 100644
--- a/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java
+++ b/streampipes-storage-management/src/main/java/org/apache/streampipes/storage/management/StorageManager.java
@@ -18,11 +18,9 @@
package org.apache.streampipes.storage.management;
-import org.eclipse.rdf4j.repository.Repository;
import org.apache.streampipes.storage.Rdf4JStorageManager;
-import org.apache.streampipes.storage.api.IBackgroundKnowledgeStorage;
-import org.apache.streampipes.storage.api.IOntologyContextStorage;
import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorageCache;
+import org.eclipse.rdf4j.repository.Repository;
public enum StorageManager {
@@ -32,18 +30,8 @@ public enum StorageManager {
return Rdf4JStorageManager.INSTANCE.getPipelineElementStorage();
}
- public IBackgroundKnowledgeStorage getBackgroundKnowledgeStorage() {
- return Rdf4JStorageManager.INSTANCE.getBackgroundKnowledgeStorage();
- }
-
public Repository getRepository() {
return Rdf4JStorageManager.INSTANCE.getRepository();
}
- public IOntologyContextStorage getContextStorage() {
- return Rdf4JStorageManager.INSTANCE.getContextStorage();
- }
-
-
-
}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/Rdf4JStorageManager.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/Rdf4JStorageManager.java
index 6538afb..84f173c 100644
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/Rdf4JStorageManager.java
+++ b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/Rdf4JStorageManager.java
@@ -17,12 +17,6 @@
*/
package org.apache.streampipes.storage;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.eclipse.rdf4j.repository.sail.SailRepository;
-import org.eclipse.rdf4j.sail.nativerdf.NativeStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import io.fogsy.empire.core.empire.Empire;
import io.fogsy.empire.core.empire.EmpireOptions;
import io.fogsy.empire.core.empire.config.ConfigKeys;
@@ -31,22 +25,23 @@ import io.fogsy.empire.rdf4j.OpenRdfEmpireModule;
import io.fogsy.empire.rdf4j.RepositoryFactoryKeys;
import org.apache.streampipes.serializers.jsonld.CustomAnnotationProvider;
import org.apache.streampipes.storage.api.IBackgroundKnowledgeStorage;
-import org.apache.streampipes.storage.api.IOntologyContextStorage;
import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorageCache;
import org.apache.streampipes.storage.api.ITripleStorage;
import org.apache.streampipes.storage.rdf4j.config.Rdf4JConfig;
-import org.apache.streampipes.storage.rdf4j.impl.BackgroundKnowledgeStorageImpl;
-import org.apache.streampipes.storage.rdf4j.impl.ContextStorageImpl;
import org.apache.streampipes.storage.rdf4j.impl.PipelineElementInMemoryStorage;
import org.apache.streampipes.storage.rdf4j.impl.PipelineElementStorageRequests;
+import org.eclipse.rdf4j.repository.Repository;
+import org.eclipse.rdf4j.repository.sail.SailRepository;
+import org.eclipse.rdf4j.sail.nativerdf.NativeStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.persistence.EntityManager;
+import javax.persistence.spi.PersistenceProvider;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.spi.PersistenceProvider;
-
public enum Rdf4JStorageManager implements ITripleStorage {
INSTANCE;
@@ -61,20 +56,6 @@ public enum Rdf4JStorageManager implements ITripleStorage {
Rdf4JStorageManager() {
initPipelineElementStorage();
- initBackgroundKnowledgeStorage();
- }
-
- private void initBackgroundKnowledgeStorage() {
- backgroundKnowledgeRepository = makeRepo(Rdf4JConfig
- .INSTANCE
- .getBackgroundKnowledgeStorageLocation());
- try {
- backgroundKnowledgeRepository.initialize();
- this.backgroundKnowledgeStorage =
- new BackgroundKnowledgeStorageImpl(backgroundKnowledgeRepository);
- } catch (RepositoryException e) {
- LOG.error("Could not initialize background knowledge repository", e);
- }
}
private void initPipelineElementStorage() {
@@ -133,9 +114,4 @@ public enum Rdf4JStorageManager implements ITripleStorage {
return this.pipelineElementInMemoryStorage;
}
- @Override
- public IOntologyContextStorage getContextStorage() {
- return new ContextStorageImpl(backgroundKnowledgeRepository);
- }
-
}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/config/Rdf4JConfig.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/config/Rdf4JConfig.java
index abc53af..48f1965 100644
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/config/Rdf4JConfig.java
+++ b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/config/Rdf4JConfig.java
@@ -56,10 +56,6 @@ public enum Rdf4JConfig {
+ File.separator;
}
- public String getBackgroundKnowledgeStorageLocation() {
- return config.getString(ConfigKeys.BACKGROUND_KNOWLEDGE_DIR);
- }
-
public String getPipelineElementStorageLocation() {
return config.getString(ConfigKeys.PIPELINE_ELEMENT_KNOWLEDGE_DIR);
}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/BackgroundKnowledgeFilter.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/BackgroundKnowledgeFilter.java
deleted file mode 100644
index 4452980..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/BackgroundKnowledgeFilter.java
+++ /dev/null
@@ -1,84 +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.storage.rdf4j.filter;
-
-import org.apache.streampipes.model.client.ontology.OntologyNode;
-import org.apache.streampipes.model.client.ontology.Property;
-import org.apache.streampipes.storage.rdf4j.util.BackgroundKnowledgeUtils;
-import org.apache.streampipes.vocabulary.StreamPipes;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class BackgroundKnowledgeFilter {
-
- public static List<String> omittedPropertyPrefixes = Arrays.asList(StreamPipes.NS,
- "http://schema.org/Thing", "http://purl.oclc.org/NET/ssnx/ssn#",
- "http://sepa.event-processing.org/sepa#",
- "http://www.w3.org/2000/01/rdf-schema#",
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
-
- public static List<OntologyNode> propertiesFilter(List<OntologyNode> nodes, boolean filterDuplicates) {
- List<OntologyNode> filteredList = nodes
- .stream()
- .filter(n -> omittedPropertyPrefixes
- .stream()
- .noneMatch(op -> n.getId().startsWith(op)))
- .collect(Collectors.toList());
- if (filterDuplicates) {
- return BackgroundKnowledgeUtils.filterDuplicates(filteredList);
- } else {
- return filteredList;
- }
- }
-
- public static List<Property> rdfsFilter(List<Property> properties, boolean filterDuplicates) {
- List<Property> filteredList = properties
- .stream()
- .filter(n -> omittedPropertyPrefixes
- .stream()
- .noneMatch(op -> n.getElementHeader()
- .getId()
- .startsWith(op)))
- .collect(Collectors.toList());
- if (filterDuplicates) {
- return BackgroundKnowledgeUtils.filterDuplicates(filteredList);
- } else {
- return filteredList;
- }
- }
-
-
- public static List<OntologyNode> classFilter(List<OntologyNode> nodes, boolean filterDuplicates) {
- List<OntologyNode> filteredList = nodes
- .stream()
- .filter(n -> omittedPropertyPrefixes
- .stream()
- .noneMatch(op -> n
- .getId()
- .startsWith(op)))
- .collect(Collectors.toList());
- if (filterDuplicates) {
- return BackgroundKnowledgeUtils.filterDuplicates(filteredList);
- } else {
- return filteredList;
- }
- }
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/Filter.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/Filter.java
index 8342e99..dccc396 100644
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/Filter.java
+++ b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/filter/Filter.java
@@ -19,30 +19,17 @@
package org.apache.streampipes.storage.rdf4j.filter;
import org.apache.streampipes.model.base.NamedStreamPipesEntity;
-import org.apache.streampipes.model.client.user.Element;
import java.util.List;
import java.util.stream.Collectors;
public class Filter {
-
- public static <T extends NamedStreamPipesEntity> List<T> byElement(List<T> allElements, List<Element> userElements)
- {
- return allElements.stream().filter(e -> userElements.stream().anyMatch(u -> u.getElementId().equals(e.getUri()))).collect(Collectors.toList());
- }
- public static <T extends NamedStreamPipesEntity> List<T> byUri(List<T> allElements, List<String> userElements)
- {
+ public static <T extends NamedStreamPipesEntity> List<T> byUri(List<T> allElements, List<String> userElements) {
return allElements
.stream()
.filter(e -> userElements.stream()
.anyMatch(u -> u.equals(e.getUri()))).collect(Collectors.toList());
- }
-
- public static <T extends NamedStreamPipesEntity> List<T> addFavorites(List<T> actionClients, List<String> favorites)
- {
- //actionClients.stream().forEach(a -> a.setFavorite(favorites.stream().anyMatch(f -> a.getElementId().equals(f))));
- return actionClients;
}
}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/BackgroundKnowledgeStorageImpl.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/BackgroundKnowledgeStorageImpl.java
deleted file mode 100644
index 7cad63e..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/BackgroundKnowledgeStorageImpl.java
+++ /dev/null
@@ -1,467 +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.storage.rdf4j.impl;
-
-import org.eclipse.rdf4j.model.Value;
-import org.eclipse.rdf4j.model.ValueFactory;
-import org.eclipse.rdf4j.model.vocabulary.RDF;
-import org.eclipse.rdf4j.model.vocabulary.RDFS;
-import org.eclipse.rdf4j.query.BindingSet;
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.QueryLanguage;
-import org.eclipse.rdf4j.query.TupleQueryResult;
-import org.eclipse.rdf4j.query.Update;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryConnection;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.eclipse.rdf4j.repository.RepositoryResult;
-import org.apache.streampipes.model.client.ontology.Concept;
-import org.apache.streampipes.model.client.ontology.ElementHeader;
-import org.apache.streampipes.model.client.ontology.Instance;
-import org.apache.streampipes.model.client.ontology.Namespace;
-import org.apache.streampipes.model.client.ontology.NodeType;
-import org.apache.streampipes.model.client.ontology.OntologyNode;
-import org.apache.streampipes.model.client.ontology.OntologyQuery;
-import org.apache.streampipes.model.client.ontology.OntologyQueryItem;
-import org.apache.streampipes.model.client.ontology.OntologyQueryResponse;
-import org.apache.streampipes.model.client.ontology.Property;
-import org.apache.streampipes.model.client.ontology.Resource;
-import org.apache.streampipes.storage.api.IBackgroundKnowledgeStorage;
-import org.apache.streampipes.storage.rdf4j.filter.BackgroundKnowledgeFilter;
-import org.apache.streampipes.storage.rdf4j.ontology.ClassHierarchyExecutor;
-import org.apache.streampipes.storage.rdf4j.ontology.ConceptUpdateExecutor;
-import org.apache.streampipes.storage.rdf4j.ontology.InstanceUpdateExecutor;
-import org.apache.streampipes.storage.rdf4j.ontology.PropertyUpdateExecutor;
-import org.apache.streampipes.storage.rdf4j.ontology.QueryExecutor;
-import org.apache.streampipes.storage.rdf4j.ontology.RangeQueryExecutor;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-import org.apache.streampipes.storage.rdf4j.util.BackgroundKnowledgeUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-public class BackgroundKnowledgeStorageImpl implements
- IBackgroundKnowledgeStorage {
-
- private Repository repo;
-
- public BackgroundKnowledgeStorageImpl(Repository repo) {
- this.repo = repo;
- }
-
- @Override
- public List<OntologyNode> getClassHierarchy() throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- return new ClassHierarchyExecutor(repo).getClassHierarchy();
- }
-
- @Override
- public List<OntologyNode> getPropertyHierarchy() throws RepositoryException, MalformedQueryException, QueryEvaluationException {
- List<OntologyNode> ontologyNodes = new ArrayList<>();
- String queryString = QueryBuilder.getEventProperties();
-
- TupleQueryResult result = getQueryResult(queryString);
-
- while (result.hasNext()) { // iterate over the result
- BindingSet bindingSet = result.next();
- Value valueOfX = bindingSet.getValue("result");
- Optional<Namespace> ns = getNamespace(valueOfX.toString());
- if (ns.isPresent()) ontologyNodes.add(new OntologyNode(valueOfX.toString(), valueOfX.toString().replace(ns.get().getNamespaceId(), ns.get().getPrefix() +":"), ns.get().getPrefix(), ns.get().getNamespaceId(), NodeType.PROPERTY));
- else ontologyNodes.add(new OntologyNode(valueOfX.toString(), valueOfX.toString(), NodeType.PROPERTY));
- }
-
- return BackgroundKnowledgeFilter.propertiesFilter(ontologyNodes, true);
- }
-
- private Property getProperty(String propertyId, String instanceId) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- ElementHeader header = null;
- Property property = null;
- RangeQueryExecutor rangeExecutor = null;
-
- String label = "";
- String description = "";
- String range = "";
- List<String> rangeTypes = new ArrayList<>();
-
- String queryString = QueryBuilder.getProperty(propertyId);
- TupleQueryResult result = getQueryResult(queryString);
-
- Optional<Namespace> nsOpt = getNamespace(propertyId);
- if (nsOpt.isPresent())
- {
- Namespace ns = nsOpt.get();
- header = new ElementHeader(propertyId, propertyId.replace(ns.getNamespaceId(), ns.getPrefix() +":"), ns.getPrefix(), ns.getNamespaceId());
- }
- else
- header = new ElementHeader(propertyId, propertyId);
-
- while(result.hasNext())
- {
- BindingSet bindingSet = result.next();
- Value labelField = bindingSet.getValue("label");
- Value descriptionField = bindingSet.getValue("description");
- range = bindingSet.getValue("range").stringValue();
- rangeTypes.add(bindingSet.getValue("rangeType").stringValue());
-
- if (labelField != null) label = labelField.stringValue();
- if (descriptionField != null) description = descriptionField.stringValue();
- }
-
- if (instanceId == null) rangeExecutor = new RangeQueryExecutor(repo, propertyId, range, rangeTypes);
- else rangeExecutor = new RangeQueryExecutor(repo, propertyId, range, rangeTypes, instanceId);
- property = new Property(header, label, description, rangeExecutor.getRange());
- property.setRangeDefined((range != null && !range.equals("")) ? true : false);
-
- return property;
- }
-
- @Override
- public Property getProperty(String propertyId) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- return getProperty(propertyId, null);
- }
-
- @Override
- public Concept getConcept(String conceptId) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- TupleQueryResult result =getQueryResult(QueryBuilder.getTypeDetails(conceptId));
-
- Concept concept = new Concept();
- ElementHeader header = null;
-
- List<Property> properties = new ArrayList<>();
- int idx = 0;
-
- Optional<Namespace> nsOpt = getNamespace(conceptId);
- if (nsOpt.isPresent())
- {
- Namespace ns = nsOpt.get();
- header = new ElementHeader(conceptId, conceptId.replace(ns.getNamespaceId(), ns.getPrefix() +":"), ns.getPrefix(), ns.getNamespaceId());
- }
- else
- header = new ElementHeader(conceptId, conceptId);
-
- concept.setElementHeader(header);
-
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- if (idx == 0)
- {
- Value label = bindingSet.getValue("label");
- Value description = bindingSet.getValue("description");
- if (label != null) concept.setRdfsLabel(label.stringValue());
- if (description != null) concept.setRdfsDescription(description.stringValue());
- }
- Value domainPropertyId = bindingSet.getValue("domainPropertyId");
- Property property = getProperty(domainPropertyId.stringValue());
- properties.add(property);
-
- idx++;
- }
-
- concept.setDomainProperties(BackgroundKnowledgeUtils.filterDuplicates(properties));
- return concept;
- }
-
- @Override
- public boolean updateProperty(Property property) {
- PropertyUpdateExecutor propertyUpdateExecutor = new PropertyUpdateExecutor(repo, property);
-
- try {
- propertyUpdateExecutor.deleteExistingTriples();
- propertyUpdateExecutor.addNewTriples();
- return true;
- } catch (RepositoryException | MalformedQueryException | UpdateExecutionException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public List<Namespace> getNamespaces() throws RepositoryException {
-
- List<Namespace> result = new ArrayList<>();
- RepositoryResult<org.eclipse.rdf4j.model.Namespace> namespaces = repo.getConnection().getNamespaces();
-
- while(namespaces.hasNext())
- {
- org.eclipse.rdf4j.model.Namespace ns = namespaces.next();
- result.add(new Namespace(ns.getPrefix(), ns.getName()));
- }
- return result;
-
- }
-
- private Optional<Namespace> getNamespace(String propertyId)
- {
- return BackgroundKnowledgeUtils.getNamespace(propertyId);
- }
-
- private TupleQueryResult getQueryResult(String queryString) throws QueryEvaluationException, RepositoryException, MalformedQueryException
- {
- return new QueryExecutor(repo).executeQuery(queryString);
- }
-
- @Override
- public boolean addNamespace(Namespace namespace) {
-
- try {
- RepositoryConnection conn = repo.getConnection();
- conn.setNamespace(namespace.getPrefix(), namespace.getNamespaceId());
- conn.close();
- return true;
- } catch (RepositoryException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public boolean deleteNamespace(String prefix) {
- try {
- RepositoryConnection conn = repo.getConnection();
- conn.removeNamespace(prefix);
- conn.close();
- return true;
- } catch (RepositoryException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public boolean addProperty(Resource resource) {
- return addResource(resource, RDF.PROPERTY);
- }
-
- @Override
- public boolean addConcept(Resource resource) {
- return addResource(resource, RDFS.CLASS);
- }
-
- @Override
- public boolean addIndividual(Resource resource) {
- try {
- RepositoryConnection conn = repo.getConnection();
- ValueFactory factory = conn.getValueFactory();
- String elementName = resource.getElementName().replaceAll(" ", "_");
- org.eclipse.rdf4j.model.Statement st;
-
- if (resource.getInstanceOf() != null ) st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, factory.createURI(resource.getInstanceOf()));
- else st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, RDFS.RESOURCE);
-
- conn.add(st);
- conn.close();
- return true;
- } catch (RepositoryException e) {
- return false;
- }
- }
-
- private boolean addResource(Resource resource, org.eclipse.rdf4j.model.URI object)
- {
- try {
- RepositoryConnection conn = repo.getConnection();
- ValueFactory factory = conn.getValueFactory();
- String elementName = resource.getElementName().replaceAll(" ", "_");
- org.eclipse.rdf4j.model.Statement st = factory.createStatement(factory.createURI(resource.getNamespace()
- +elementName), RDF.TYPE, object);
- conn.add(st);
- conn.close();
- return true;
- } catch (RepositoryException e) {
- return false;
- }
- }
-
- @Override
- public boolean updateConcept(Concept concept) {
- ConceptUpdateExecutor conceptUpdateExecutor = new ConceptUpdateExecutor(repo, concept);
- try {
- conceptUpdateExecutor.deleteExistingTriples();
- conceptUpdateExecutor.addNewTriples();
- return true;
- } catch (RepositoryException | MalformedQueryException | UpdateExecutionException | QueryEvaluationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public Instance getInstance(String instanceId)
- throws QueryEvaluationException, RepositoryException,
- MalformedQueryException {
- TupleQueryResult result =getQueryResult(QueryBuilder.getInstanceDetails(instanceId));
- Instance instance = new Instance();
- ElementHeader header = null;
-
- List<Property> properties = new ArrayList<>();
- List<String> instanceProperties = new ArrayList<>();
- int idx = 0;
-
- Optional<Namespace> nsOpt = getNamespace(instanceId);
- if (nsOpt.isPresent())
- {
- Namespace ns = nsOpt.get();
- header = new ElementHeader(instanceId, instanceId.replace(ns.getNamespaceId(), ns.getPrefix() +":"), ns.getPrefix(), ns.getNamespaceId());
- }
- else
- header = new ElementHeader(instanceId, instanceId);
-
- instance.setElementHeader(header);
-
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
-
- if (idx == 0)
- {
- Value label = bindingSet.getValue("label");
- Value description = bindingSet.getValue("description");
- if (label != null) instance.setRdfsLabel(label.stringValue());
- if (description != null) instance.setRdfsDescription(description.stringValue());
- }
-
- instanceProperties.add(bindingSet.getValue("property").stringValue());
-
- idx++;
- }
-
- for(String propertyId : instanceProperties)
- {
- Property p = getProperty(propertyId, instanceId);
- properties.add(p);
- }
-
- List<String> rdfTypes = getRdfTypes(instanceId);
- rdfTypes
- .stream()
- .filter(type -> !BackgroundKnowledgeFilter.omittedPropertyPrefixes
- .stream()
- .anyMatch(prefix -> type.equals(prefix)))
- .forEach(type -> {
- try {
- Concept concept = getConcept(type);
-
- concept.getDomainProperties()
- .stream()
- .filter(dp -> !properties
- .stream()
- .anyMatch(p -> p.getElementHeader().getId().equals(dp.getElementHeader().getId())))
- .forEach(dp -> properties.add(dp));
- } catch (Exception e) {
- e.printStackTrace();
- }
- });;
-
-
- instance.setDomainProperties(BackgroundKnowledgeUtils.filterDuplicates(BackgroundKnowledgeFilter.rdfsFilter(properties, true)));
- return instance;
- }
-
- private List<String> getRdfTypes(String instanceId) throws QueryEvaluationException, RepositoryException, MalformedQueryException
- {
- List<String> rdfTypes = new ArrayList<>();
- TupleQueryResult result =getQueryResult(QueryBuilder.getRdfType(instanceId));
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- Value typeOf = bindingSet.getValue("typeOf");
- rdfTypes.add(typeOf.stringValue());
- }
-
- return rdfTypes;
- }
-
- @Override
- public boolean updateInstance(Instance instance) {
- InstanceUpdateExecutor instanceUpdateExecutor = new InstanceUpdateExecutor(repo, instance);
- try {
- instanceUpdateExecutor.deleteExistingTriples();
- instanceUpdateExecutor.addNewTriples();
- return true;
- } catch (RepositoryException | MalformedQueryException | UpdateExecutionException | QueryEvaluationException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public boolean deleteResource(String resourceId) {
-
- String deleteQuery = QueryBuilder.deleteResource(resourceId);
- try {
- RepositoryConnection connection = repo.getConnection();
- Update tupleQuery;
- tupleQuery = connection.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
- tupleQuery.execute();
-
- connection.close();
- return true;
- } catch (RepositoryException | MalformedQueryException | UpdateExecutionException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- @Override
- public OntologyQuery getOntologyResult(OntologyQuery query) {
- for(OntologyQueryItem item : query.getRequiredProperties())
- {
- TupleQueryResult result;
- List<OntologyQueryResponse> queryResponse = new ArrayList<>();
- try {
- result = getQueryResult(QueryBuilder.getPropertyDetails(query.getRequiredClass(), item.getPropertyId(), query.getRequiredProperties()));
-
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- OntologyQueryResponse response = new OntologyQueryResponse();
-
- Value label = bindingSet.getValue("label");
- Value description = bindingSet.getValue("description");
- Value propertyValue = bindingSet.getValue("propertyValue");
- if (label != null) response.setLabel(label.stringValue());
- if (description != null) response.setDescription(description.stringValue());
- response.setPropertyValue(propertyValue.stringValue());
-
- queryResponse.add(response);
- }
- item.setQueryResponse(queryResponse);
-
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- e.printStackTrace();
-
- }
- }
- return query;
- }
-
- @Override
- public boolean initialize() {
- try {
- new QueryExecutor(repo).executeUpdate(QueryBuilder.addRequiredTriples());
- return true;
- } catch (UpdateExecutionException | RepositoryException
- | MalformedQueryException e) {
- e.printStackTrace();
- return false;
- }
- }
-
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/ContextStorageImpl.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/ContextStorageImpl.java
deleted file mode 100644
index abedb88..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/impl/ContextStorageImpl.java
+++ /dev/null
@@ -1,131 +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.storage.rdf4j.impl;
-
-import org.eclipse.rdf4j.model.Resource;
-import org.eclipse.rdf4j.model.Statement;
-import org.eclipse.rdf4j.model.ValueFactory;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryConnection;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.eclipse.rdf4j.repository.RepositoryResult;
-import org.eclipse.rdf4j.rio.RDFFormat;
-import org.eclipse.rdf4j.rio.RDFParser;
-import org.eclipse.rdf4j.rio.Rio;
-import org.eclipse.rdf4j.rio.helpers.StatementCollector;
-import org.apache.streampipes.model.client.ontology.Context;
-import org.apache.streampipes.model.client.ontology.RdfFormat;
-import org.apache.streampipes.storage.api.IOntologyContextStorage;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class ContextStorageImpl implements IOntologyContextStorage {
-
- private Repository repository;
-
- public ContextStorageImpl(Repository repository)
- {
- this.repository = repository;
- }
-
-
- public boolean addContext(Context context)
- {
- try {
- RepositoryConnection conn = getConnection();
- {
- ValueFactory vf = conn.getValueFactory();
- RDFParser rdfParser = getParser(context.getRdfFormat());
- StatementCollector handler = new StatementCollector();
- rdfParser.setRDFHandler(handler);
- rdfParser.parse(context.getInputStream(), context.getBaseUri());
- Collection<Statement> col = handler.getStatements();
-
- for (Statement statement : col) {
- conn.add(statement, vf.createURI(context.getContextId()));
- }
- }
- closeConnection(conn);
- return true;
- } catch (Exception e)
- {
- e.printStackTrace();
- return false;
- }
- }
-
- private RDFParser getParser(RdfFormat rdfFormat) {
- if (rdfFormat == RdfFormat.RDFXML) return Rio.createParser(RDFFormat.RDFXML);
- else if (rdfFormat == RdfFormat.JSONLD) return Rio.createParser(RDFFormat.JSONLD);
- else if (rdfFormat == RdfFormat.TURTLE) return Rio.createParser(RDFFormat.TURTLE);
- else if (rdfFormat == RdfFormat.RDFA) return Rio.createParser(RDFFormat.RDFA);
- else return Rio.createParser(RDFFormat.N3);
- }
-
-
- public boolean deleteContext(String contextId)
- {
- try {
- RepositoryConnection conn = getConnection();
- {
- conn.clear(conn.getValueFactory().createURI(contextId));
- }
- closeConnection(conn);
- return true;
- } catch (Exception e)
- {
- e.printStackTrace();
- return false;
- }
- }
-
- public List<String> getAvailableContexts() {
- List<String> contexts = new ArrayList<>();
-
- try {
- RepositoryConnection conn = getConnection();
- {
- RepositoryResult<Resource> result = conn.getContextIDs();
- while(result.hasNext())
- {
- Resource resource = result.next();
- contexts.add(resource.stringValue());
- }
- }
- closeConnection(conn);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
-
- return contexts;
- }
-
- private RepositoryConnection getConnection() throws RepositoryException
- {
- return repository.getConnection();
- }
-
- private void closeConnection(RepositoryConnection connection) throws RepositoryException
- {
- connection.close();
- }
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ClassHierarchyExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ClassHierarchyExecutor.java
deleted file mode 100644
index a5a884b..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ClassHierarchyExecutor.java
+++ /dev/null
@@ -1,116 +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.storage.rdf4j.ontology;
-
-import org.eclipse.rdf4j.model.Value;
-import org.eclipse.rdf4j.query.BindingSet;
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.TupleQueryResult;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.apache.streampipes.model.client.ontology.Namespace;
-import org.apache.streampipes.model.client.ontology.NodeType;
-import org.apache.streampipes.model.client.ontology.OntologyNode;
-import org.apache.streampipes.storage.rdf4j.filter.BackgroundKnowledgeFilter;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-import org.apache.streampipes.storage.rdf4j.util.BackgroundKnowledgeUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-public class ClassHierarchyExecutor extends QueryExecutor {
-
- public ClassHierarchyExecutor(Repository repository)
- {
- super(repository);
- }
-
- private List<OntologyNode> getClasses() throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- TupleQueryResult result = getQueryResult(QueryBuilder.getClasses());
- List<OntologyNode> classNodes = new ArrayList<>();
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- Value valueOfX = bindingSet.getValue("result");
- classNodes.add(makeNode(valueOfX.stringValue(), NodeType.CLASS));
- }
- return BackgroundKnowledgeFilter.classFilter(classNodes, true);
- }
-
- private String getLabelName(String value)
- {
- if (value.contains("#")) return value.substring(value.indexOf("#")+1);
- else if (value.contains("/")) return value.substring(value.lastIndexOf("/")+1);
- else return value;
- }
-
- private TupleQueryResult getQueryResult(String queryString) throws QueryEvaluationException, RepositoryException, MalformedQueryException
- {
- return executeQuery(queryString);
- }
-
- public List<OntologyNode> getClassHierarchy() throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- List<OntologyNode> classHierarchy = new ArrayList<>();
- for(OntologyNode node : getClasses())
- {
- List<OntologyNode> children = new ArrayList<>();
- children.addAll(getInstances(node.getId()));
- node.setNodes(children);
- classHierarchy.add(node);
- }
- return classHierarchy;
- }
-
- @SuppressWarnings("unused")
- private List<OntologyNode> getSubclasses(String nodeUri) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- List<OntologyNode> result = new ArrayList<>();
- TupleQueryResult queryResult = getQueryResult(QueryBuilder.getSubclasses(nodeUri));
-
- while (queryResult.hasNext()) {
- BindingSet bindingSet = queryResult.next();
- Value valueOfX = bindingSet.getValue("s");
- result.add(makeNode(valueOfX.stringValue(), NodeType.CLASS));
- }
- return result;
- }
-
- private OntologyNode makeNode(String id, NodeType nodeType)
- {
- OntologyNode node;
- Optional<Namespace> ns = BackgroundKnowledgeUtils.getNamespace(id);
- node = ns.map(namespace -> new OntologyNode(id, id.replace(namespace.getNamespaceId(), namespace.getPrefix() + ":"), namespace.getPrefix(), namespace.getNamespaceId(), NodeType.CLASS))
- .orElseGet(() -> new OntologyNode(id, getLabelName(id), nodeType));
-
- return node;
- }
-
- private List<OntologyNode> getInstances(String className) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
-
- List<OntologyNode> result = new ArrayList<>();
- TupleQueryResult queryResult = getQueryResult(QueryBuilder.getInstances(className));
-
- while (queryResult.hasNext()) {
- BindingSet bindingSet = queryResult.next();
- Value valueOfX = bindingSet.getValue("s");
- result.add(makeNode(valueOfX.toString(), NodeType.INSTANCE));
- }
- return BackgroundKnowledgeUtils.filterDuplicates(result);
- }
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ConceptUpdateExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ConceptUpdateExecutor.java
deleted file mode 100644
index 8fc043e..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/ConceptUpdateExecutor.java
+++ /dev/null
@@ -1,52 +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.storage.rdf4j.ontology;
-
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.apache.streampipes.model.client.ontology.Concept;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-
-public class ConceptUpdateExecutor extends UpdateExecutor {
-
- private Concept concept;
-
- public ConceptUpdateExecutor(Repository repository, Concept concept) {
- super(repository);
- this.concept = concept;
- }
-
- @Override
- public void deleteExistingTriples() throws RepositoryException,
- QueryEvaluationException, MalformedQueryException,
- UpdateExecutionException {
- executeUpdate(QueryBuilder.deleteConceptDetails(concept.getElementHeader().getId()));
- }
-
- @Override
- public void addNewTriples() throws RepositoryException,
- QueryEvaluationException, MalformedQueryException,
- UpdateExecutionException {
- executeUpdate(QueryBuilder.addConceptDetails(concept));
- }
-
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/InstanceUpdateExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/InstanceUpdateExecutor.java
deleted file mode 100644
index 0123e8d..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/InstanceUpdateExecutor.java
+++ /dev/null
@@ -1,51 +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.storage.rdf4j.ontology;
-
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.apache.streampipes.model.client.ontology.Instance;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-
-public class InstanceUpdateExecutor extends UpdateExecutor {
-
-private Instance instance;
-
- public InstanceUpdateExecutor(Repository repository, Instance instance) {
- super(repository);
- this.instance = instance;
- }
-
- @Override
- public void deleteExistingTriples() throws RepositoryException,
- QueryEvaluationException, MalformedQueryException,
- UpdateExecutionException {
- executeUpdate(QueryBuilder.deleteInstanceDetails(instance.getElementHeader().getId()));
- }
-
- @Override
- public void addNewTriples() throws RepositoryException,
- QueryEvaluationException, MalformedQueryException,
- UpdateExecutionException {
- executeUpdate(QueryBuilder.addInstanceDetails(instance));
- }
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/PropertyUpdateExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/PropertyUpdateExecutor.java
deleted file mode 100644
index 37450af..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/PropertyUpdateExecutor.java
+++ /dev/null
@@ -1,48 +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.storage.rdf4j.ontology;
-
-
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.apache.streampipes.model.client.ontology.Property;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-
-public class PropertyUpdateExecutor extends UpdateExecutor{
-
- private Property property;
-
- public PropertyUpdateExecutor(Repository repository, Property property)
- {
- super(repository);
- this.property = property;
- }
-
- public void deleteExistingTriples() throws UpdateExecutionException, RepositoryException, MalformedQueryException
- {
- executeUpdate(QueryBuilder.deletePropertyDetails(property.getElementHeader().getId()));
- }
-
- public void addNewTriples() throws UpdateExecutionException, RepositoryException, MalformedQueryException
- {
- executeUpdate(QueryBuilder.addPropertyDetails(property));
- }
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/QueryExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/QueryExecutor.java
deleted file mode 100644
index 4e18252..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/QueryExecutor.java
+++ /dev/null
@@ -1,62 +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.storage.rdf4j.ontology;
-
-
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.QueryLanguage;
-import org.eclipse.rdf4j.query.TupleQuery;
-import org.eclipse.rdf4j.query.TupleQueryResult;
-import org.eclipse.rdf4j.query.Update;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryConnection;
-import org.eclipse.rdf4j.repository.RepositoryException;
-
-public class QueryExecutor {
-
- private Repository repository;
-
- public QueryExecutor(Repository repository) {
- this.repository = repository;
- }
-
- public TupleQueryResult executeQuery(String sparqlQuery) throws QueryEvaluationException, RepositoryException, MalformedQueryException {
- RepositoryConnection connection = repository.getConnection();
- TupleQuery tupleQuery;
- TupleQueryResult result;
- tupleQuery = connection.prepareTupleQuery(
- QueryLanguage.SPARQL, sparqlQuery);
- result = tupleQuery.evaluate();
-
- connection.close();
- return result;
- }
-
- public void executeUpdate(String sparqlUpdate) throws UpdateExecutionException, RepositoryException, MalformedQueryException {
- RepositoryConnection connection = repository.getConnection();
- Update tupleQuery;
- tupleQuery = connection.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
- tupleQuery.execute();
-
- connection.close();
- }
-
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/RangeQueryExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/RangeQueryExecutor.java
deleted file mode 100644
index 448881d..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/RangeQueryExecutor.java
+++ /dev/null
@@ -1,149 +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.storage.rdf4j.ontology;
-
-import org.eclipse.rdf4j.model.Value;
-import org.eclipse.rdf4j.query.BindingSet;
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.TupleQueryResult;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.streampipes.model.client.ontology.PrimitiveRange;
-import org.apache.streampipes.model.client.ontology.QuantitativeValueRange;
-import org.apache.streampipes.model.client.ontology.Range;
-import org.apache.streampipes.model.client.ontology.RangeType;
-import org.apache.streampipes.storage.rdf4j.sparql.QueryBuilder;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class RangeQueryExecutor extends QueryExecutor {
-
- private static final Logger LOG = LoggerFactory.getLogger(RangeQueryExecutor.class);
-
- private static final String RANGE_TYPE_RDFS_ENUMERATION = "http://sepa.event-processing.org/sepa#Enumeration";
- public static final List<String> RANGE_TYPE_RDFS_LITERAL = Arrays.asList("http://www.w3.org/2001/XMLSchema#string",
- "http://www.w3.org/2001/XMLSchema#boolean",
- "http://www.w3.org/2001/XMLSchema#integer",
- "http://www.w3.org/2001/XMLSchema#double",
- "http://www.w3.org/2001/XMLSchema#float");
- private static final String RANGE_TYPE_RDFS_QUANTITATIVE_VALUE = "http://schema.org/QuantitativeValue";
-
-
- private Range range;
- private RangeType rangeType;
-
- private String propertyId;
- private String rangeId;
- private List<String> rangeTypeRdfs;
-
- private boolean includeValues;
- private String instanceId;
-
- public RangeQueryExecutor(Repository repository, String propertyId, String rangeId, List<String> rangeTypeRdfs) {
- super(repository);
- this.propertyId = propertyId;
- this.rangeTypeRdfs = rangeTypeRdfs;
- this.includeValues = false;
- this.rangeId = rangeId;
- prepare();
- }
-
- public RangeQueryExecutor(Repository repository, String propertyId, String rangeId, List<String> rangeTypeRdfs, String instanceId) {
- super(repository);
- this.propertyId = propertyId;
- this.rangeTypeRdfs = rangeTypeRdfs;
- this.instanceId = instanceId;
- this.includeValues = true;
- this.rangeId = rangeId;
- prepare();
- }
-
- private void prepare() {
- prepareRangeType();
-
- if (rangeType == RangeType.PRIMITIVE) {
- range = new PrimitiveRange(rangeId);
- if (includeValues) {
- try {
- TupleQueryResult result = executeQuery(QueryBuilder.getPrimitivePropertyValue(instanceId, propertyId));
- LOG.info(QueryBuilder.getPrimitivePropertyValue(instanceId, propertyId));
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- Value value = bindingSet.getValue("value");
-
- ((PrimitiveRange) range).setValue(value.stringValue());
- }
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- e.printStackTrace();
- }
- }
- } else if (rangeType == RangeType.ENUMERATION) {
- //TODO implement enumerated type
- } else if (rangeType == RangeType.QUANTITATIVE_VALUE) {
- range = new QuantitativeValueRange();
- if (includeValues) {
- try {
- TupleQueryResult result = executeQuery(QueryBuilder.getQuantitativeValueRange(propertyId));
- while (result.hasNext()) {
- BindingSet bindingSet = result.next();
- Value minValue = bindingSet.getValue("minValue");
- Value maxValue = bindingSet.getValue("maxValue");
- Value unitCode = bindingSet.getValue("unitCode");
-
- ((QuantitativeValueRange) range).setMinValue(Integer.parseInt(minValue.stringValue()));
- ((QuantitativeValueRange) range).setMaxValue(Integer.parseInt(maxValue.stringValue()));
- ((QuantitativeValueRange) range).setUnitCode(unitCode.stringValue());
-
-
- }
- } catch (QueryEvaluationException | RepositoryException
- | MalformedQueryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
-
- private void prepareRangeType() {
- if (rangeTypeRdfs.stream().anyMatch(p -> p.startsWith(RANGE_TYPE_RDFS_ENUMERATION))) {
- rangeType = RangeType.ENUMERATION;
- } else if (rangeTypeRdfs.stream().anyMatch(p -> p.startsWith(RANGE_TYPE_RDFS_QUANTITATIVE_VALUE))) {
- rangeType = RangeType.QUANTITATIVE_VALUE;
- } else if (RANGE_TYPE_RDFS_LITERAL.stream().anyMatch(rt -> rangeId.startsWith(rt))) {
- rangeType = RangeType.PRIMITIVE;
- } else {
- rangeType = RangeType.RDFS_CLASS;
- }
- }
-
- public Range getRange() {
- return range;
- }
-
- public RangeType getRangeType() {
- return rangeType;
- }
-
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/UpdateExecutor.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/UpdateExecutor.java
deleted file mode 100644
index 808f66f..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/ontology/UpdateExecutor.java
+++ /dev/null
@@ -1,37 +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.storage.rdf4j.ontology;
-
-import org.eclipse.rdf4j.query.MalformedQueryException;
-import org.eclipse.rdf4j.query.QueryEvaluationException;
-import org.eclipse.rdf4j.query.UpdateExecutionException;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryException;
-
-public abstract class UpdateExecutor extends QueryExecutor {
-
- public UpdateExecutor(Repository repository) {
- super(repository);
- }
-
- public abstract void deleteExistingTriples() throws RepositoryException, QueryEvaluationException, MalformedQueryException, UpdateExecutionException;
-
- public abstract void addNewTriples() throws RepositoryException, QueryEvaluationException, MalformedQueryException, UpdateExecutionException;
-
-}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/sparql/QueryBuilder.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/sparql/QueryBuilder.java
index 7960ad3..b699488 100644
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/sparql/QueryBuilder.java
+++ b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/sparql/QueryBuilder.java
@@ -18,39 +18,8 @@
package org.apache.streampipes.storage.rdf4j.sparql;
-import org.apache.commons.lang.RandomStringUtils;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.streampipes.model.client.ontology.Concept;
-import org.apache.streampipes.model.client.ontology.Instance;
-import org.apache.streampipes.model.client.ontology.OntologyQueryItem;
-import org.apache.streampipes.model.client.ontology.PrimitiveRange;
-import org.apache.streampipes.model.client.ontology.Property;
-import org.apache.streampipes.model.client.ontology.QuantitativeValueRange;
-import org.apache.streampipes.model.client.ontology.RangeType;
-import org.apache.streampipes.storage.rdf4j.util.BackgroundKnowledgeUtils;
-import org.apache.streampipes.vocabulary.SO;
-import org.apache.streampipes.vocabulary.StreamPipes;
-
-import java.util.List;
-
public class QueryBuilder {
- private static final Logger LOG = LoggerFactory.getLogger(QueryBuilder.class);
-
- public static final String RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
- public static final String RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
- public static final String RDFS_CLASS = "http://www.w3.org/2000/01/rdf-schema#Class";
- public static final String RDFS_LABEL = "http://www.w3.org/2000/01/rdf-schema#label";
- public static final String RDFS_DESCRIPTION = "http://www.w3.org/2000/01/rdf-schema#description";
- public static final String RDFS_RANGE = "http://www.w3.org/2000/01/rdf-schema#range";
- public static final String RDFS_DOMAIN = "http://www.w3.org/2000/01/rdf-schema#domain";
- public static final String SP = StreamPipes.NS;
-
- public static final String SO_DOMAIN_INCLUDES = "http://schema.org/domainIncludes";
- public static final String SO_RANGE_INCLUDES = "http://schema.org/rangeIncludes";
-
public static String buildListDataStreamQuery() {
return "where { ?result rdf:type sp:DataStream. }";
}
@@ -60,275 +29,30 @@ public class QueryBuilder {
}
private static String getPrefix() {
- StringBuilder builder = new StringBuilder();
- builder.append("PREFIX sp:<https://streampipes.org/vocabulary/v1/>\n")
- .append("PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n");
-
- return builder.toString();
+ return "PREFIX sp:<https://streampipes.org/vocabulary/v1/>\n" +
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n";
}
public static String getMatching() {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix())
- .append("select ?d where {?a rdf:type sp:EventProperty. ?b rdf:type sp:EventSchema. ?b " +
- "sp:hasEventProperty ?a. ?a sp:hasPropertyName ?d}");
- return builder.toString();
- }
-
- public static String getAllStatements() {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix()).append("select ?a where { ?a ?b ?c }");
-
- return builder.toString();
+ return getPrefix() +
+ "select ?d where {?a rdf:type sp:EventProperty. ?b rdf:type sp:EventSchema. ?b " +
+ "sp:hasEventProperty ?a. ?a sp:hasPropertyName ?d}";
}
public static String buildListSEPAQuery() {
- StringBuilder builder = new StringBuilder();
- builder.append("where { ?result rdf:type sp:DataProcessorDescription. }");
-
- return builder.toString();
+ return "where { ?result rdf:type sp:DataProcessorDescription. }";
}
public static String buildListSECQuery() {
- StringBuilder builder = new StringBuilder();
- builder.append("where { ?result rdf:type sp:DataSinkDescription }");
-
- return builder.toString();
+ return "where { ?result rdf:type sp:DataSinkDescription }";
}
public static String getClasses() {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?result where {?result rdf:type <http://www.w3.org/2000/01/rdf-schema#Class>}");
- return builder.toString();
+ return getPrefix() + " select ?result where {?result rdf:type <http://www.w3.org/2000/01/rdf-schema#Class>}";
}
public static String getEventProperties() {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?result where {?result rdf:type <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>}");
- return builder.toString();
- }
-
- public static String getTypeDetails(String typeId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?label ?description ?domainPropertyId where { "
- + getLabelDescriptionQueryPart(typeId)
- + " ?domainPropertyId <" + SO_DOMAIN_INCLUDES + "> <" + typeId + "> . }");
- return builder.toString();
- }
-
- public static String getInstanceDetails(String instanceId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?label ?description ?property where { "
- + getLabelDescriptionQueryPart(instanceId)
- + " <" + instanceId + "> ?property ?o ."
- + " }");
-
- return builder.toString();
- }
-
- public static String getRdfType(String instanceId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?typeOf where { "
- + " <" + instanceId + "> <" + RDF_TYPE + "> " + " ?typeOf . }");
- return builder.toString();
- }
-
- public static String getSubclasses(String className) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?s where {?s <" + RDFS_SUBCLASS_OF + "> <" + className + ">}");
- return builder.toString();
- }
-
- public static String getInstances(String className) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?s where {?s <" + RDF_TYPE + "> <" + className + ">}");
- return builder.toString();
- }
-
- public static String getAutocompleteSuggestion(String propertyName) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?label ?value where { "//?s <" +RDF_TYPE +"> sepa:DomainConcept ."
- + "?s <" + propertyName + "> ?value ."
- + "?s rdfs:label ?label ."
- + "}"
- );
- return builder.toString();
- }
-
- public static String getProperty(String propertyId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?label ?description ?range ?rangeType where {"
- + getLabelDescriptionQueryPart(propertyId)
- + "<" + propertyId + "> <" + SO_RANGE_INCLUDES + "> " + " ?range ."
- + "?range <" + RDF_TYPE + "> " + " ?rangeType ."
- + "}");
- LOG.info(builder.toString());
- return builder.toString();
- }
-
- public static String getQuantitativeValueRange(String rangeId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?minValue ?maxValue ?unitCode where {"
- + "<" + rangeId + "> <" + RDF_TYPE + "> " + " <http://schema.org/QuantitativeValue> ."
- + "<" + rangeId + "> <" + SO.MinValue + "> " + " ?minValue ."
- + "<" + rangeId + "> <" + SO.MaxValue + "> " + " ?maxValue ."
- + "<" + rangeId + "> <" + SO.UnitCode + "> " + " ?unitCode ."
- + "}");
-
- return builder.toString();
- }
-
- public static String deletePropertyDetails(String propertyId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " DELETE { ?s ?p ?o }"
- + " WHERE { ?s ?p ?o ."
- + " FILTER (?s = <" + propertyId + "> && ("
- + " ?p = <" + RDFS_LABEL + "> || "
- + " ?p = <" + RDFS_DESCRIPTION + "> || "
- + " ?p = <" + SO_RANGE_INCLUDES + "> )) } ");
-
- return builder.toString();
- }
-
- public static String deleteConceptDetails(String conceptId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " DELETE { ?s ?p ?o }"
- + " WHERE { ?s ?p ?o ."
- + " FILTER ( (?s = <" + conceptId + "> && ("
- + " ?p = <" + RDFS_LABEL + "> || "
- + " ?p = <" + RDFS_DESCRIPTION + ">) || "
- + " ( ?o = <" + conceptId + "> && ?p = <" + SO_DOMAIN_INCLUDES + ">) )) } ");
-
- return builder.toString();
- }
-
- public static String addConceptDetails(Concept concept) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " INSERT DATA {"
- + "<" + concept.getElementHeader().getId() + "> <" + RDFS_LABEL + "> '" + concept.getRdfsLabel() + "' ."
- + "<" + concept.getElementHeader().getId() + "> <" + RDFS_DESCRIPTION + "> '" + concept.getRdfsDescription() + "' .");
-
- concept.getDomainProperties().forEach(dp -> builder.append("<" + dp.getElementHeader().getId() + "> <" + SO_DOMAIN_INCLUDES + "> <" + concept.getElementHeader().getId() + "> ."));
-
- builder.append(" }");
- return builder.toString();
-
- }
-
- public static String addPropertyDetails(Property property) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " INSERT DATA {"
- + "<" + property.getElementHeader().getId() + "> <" + RDFS_LABEL + "> '" + property.getRdfsLabel() + "' ."
- + "<" + property.getElementHeader().getId() + "> <" + RDFS_DESCRIPTION + "> '" + property.getRdfsDescription() + "' .");
-
- if (property.getRange().getRangeType() == RangeType.PRIMITIVE) {
- builder.append("<" + property.getElementHeader().getId() + "> <" + SO_RANGE_INCLUDES + "> <" + ((PrimitiveRange) property.getRange()).getRdfsDatatype() + "> .");
- } else if (property.getRange().getRangeType() == RangeType.QUANTITATIVE_VALUE) {
- builder.append("<" + property.getElementHeader().getId() + "> <" + SO_RANGE_INCLUDES + "> <" + SO.QuantitativeValue + "> .");
- } else if (property.getRange().getRangeType() == RangeType.ENUMERATION) {
- builder.append("");
- }
-
- builder.append(" }");
- return builder.toString();
-
- }
-
- public static String deleteInstanceDetails(String id) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " DELETE { ?s ?p ?o }"
- + " WHERE { ?s ?p ?o ."
- + " FILTER ((?s = <" + id + "> && ("
- + " ?p != <" + RDF_TYPE + "> )) || (?s = <" + id + "-qv>) || (?o = <" + id + "-qv>)) } ");
-
- return builder.toString();
- }
-
- public static String addInstanceDetails(Instance instance) {
-
- StringBuilder builder = new StringBuilder();
- String id = instance.getElementHeader().getId();
-
- builder.append(getPrefix() + " INSERT DATA {"
- + "<" + instance.getElementHeader().getId() + "> <" + RDFS_LABEL + "> '" + instance.getRdfsLabel() + "' ."
- + "<" + instance.getElementHeader().getId() + "> <" + RDFS_DESCRIPTION + "> '" + instance.getRdfsDescription() + "' .");
-
- for (Property property : instance.getDomainProperties()) {
- if (property.getRange().getRangeType() == RangeType.PRIMITIVE) {
- String value = ((PrimitiveRange) property.getRange()).getValue();
- String rangeTypeRdfs = ((PrimitiveRange) property.getRange()).getRdfsDatatype();
- try {
- builder.append("<" + id + "> <" + property.getElementHeader().getId() + "> " + BackgroundKnowledgeUtils.parse(value, rangeTypeRdfs) + " .");
- } catch (RepositoryException | IllegalArgumentException e) {
- e.printStackTrace();
- }
- } else if (property.getRange().getRangeType() == RangeType.QUANTITATIVE_VALUE) {
- builder.append("<" + id + "-qv> <" + RDF_TYPE + "> <" + SO.QuantitativeValue + "> .");
- builder.append("<" + id + "> <" + SO.QuantitativeValue + "> <" + id + "-qv> .");
- builder.append("<" + id + "-qv> <" + SO.MinValue + "> \"" + ((QuantitativeValueRange) property.getRange()).getMinValue() + "\" .");
- builder.append("<" + id + "-qv> <" + SO.MaxValue + "> \"" + ((QuantitativeValueRange) property.getRange()).getMaxValue() + "\" .");
- builder.append("<" + id + "-qv> <" + SO.UnitCode + "> \"" + ((QuantitativeValueRange) property.getRange()).getUnitCode() + "\" .");
- }
- }
-
- builder.append(" }");
- return builder.toString();
- }
-
- public static String getPrimitivePropertyValue(String instanceId,
- String propertyId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?value where {"
- + "<" + instanceId + "> <" + propertyId + "> " + " ?value ."
- + "}");
-
- return builder.toString();
- }
-
- public static String deleteResource(String resourceId) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " DELETE { ?s ?p ?o }"
- + " WHERE { ?s ?p ?o ."
- + " FILTER ((?s = <" + resourceId + ">) || (?p = <" + resourceId + ">) || (?o = <" + resourceId + ">)) } ");
-
- return builder.toString();
- }
-
- private static String getLabelDescriptionQueryPart(String subject) {
- StringBuilder builder = new StringBuilder();
- builder.append(" OPTIONAL { <" + subject + "> <" + RDFS_LABEL + "> " + " ?label . }"
- + " OPTIONAL { <" + subject + "> <" + RDFS_DESCRIPTION + "> " + " ?description . }");
- return builder.toString();
- }
-
- public static String getPropertyDetails(String requiredClass,
- String propertyId, List<OntologyQueryItem> requiredProperties) {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " select ?label ?description ?propertyValue where {"
- + " OPTIONAL { ?s <" + RDFS_LABEL + "> ?label . }"
- + " OPTIONAL { ?s <" + RDFS_DESCRIPTION + "> ?description . }"
- + " ?s <" + propertyId + "> ?propertyValue . ");
-
- for (OntologyQueryItem item : requiredProperties) {
- builder.append(" ?s <" + item.getPropertyId() + "> ?" + RandomStringUtils.randomAlphabetic(5) + " .");
- }
-
- if (requiredClass != null) {
- builder.append(" ?s <" + RDF_TYPE + "> <" + requiredClass + "> .");
- }
-
- builder.append(" }");
- LOG.info(builder.toString());
- return builder.toString();
-
- }
-
- public static String addRequiredTriples() {
- StringBuilder builder = new StringBuilder();
- builder.append(getPrefix() + " INSERT DATA {"
- + "sp:domainProperty <" + RDFS_RANGE + "> " + "rdf:Property ."
- + " }");
- return builder.toString();
+ return getPrefix() + " select ?result where {?result rdf:type <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>}";
}
}
diff --git a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/util/BackgroundKnowledgeUtils.java b/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/util/BackgroundKnowledgeUtils.java
deleted file mode 100644
index a03348a..0000000
--- a/streampipes-storage-rdf4j/src/main/java/org/apache/streampipes/storage/rdf4j/util/BackgroundKnowledgeUtils.java
+++ /dev/null
@@ -1,92 +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.storage.rdf4j.util;
-
-import org.eclipse.rdf4j.model.Literal;
-import org.eclipse.rdf4j.model.ValueFactory;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryConnection;
-import org.eclipse.rdf4j.repository.RepositoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.streampipes.model.client.ontology.Namespace;
-import org.apache.streampipes.storage.Rdf4JStorageManager;
-import org.apache.streampipes.storage.rdf4j.ontology.RangeQueryExecutor;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-public class BackgroundKnowledgeUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(BackgroundKnowledgeUtils.class);
-
- public static boolean hasNamespace(String elementId) {
- try {
- List<Namespace> namespaces = Rdf4JStorageManager.INSTANCE.getBackgroundKnowledgeStorage().getNamespaces();
- return namespaces.stream().anyMatch(n -> elementId.startsWith(n.getNamespaceId()));
- } catch (RepositoryException e) {
- return false;
- }
- }
-
- public static Optional<Namespace> getNamespace(String elementId) {
- try {
- return Rdf4JStorageManager.INSTANCE.getBackgroundKnowledgeStorage().getNamespaces().stream().filter(n -> elementId.startsWith(n.getNamespaceId())).findFirst();
- } catch (RepositoryException e) {
- return Optional.empty();
- }
- }
-
- public static Literal parse(String propertyValue, String rdfsType) throws RepositoryException {
- Repository repository = Rdf4JStorageManager.INSTANCE.getRepository();
- RepositoryConnection connection = null;
- ValueFactory vf = null;
-
- Literal result;
- try {
- connection = repository.getConnection();
- vf = connection.getValueFactory();
- } catch (RepositoryException e) {
- e.printStackTrace();
- }
- LOG.info(rdfsType);
- if (rdfsType.startsWith(RangeQueryExecutor.RANGE_TYPE_RDFS_LITERAL.get(0))) {
- result = vf.createLiteral(propertyValue);
- } else if (rdfsType.startsWith(RangeQueryExecutor.RANGE_TYPE_RDFS_LITERAL.get(1))) {
- result = vf.createLiteral(Boolean.parseBoolean(propertyValue));
- } else if (rdfsType.startsWith(RangeQueryExecutor.RANGE_TYPE_RDFS_LITERAL.get(2))) {
- result = vf.createLiteral(Integer.parseInt(propertyValue));
- } else if (rdfsType.startsWith(RangeQueryExecutor.RANGE_TYPE_RDFS_LITERAL.get(3))) {
- result = vf.createLiteral(Double.parseDouble(propertyValue));
- } else if (rdfsType.startsWith(RangeQueryExecutor.RANGE_TYPE_RDFS_LITERAL.get(4))) {
- result = vf.createLiteral(Float.parseFloat(propertyValue));
- } else {
- connection.close();
- throw new IllegalArgumentException();
- }
- connection.close();
- return result;
- }
-
- public static <T> List<T> filterDuplicates(List<T> nodes) {
- return nodes.parallelStream().distinct().collect(Collectors.toList());
- }
-
-}