From 624c1bed2af891372fdc47d32050f23b95637657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Mon, 25 Nov 2024 16:34:27 +0800 Subject: [PATCH 01/12] feat(knext & cloud-ext):Extend the knext search API parameters --- .../request/query/FullTextSearchQuery.java | 4 + .../request/query/VectorSearchQuery.java | 9 +- python/knext/KNEXT_VERSION | 2 +- python/knext/knext/__init__.py | 2 +- .../knext/{graph_algo => graph}/__init__.py | 0 .../knext/{graph_algo => graph}/client.py | 12 +- .../{graph_algo => graph}/rest/__init__.py | 0 .../{graph_algo => graph}/rest/graph_api.py | 0 .../rest/models/__init__.py | 0 .../rest/models/delete_edge_request.py | 0 .../rest/models/delete_vertex_request.py | 0 .../rest/models/edge_record_instance.py | 0 .../models/get_page_rank_scores_request.py | 0 ...et_page_rank_scores_request_start_nodes.py | 0 .../rest/models/page_rank_score_instance.py | 0 .../rest/models/upsert_edge_request.py | 0 .../rest/models/upsert_vertex_request.py | 0 .../rest/models/vertex_record_instance.py | 0 .../rest/models/writer_graph_request.py | 0 python/knext/knext/search/client.py | 8 +- .../search/rest/models/text_search_request.py | 101 +++++++------- .../rest/models/vector_search_request.py | 125 +++++++++--------- .../service/request/TextSearchRequest.java | 7 + .../service/request/VectorSearchRequest.java | 17 ++- 24 files changed, 152 insertions(+), 135 deletions(-) rename python/knext/knext/{graph_algo => graph}/__init__.py (100%) rename python/knext/knext/{graph_algo => graph}/client.py (92%) rename python/knext/knext/{graph_algo => graph}/rest/__init__.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/graph_api.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/__init__.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/delete_edge_request.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/delete_vertex_request.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/edge_record_instance.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/get_page_rank_scores_request.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/get_page_rank_scores_request_start_nodes.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/page_rank_score_instance.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/upsert_edge_request.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/upsert_vertex_request.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/vertex_record_instance.py (100%) rename python/knext/knext/{graph_algo => graph}/rest/models/writer_graph_request.py (100%) diff --git a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java index 01ba1f34f..1c0540ee5 100644 --- a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java +++ b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java @@ -14,14 +14,18 @@ package com.antgroup.openspg.cloudext.interfaces.searchengine.model.request.query; import java.util.List; +import java.util.Map; import javax.annotation.Nullable; import lombok.Getter; import lombok.NonNull; +import lombok.Setter; public class FullTextSearchQuery extends BaseQuery { @Getter private final String queryString; @Getter private final List labelConstraints; + @Getter @Setter + private Map params; public FullTextSearchQuery(@NonNull String queryString) { this(queryString, null); diff --git a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java index a6a5212b2..055e241d9 100644 --- a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java +++ b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java @@ -15,6 +15,9 @@ import lombok.Getter; import lombok.NonNull; +import lombok.Setter; + +import java.util.Map; public class VectorSearchQuery extends BaseQuery { @@ -22,14 +25,16 @@ public class VectorSearchQuery extends BaseQuery { @Getter private final String propertyKey; @Getter private final float[] queryVector; @Getter private final int efSearch; + @Getter @Setter + private Map params; public VectorSearchQuery( - @NonNull String label, @NonNull String propertyKey, float @NonNull [] queryVector) { + String label, @NonNull String propertyKey, float @NonNull [] queryVector) { this(label, propertyKey, queryVector, -1); } public VectorSearchQuery( - @NonNull String label, + String label, @NonNull String propertyKey, float @NonNull [] queryVector, int efSearch) { diff --git a/python/knext/KNEXT_VERSION b/python/knext/KNEXT_VERSION index f44d044dc..461d83ed9 100644 --- a/python/knext/KNEXT_VERSION +++ b/python/knext/KNEXT_VERSION @@ -1 +1 @@ -0.0.3.20241022.2 +0.6.0.20241125.1 diff --git a/python/knext/knext/__init__.py b/python/knext/knext/__init__.py index 368d87015..ee80cff59 100644 --- a/python/knext/knext/__init__.py +++ b/python/knext/knext/__init__.py @@ -11,7 +11,7 @@ __package_name__ = "openspg-knext" -__version__ = "0.0.3.20241022.2" +__version__ = "0.6.0.20241125.1" from knext.common.env import init_env diff --git a/python/knext/knext/graph_algo/__init__.py b/python/knext/knext/graph/__init__.py similarity index 100% rename from python/knext/knext/graph_algo/__init__.py rename to python/knext/knext/graph/__init__.py diff --git a/python/knext/knext/graph_algo/client.py b/python/knext/knext/graph/client.py similarity index 92% rename from python/knext/knext/graph_algo/client.py rename to python/knext/knext/graph/client.py index 07fb5e7f9..a1ae4dd48 100644 --- a/python/knext/knext/graph_algo/client.py +++ b/python/knext/knext/graph/client.py @@ -13,15 +13,9 @@ from knext.common.base.client import Client from knext.common.rest import ApiClient, Configuration -from knext.graph_algo import ( - GetPageRankScoresRequest, - GetPageRankScoresRequestStartNodes, - WriterGraphRequest, -) -from knext.graph_algo import rest +from knext.graph import rest, GetPageRankScoresRequest, GetPageRankScoresRequestStartNodes, WriterGraphRequest - -class GraphAlgoClient(Client): +class GraphClient(Client): """ """ def __init__(self, host_addr: str = None, project_id: int = None): @@ -69,7 +63,7 @@ def write_graph(self, sub_graph: dict, operation: str, lead_to_builder: bool): if __name__ == "__main__": - sc = GraphAlgoClient("http://127.0.0.1:8887", 4) + sc = GraphClient("http://127.0.0.1:8887", 4) out = sc.calculate_pagerank_scores( "Entity", [{"name": "Anxiety_and_nervousness", "type": "Entity"}] ) diff --git a/python/knext/knext/graph_algo/rest/__init__.py b/python/knext/knext/graph/rest/__init__.py similarity index 100% rename from python/knext/knext/graph_algo/rest/__init__.py rename to python/knext/knext/graph/rest/__init__.py diff --git a/python/knext/knext/graph_algo/rest/graph_api.py b/python/knext/knext/graph/rest/graph_api.py similarity index 100% rename from python/knext/knext/graph_algo/rest/graph_api.py rename to python/knext/knext/graph/rest/graph_api.py diff --git a/python/knext/knext/graph_algo/rest/models/__init__.py b/python/knext/knext/graph/rest/models/__init__.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/__init__.py rename to python/knext/knext/graph/rest/models/__init__.py diff --git a/python/knext/knext/graph_algo/rest/models/delete_edge_request.py b/python/knext/knext/graph/rest/models/delete_edge_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/delete_edge_request.py rename to python/knext/knext/graph/rest/models/delete_edge_request.py diff --git a/python/knext/knext/graph_algo/rest/models/delete_vertex_request.py b/python/knext/knext/graph/rest/models/delete_vertex_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/delete_vertex_request.py rename to python/knext/knext/graph/rest/models/delete_vertex_request.py diff --git a/python/knext/knext/graph_algo/rest/models/edge_record_instance.py b/python/knext/knext/graph/rest/models/edge_record_instance.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/edge_record_instance.py rename to python/knext/knext/graph/rest/models/edge_record_instance.py diff --git a/python/knext/knext/graph_algo/rest/models/get_page_rank_scores_request.py b/python/knext/knext/graph/rest/models/get_page_rank_scores_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/get_page_rank_scores_request.py rename to python/knext/knext/graph/rest/models/get_page_rank_scores_request.py diff --git a/python/knext/knext/graph_algo/rest/models/get_page_rank_scores_request_start_nodes.py b/python/knext/knext/graph/rest/models/get_page_rank_scores_request_start_nodes.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/get_page_rank_scores_request_start_nodes.py rename to python/knext/knext/graph/rest/models/get_page_rank_scores_request_start_nodes.py diff --git a/python/knext/knext/graph_algo/rest/models/page_rank_score_instance.py b/python/knext/knext/graph/rest/models/page_rank_score_instance.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/page_rank_score_instance.py rename to python/knext/knext/graph/rest/models/page_rank_score_instance.py diff --git a/python/knext/knext/graph_algo/rest/models/upsert_edge_request.py b/python/knext/knext/graph/rest/models/upsert_edge_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/upsert_edge_request.py rename to python/knext/knext/graph/rest/models/upsert_edge_request.py diff --git a/python/knext/knext/graph_algo/rest/models/upsert_vertex_request.py b/python/knext/knext/graph/rest/models/upsert_vertex_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/upsert_vertex_request.py rename to python/knext/knext/graph/rest/models/upsert_vertex_request.py diff --git a/python/knext/knext/graph_algo/rest/models/vertex_record_instance.py b/python/knext/knext/graph/rest/models/vertex_record_instance.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/vertex_record_instance.py rename to python/knext/knext/graph/rest/models/vertex_record_instance.py diff --git a/python/knext/knext/graph_algo/rest/models/writer_graph_request.py b/python/knext/knext/graph/rest/models/writer_graph_request.py similarity index 100% rename from python/knext/knext/graph_algo/rest/models/writer_graph_request.py rename to python/knext/knext/graph/rest/models/writer_graph_request.py diff --git a/python/knext/knext/search/client.py b/python/knext/knext/search/client.py index 6c5c08f03..0a70e7f03 100644 --- a/python/knext/knext/search/client.py +++ b/python/knext/knext/search/client.py @@ -28,14 +28,14 @@ def __init__(self, host_addr: str = None, project_id: int = None): api_client=ApiClient(configuration=Configuration(host=host_addr)) ) - def search_text(self, query_string, label_constraints=None, topk=10): - req = TextSearchRequest(self._project_id, query_string, label_constraints, topk) + def search_text(self, query_string, label_constraints=None, topk=10, params=None): + req = TextSearchRequest(self._project_id, query_string, label_constraints, topk, params) records = self._rest_client.search_text_post(text_search_request=req) return [idx_record_to_dict(record) for record in records] - def search_vector(self, label, property_key, query_vector, topk=10, ef_search=None): + def search_vector(self, label, property_key, query_vector, topk=10, ef_search=None, params=None): req = VectorSearchRequest( - self._project_id, label, property_key, query_vector, ef_search, topk + self._project_id, label, property_key, query_vector, ef_search, topk, params ) records = self._rest_client.search_vector_post(vector_search_request=req) return [idx_record_to_dict(record) for record in records] diff --git a/python/knext/knext/search/rest/models/text_search_request.py b/python/knext/knext/search/rest/models/text_search_request.py index 360ba9a93..e578599e6 100644 --- a/python/knext/knext/search/rest/models/text_search_request.py +++ b/python/knext/knext/search/rest/models/text_search_request.py @@ -10,7 +10,6 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. - """ knext @@ -44,27 +43,22 @@ class TextSearchRequest(object): and the value is json key in definition. """ openapi_types = { - "project_id": "int", - "query_string": "str", - "label_constraints": "list[str]", - "topk": "int", + 'project_id': 'int', + 'query_string': 'str', + 'label_constraints': 'list[str]', + 'topk': 'int', + 'params': 'object' } attribute_map = { - "project_id": "projectId", - "query_string": "queryString", - "label_constraints": "labelConstraints", - "topk": "topk", + 'project_id': 'projectId', + 'query_string': 'queryString', + 'label_constraints': 'labelConstraints', + 'topk': 'topk', + 'params': 'params' } - def __init__( - self, - project_id=None, - query_string=None, - label_constraints=None, - topk=None, - local_vars_configuration=None, - ): # noqa: E501 + def __init__(self, project_id=None, query_string=None, label_constraints=None, topk=None, params=None, local_vars_configuration=None): # noqa: E501 """TextSearchRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -74,12 +68,14 @@ def __init__( self._query_string = None self._label_constraints = None self._topk = None + self._params = None self.discriminator = None self.project_id = project_id self.query_string = query_string self.label_constraints = label_constraints self.topk = topk + self.params = params @property def project_id(self): @@ -99,12 +95,8 @@ def project_id(self, project_id): :param project_id: The project_id of this TextSearchRequest. # noqa: E501 :type: int """ - if ( - self.local_vars_configuration.client_side_validation and project_id is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `project_id`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 + raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 self._project_id = project_id @@ -126,13 +118,8 @@ def query_string(self, query_string): :param query_string: The query_string of this TextSearchRequest. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation - and query_string is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `query_string`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and query_string is None: # noqa: E501 + raise ValueError("Invalid value for `query_string`, must not be `None`") # noqa: E501 self._query_string = query_string @@ -154,6 +141,9 @@ def label_constraints(self, label_constraints): :param label_constraints: The label_constraints of this TextSearchRequest. # noqa: E501 :type: list[str] """ + if self.local_vars_configuration.client_side_validation and label_constraints is None: # noqa: E501 + raise ValueError("Invalid value for `label_constraints`, must not be `None`") # noqa: E501 + self._label_constraints = label_constraints @property @@ -174,15 +164,34 @@ def topk(self, topk): :param topk: The topk of this TextSearchRequest. # noqa: E501 :type: int """ - if ( - self.local_vars_configuration.client_side_validation and topk is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `topk`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and topk is None: # noqa: E501 + raise ValueError("Invalid value for `topk`, must not be `None`") # noqa: E501 self._topk = topk + @property + def params(self): + """Gets the params of this TextSearchRequest. # noqa: E501 + + + :return: The params of this TextSearchRequest. # noqa: E501 + :rtype: object + """ + return self._params + + @params.setter + def params(self, params): + """Sets the params of this TextSearchRequest. + + + :param params: The params of this TextSearchRequest. # noqa: E501 + :type: object + """ + if self.local_vars_configuration.client_side_validation and params is None: # noqa: E501 + raise ValueError("Invalid value for `params`, must not be `None`") # noqa: E501 + + self._params = params + def to_dict(self): """Returns the model properties as a dict""" result = {} @@ -190,20 +199,18 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list( - map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) - ) + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict( - map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") - else item, - value.items(), - ) - ) + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) else: result[attr] = value diff --git a/python/knext/knext/search/rest/models/vector_search_request.py b/python/knext/knext/search/rest/models/vector_search_request.py index 641f8c2b7..b6d12a851 100644 --- a/python/knext/knext/search/rest/models/vector_search_request.py +++ b/python/knext/knext/search/rest/models/vector_search_request.py @@ -10,7 +10,6 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. - """ knext @@ -44,33 +43,26 @@ class VectorSearchRequest(object): and the value is json key in definition. """ openapi_types = { - "project_id": "int", - "label": "str", - "property_key": "str", - "query_vector": "list[float]", - "ef_search": "int", - "topk": "int", + 'project_id': 'int', + 'label': 'str', + 'property_key': 'str', + 'query_vector': 'list[float]', + 'ef_search': 'int', + 'topk': 'int', + 'params': 'object' } attribute_map = { - "project_id": "projectId", - "label": "label", - "property_key": "propertyKey", - "query_vector": "queryVector", - "ef_search": "efSearch", - "topk": "topk", + 'project_id': 'projectId', + 'label': 'label', + 'property_key': 'propertyKey', + 'query_vector': 'queryVector', + 'ef_search': 'efSearch', + 'topk': 'topk', + 'params': 'params' } - def __init__( - self, - project_id=None, - label=None, - property_key=None, - query_vector=None, - ef_search=None, - topk=None, - local_vars_configuration=None, - ): # noqa: E501 + def __init__(self, project_id=None, label=None, property_key=None, query_vector=None, ef_search=None, topk=None, params=None, local_vars_configuration=None): # noqa: E501 """VectorSearchRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -82,6 +74,7 @@ def __init__( self._query_vector = None self._ef_search = None self._topk = None + self._params = None self.discriminator = None self.project_id = project_id @@ -91,6 +84,7 @@ def __init__( if ef_search is not None: self.ef_search = ef_search self.topk = topk + self.params = params @property def project_id(self): @@ -110,12 +104,8 @@ def project_id(self, project_id): :param project_id: The project_id of this VectorSearchRequest. # noqa: E501 :type: int """ - if ( - self.local_vars_configuration.client_side_validation and project_id is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `project_id`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 + raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 self._project_id = project_id @@ -137,12 +127,8 @@ def label(self, label): :param label: The label of this VectorSearchRequest. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and label is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `label`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and label is None: # noqa: E501 + raise ValueError("Invalid value for `label`, must not be `None`") # noqa: E501 self._label = label @@ -164,13 +150,8 @@ def property_key(self, property_key): :param property_key: The property_key of this VectorSearchRequest. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation - and property_key is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `property_key`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and property_key is None: # noqa: E501 + raise ValueError("Invalid value for `property_key`, must not be `None`") # noqa: E501 self._property_key = property_key @@ -192,13 +173,8 @@ def query_vector(self, query_vector): :param query_vector: The query_vector of this VectorSearchRequest. # noqa: E501 :type: list[float] """ - if ( - self.local_vars_configuration.client_side_validation - and query_vector is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `query_vector`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and query_vector is None: # noqa: E501 + raise ValueError("Invalid value for `query_vector`, must not be `None`") # noqa: E501 self._query_vector = query_vector @@ -241,15 +217,34 @@ def topk(self, topk): :param topk: The topk of this VectorSearchRequest. # noqa: E501 :type: int """ - if ( - self.local_vars_configuration.client_side_validation and topk is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `topk`, must not be `None`" - ) # noqa: E501 + if self.local_vars_configuration.client_side_validation and topk is None: # noqa: E501 + raise ValueError("Invalid value for `topk`, must not be `None`") # noqa: E501 self._topk = topk + @property + def params(self): + """Gets the params of this VectorSearchRequest. # noqa: E501 + + + :return: The params of this VectorSearchRequest. # noqa: E501 + :rtype: object + """ + return self._params + + @params.setter + def params(self, params): + """Sets the params of this VectorSearchRequest. + + + :param params: The params of this VectorSearchRequest. # noqa: E501 + :type: object + """ + if self.local_vars_configuration.client_side_validation and params is None: # noqa: E501 + raise ValueError("Invalid value for `params`, must not be `None`") # noqa: E501 + + self._params = params + def to_dict(self): """Returns the model properties as a dict""" result = {} @@ -257,20 +252,18 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list( - map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) - ) + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict( - map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") - else item, - value.items(), - ) - ) + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) else: result[attr] = value diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java index 8b686214e..388524fc3 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java @@ -13,13 +13,20 @@ package com.antgroup.openspg.server.api.facade.dto.service.request; +import java.util.Map; import java.util.Set; + +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@AllArgsConstructor +@NoArgsConstructor public class TextSearchRequest { private Long projectId; private String queryString; private Set labelConstraints; private Integer topk; + private Map params; } diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java index 75fc9649c..58d2065c8 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java @@ -13,14 +13,21 @@ package com.antgroup.openspg.server.api.facade.dto.service.request; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; @Data +@NoArgsConstructor +@AllArgsConstructor public class VectorSearchRequest { private Long projectId; - private final String label; - private final String propertyKey; - private final float[] queryVector; - private final Integer efSearch; - private final Integer topk; + private String label; + private String propertyKey; + private float[] queryVector; + private Integer efSearch; + private Integer topk; + private Map params; } From 4dfe62812bd4bfd526027aaee5b28ae52d177ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Mon, 25 Nov 2024 21:12:24 +0800 Subject: [PATCH 02/12] feat(knext)graph client --- .../model/lpg/schema/EdgeTypeName.java | 8 +- .../knext/common/rest/models/__init__.py | 2 +- python/knext/knext/graph/__init__.py | 33 +-- python/knext/knext/graph/client.py | 36 ++- python/knext/knext/graph/rest/__init__.py | 33 +-- python/knext/knext/graph/rest/graph_api.py | 224 ++++++++++++++++++ .../knext/knext/graph/rest/models/__init__.py | 31 +-- python/knext/upload_dev.sh | 2 +- 8 files changed, 319 insertions(+), 50 deletions(-) diff --git a/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/schema/EdgeTypeName.java b/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/schema/EdgeTypeName.java index 8457e3e11..819647561 100644 --- a/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/schema/EdgeTypeName.java +++ b/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/schema/EdgeTypeName.java @@ -17,6 +17,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; /** * {@link EdgeTypeName EdgeTypeName} is the unique identifier of {@link EdgeType EdgeType}, and it @@ -25,15 +26,16 @@ */ @Getter @AllArgsConstructor +@NoArgsConstructor @EqualsAndHashCode(callSuper = false) public class EdgeTypeName extends BaseValObj { - private final String startVertexType; + private String startVertexType; /** The label of edge type */ - private final String edgeLabel; + private String edgeLabel; - private final String endVertexType; + private String endVertexType; public static EdgeTypeName parse(String edgeTypeName) { String[] splits = edgeTypeName.split("_"); diff --git a/python/knext/knext/common/rest/models/__init__.py b/python/knext/knext/common/rest/models/__init__.py index 616e15f03..ca17c13e8 100644 --- a/python/knext/knext/common/rest/models/__init__.py +++ b/python/knext/knext/common/rest/models/__init__.py @@ -14,5 +14,5 @@ from knext.reasoner.rest.models import * from knext.project.rest.models import * from knext.search.rest.models import * -from knext.graph_algo.rest.models import * +from knext.graph.rest.models import * from knext.thinker.rest.models import * diff --git a/python/knext/knext/graph/__init__.py b/python/knext/knext/graph/__init__.py index b4afad6a7..bd4388a5c 100644 --- a/python/knext/knext/graph/__init__.py +++ b/python/knext/knext/graph/__init__.py @@ -28,21 +28,24 @@ __version__ = "1.0.0" # import apis into sdk package -from knext.graph_algo.rest.graph_api import GraphApi +from knext.graph.rest.graph_api import GraphApi # import models into model package -from knext.graph_algo.rest.models.get_page_rank_scores_request import ( - GetPageRankScoresRequest, -) -from knext.graph_algo.rest.models.get_page_rank_scores_request_start_nodes import ( - GetPageRankScoresRequestStartNodes, -) -from knext.graph_algo.rest.models.page_rank_score_instance import PageRankScoreInstance -from knext.graph_algo.rest.models.delete_vertex_request import DeleteVertexRequest -from knext.graph_algo.rest.models.delete_edge_request import DeleteEdgeRequest -from knext.graph_algo.rest.models.edge_record_instance import EdgeRecordInstance -from knext.graph_algo.rest.models.upsert_vertex_request import UpsertVertexRequest -from knext.graph_algo.rest.models.upsert_edge_request import UpsertEdgeRequest -from knext.graph_algo.rest.models.vertex_record_instance import VertexRecordInstance -from knext.graph_algo.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance +from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest +from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest +from knext.graph.rest.models.edge_record_instance import EdgeRecordInstance +from knext.graph.rest.models.upsert_vertex_request import UpsertVertexRequest +from knext.graph.rest.models.upsert_edge_request import UpsertEdgeRequest +from knext.graph.rest.models.vertex_record_instance import VertexRecordInstance +from knext.graph.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.edge_record import EdgeRecord +from knext.graph.rest.models.edge_type_name import EdgeTypeName +from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest +from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord +from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.vertex_record import VertexRecord +from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index a1ae4dd48..f777c8598 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -13,7 +13,8 @@ from knext.common.base.client import Client from knext.common.rest import ApiClient, Configuration -from knext.graph import rest, GetPageRankScoresRequest, GetPageRankScoresRequestStartNodes, WriterGraphRequest +from knext.graph import (rest, GetPageRankScoresRequest, GetPageRankScoresRequestStartNodes, WriterGraphRequest, + QueryVertexRequest, ExpendOneHopRequest, EdgeTypeName) class GraphClient(Client): """ """ @@ -61,11 +62,44 @@ def write_graph(self, sub_graph: dict, operation: str, lead_to_builder: bool): ) self._rest_client.graph_writer_graph_post(writer_graph_request=request) + def query_vertex(self, type_name: str, biz_id: str): + request = QueryVertexRequest( + project_id=self._project_id, + type_name=type_name, + biz_id=biz_id + ) + return self._rest_client.graph_query_vertex_post(query_vertex_request=request) + + def expend_one_hop(self, type_name: str, biz_id: str, edge_type_name_constraint: List[EdgeTypeName] = None): + request = ExpendOneHopRequest( + project_id=self._project_id, + type_name=type_name, + biz_id=biz_id, + edge_type_name_constraint=edge_type_name_constraint + ) + return self._rest_client.graph_expend_one_hop_post(expend_one_hop_request=request) if __name__ == "__main__": + ''' sc = GraphClient("http://127.0.0.1:8887", 4) out = sc.calculate_pagerank_scores( "Entity", [{"name": "Anxiety_and_nervousness", "type": "Entity"}] ) for o in out: print(o) + ''' + + #test ant main-site + client = GraphClient("https://spgservice-standard-pre.alipay.com", 644000146) + v = client.query_vertex("Antwork.EntityName", "千三") + #print(v) + + edge_name = EdgeTypeName(start_vertex_type="BCTEST.DeleteDataEntity3", + edge_label="concept", + end_vertex_type="BCTEST.TestConcept") + client2 = GraphClient("https://spgservice-standard-pre.alipay.com", 363000133) + edge_type_name_constraint =[] + edge_type_name_constraint.append(edge_name) + g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", edge_type_name_constraint) + #g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name]) + print(g1) \ No newline at end of file diff --git a/python/knext/knext/graph/rest/__init__.py b/python/knext/knext/graph/rest/__init__.py index b4afad6a7..bd4388a5c 100644 --- a/python/knext/knext/graph/rest/__init__.py +++ b/python/knext/knext/graph/rest/__init__.py @@ -28,21 +28,24 @@ __version__ = "1.0.0" # import apis into sdk package -from knext.graph_algo.rest.graph_api import GraphApi +from knext.graph.rest.graph_api import GraphApi # import models into model package -from knext.graph_algo.rest.models.get_page_rank_scores_request import ( - GetPageRankScoresRequest, -) -from knext.graph_algo.rest.models.get_page_rank_scores_request_start_nodes import ( - GetPageRankScoresRequestStartNodes, -) -from knext.graph_algo.rest.models.page_rank_score_instance import PageRankScoreInstance -from knext.graph_algo.rest.models.delete_vertex_request import DeleteVertexRequest -from knext.graph_algo.rest.models.delete_edge_request import DeleteEdgeRequest -from knext.graph_algo.rest.models.edge_record_instance import EdgeRecordInstance -from knext.graph_algo.rest.models.upsert_vertex_request import UpsertVertexRequest -from knext.graph_algo.rest.models.upsert_edge_request import UpsertEdgeRequest -from knext.graph_algo.rest.models.vertex_record_instance import VertexRecordInstance -from knext.graph_algo.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance +from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest +from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest +from knext.graph.rest.models.edge_record_instance import EdgeRecordInstance +from knext.graph.rest.models.upsert_vertex_request import UpsertVertexRequest +from knext.graph.rest.models.upsert_edge_request import UpsertEdgeRequest +from knext.graph.rest.models.vertex_record_instance import VertexRecordInstance +from knext.graph.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.edge_record import EdgeRecord +from knext.graph.rest.models.edge_type_name import EdgeTypeName +from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest +from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord +from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.vertex_record import VertexRecord +from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/rest/graph_api.py b/python/knext/knext/graph/rest/graph_api.py index 1256b12ea..15223ad96 100644 --- a/python/knext/knext/graph/rest/graph_api.py +++ b/python/knext/knext/graph/rest/graph_api.py @@ -753,3 +753,227 @@ def graph_writer_graph_post_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get("_request_timeout"), collection_formats=collection_formats, ) + + def graph_expend_one_hop_post(self, **kwargs): # noqa: E501 + """expend_one_hop # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_expend_one_hop_post(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param ExpendOneHopRequest expend_one_hop_request: + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: ExpendOneHopResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + return self.graph_expend_one_hop_post_with_http_info(**kwargs) # noqa: E501 + + def graph_expend_one_hop_post_with_http_info(self, **kwargs): # noqa: E501 + """expend_one_hop # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_expend_one_hop_post_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param ExpendOneHopRequest expend_one_hop_request: + :param _return_http_data_only: response data without head status code + and headers + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: tuple(ExpendOneHopResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = [ + 'expend_one_hop_request' + ] + all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout' + ] + ) + + for key, val in six.iteritems(local_var_params['kwargs']): + if key not in all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method graph_expend_one_hop_post" % key + ) + local_var_params[key] = val + del local_var_params['kwargs'] + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'expend_one_hop_request' in local_var_params: + body_params = local_var_params['expend_one_hop_request'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + '/graph/expendOneHop', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='ExpendOneHopResponse', # noqa: E501 + auth_settings=auth_settings, + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats=collection_formats) + + def graph_query_vertex_post(self, **kwargs): # noqa: E501 + """query_vertex # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_query_vertex_post(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param QueryVertexRequest query_vertex_request: + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: VertexRecord + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + return self.graph_query_vertex_post_with_http_info(**kwargs) # noqa: E501 + + def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 + """query_vertex # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_query_vertex_post_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param QueryVertexRequest query_vertex_request: + :param _return_http_data_only: response data without head status code + and headers + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: tuple(VertexRecord, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = [ + 'query_vertex_request' + ] + all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout' + ] + ) + + for key, val in six.iteritems(local_var_params['kwargs']): + if key not in all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method graph_query_vertex_post" % key + ) + local_var_params[key] = val + del local_var_params['kwargs'] + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'query_vertex_request' in local_var_params: + body_params = local_var_params['query_vertex_request'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + '/graph/queryVertex', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='VertexRecord', # noqa: E501 + auth_settings=auth_settings, + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats=collection_formats) diff --git a/python/knext/knext/graph/rest/models/__init__.py b/python/knext/knext/graph/rest/models/__init__.py index 2c1ef91e5..6114b8fc9 100644 --- a/python/knext/knext/graph/rest/models/__init__.py +++ b/python/knext/knext/graph/rest/models/__init__.py @@ -16,17 +16,20 @@ from __future__ import absolute_import # import models into model package -from knext.graph_algo.rest.models.get_page_rank_scores_request import ( - GetPageRankScoresRequest, -) -from knext.graph_algo.rest.models.get_page_rank_scores_request_start_nodes import ( - GetPageRankScoresRequestStartNodes, -) -from knext.graph_algo.rest.models.page_rank_score_instance import PageRankScoreInstance -from knext.graph_algo.rest.models.delete_vertex_request import DeleteVertexRequest -from knext.graph_algo.rest.models.delete_edge_request import DeleteEdgeRequest -from knext.graph_algo.rest.models.edge_record_instance import EdgeRecordInstance -from knext.graph_algo.rest.models.upsert_vertex_request import UpsertVertexRequest -from knext.graph_algo.rest.models.upsert_edge_request import UpsertEdgeRequest -from knext.graph_algo.rest.models.vertex_record_instance import VertexRecordInstance -from knext.graph_algo.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance +from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest +from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest +from knext.graph.rest.models.edge_record_instance import EdgeRecordInstance +from knext.graph.rest.models.upsert_vertex_request import UpsertVertexRequest +from knext.graph.rest.models.upsert_edge_request import UpsertEdgeRequest +from knext.graph.rest.models.vertex_record_instance import VertexRecordInstance +from knext.graph.rest.models.writer_graph_request import WriterGraphRequest +from knext.graph.rest.models.edge_record import EdgeRecord +from knext.graph.rest.models.edge_type_name import EdgeTypeName +from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest +from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord +from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.vertex_record import VertexRecord +from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/upload_dev.sh b/python/knext/upload_dev.sh index 57b43dbb7..d1278ea94 100644 --- a/python/knext/upload_dev.sh +++ b/python/knext/upload_dev.sh @@ -13,6 +13,6 @@ rm -rf build rm -rf dist -python setup.py sdist bdist_wheel +python3 setup.py sdist bdist_wheel twine upload dist/* \ No newline at end of file From fd555a9f6e7977ebf32c2f1009be3d10d70caddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Mon, 25 Nov 2024 22:42:50 +0800 Subject: [PATCH 03/12] feat(knext) add apis for graph client --- .../knext/graph/rest/models/edge_record.py | 239 ++++++++++++++++++ .../knext/graph/rest/models/edge_type_name.py | 186 ++++++++++++++ .../rest/models/expend_one_hop_request.py | 211 ++++++++++++++++ .../rest/models/expend_one_hop_response.py | 183 ++++++++++++++ .../graph/rest/models/lpg_property_record.py | 158 ++++++++++++ .../graph/rest/models/query_vertex_request.py | 186 ++++++++++++++ .../knext/graph/rest/models/vertex_record.py | 213 ++++++++++++++++ 7 files changed, 1376 insertions(+) create mode 100644 python/knext/knext/graph/rest/models/edge_record.py create mode 100644 python/knext/knext/graph/rest/models/edge_type_name.py create mode 100644 python/knext/knext/graph/rest/models/expend_one_hop_request.py create mode 100644 python/knext/knext/graph/rest/models/expend_one_hop_response.py create mode 100644 python/knext/knext/graph/rest/models/lpg_property_record.py create mode 100644 python/knext/knext/graph/rest/models/query_vertex_request.py create mode 100644 python/knext/knext/graph/rest/models/vertex_record.py diff --git a/python/knext/knext/graph/rest/models/edge_record.py b/python/knext/knext/graph/rest/models/edge_record.py new file mode 100644 index 000000000..f94f70090 --- /dev/null +++ b/python/knext/knext/graph/rest/models/edge_record.py @@ -0,0 +1,239 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class EdgeRecord(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'record_type': 'str', + 'edge_type': 'EdgeTypeName', + 'src_id': 'str', + 'dst_id': 'str', + 'properties': 'list[LpgPropertyRecord]' + } + + attribute_map = { + 'record_type': 'recordType', + 'edge_type': 'edgeType', + 'src_id': 'srcId', + 'dst_id': 'dstId', + 'properties': 'properties' + } + + def __init__(self, record_type=None, edge_type=None, src_id=None, dst_id=None, properties=None, local_vars_configuration=None): # noqa: E501 + """EdgeRecord - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._record_type = None + self._edge_type = None + self._src_id = None + self._dst_id = None + self._properties = None + self.discriminator = None + + self.record_type = record_type + self.edge_type = edge_type + self.src_id = src_id + self.dst_id = dst_id + if properties is not None: + self.properties = properties + + @property + def record_type(self): + """Gets the record_type of this EdgeRecord. # noqa: E501 + + + :return: The record_type of this EdgeRecord. # noqa: E501 + :rtype: str + """ + return self._record_type + + @record_type.setter + def record_type(self, record_type): + """Sets the record_type of this EdgeRecord. + + + :param record_type: The record_type of this EdgeRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and record_type is None: # noqa: E501 + raise ValueError("Invalid value for `record_type`, must not be `None`") # noqa: E501 + + self._record_type = record_type + + @property + def edge_type(self): + """Gets the edge_type of this EdgeRecord. # noqa: E501 + + + :return: The edge_type of this EdgeRecord. # noqa: E501 + :rtype: EdgeTypeName + """ + return self._edge_type + + @edge_type.setter + def edge_type(self, edge_type): + """Sets the edge_type of this EdgeRecord. + + + :param edge_type: The edge_type of this EdgeRecord. # noqa: E501 + :type: EdgeTypeName + """ + if self.local_vars_configuration.client_side_validation and edge_type is None: # noqa: E501 + raise ValueError("Invalid value for `edge_type`, must not be `None`") # noqa: E501 + + self._edge_type = edge_type + + @property + def src_id(self): + """Gets the src_id of this EdgeRecord. # noqa: E501 + + + :return: The src_id of this EdgeRecord. # noqa: E501 + :rtype: str + """ + return self._src_id + + @src_id.setter + def src_id(self, src_id): + """Sets the src_id of this EdgeRecord. + + + :param src_id: The src_id of this EdgeRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and src_id is None: # noqa: E501 + raise ValueError("Invalid value for `src_id`, must not be `None`") # noqa: E501 + + self._src_id = src_id + + @property + def dst_id(self): + """Gets the dst_id of this EdgeRecord. # noqa: E501 + + + :return: The dst_id of this EdgeRecord. # noqa: E501 + :rtype: str + """ + return self._dst_id + + @dst_id.setter + def dst_id(self, dst_id): + """Sets the dst_id of this EdgeRecord. + + + :param dst_id: The dst_id of this EdgeRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and dst_id is None: # noqa: E501 + raise ValueError("Invalid value for `dst_id`, must not be `None`") # noqa: E501 + + self._dst_id = dst_id + + @property + def properties(self): + """Gets the properties of this EdgeRecord. # noqa: E501 + + + :return: The properties of this EdgeRecord. # noqa: E501 + :rtype: list[LpgPropertyRecord] + """ + return self._properties + + @properties.setter + def properties(self, properties): + """Sets the properties of this EdgeRecord. + + + :param properties: The properties of this EdgeRecord. # noqa: E501 + :type: list[LpgPropertyRecord] + """ + + self._properties = properties + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, EdgeRecord): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, EdgeRecord): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/edge_type_name.py b/python/knext/knext/graph/rest/models/edge_type_name.py new file mode 100644 index 000000000..aa4161f2b --- /dev/null +++ b/python/knext/knext/graph/rest/models/edge_type_name.py @@ -0,0 +1,186 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class EdgeTypeName(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'start_vertex_type': 'str', + 'edge_label': 'str', + 'end_vertex_type': 'str' + } + + attribute_map = { + 'start_vertex_type': 'startVertexType', + 'edge_label': 'edgeLabel', + 'end_vertex_type': 'endVertexType' + } + + def __init__(self, start_vertex_type=None, edge_label=None, end_vertex_type=None, local_vars_configuration=None): # noqa: E501 + """EdgeTypeName - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._start_vertex_type = None + self._edge_label = None + self._end_vertex_type = None + self.discriminator = None + + self.start_vertex_type = start_vertex_type + self.edge_label = edge_label + self.end_vertex_type = end_vertex_type + + @property + def start_vertex_type(self): + """Gets the start_vertex_type of this EdgeTypeName. # noqa: E501 + + + :return: The start_vertex_type of this EdgeTypeName. # noqa: E501 + :rtype: str + """ + return self._start_vertex_type + + @start_vertex_type.setter + def start_vertex_type(self, start_vertex_type): + """Sets the start_vertex_type of this EdgeTypeName. + + + :param start_vertex_type: The start_vertex_type of this EdgeTypeName. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and start_vertex_type is None: # noqa: E501 + raise ValueError("Invalid value for `start_vertex_type`, must not be `None`") # noqa: E501 + + self._start_vertex_type = start_vertex_type + + @property + def edge_label(self): + """Gets the edge_label of this EdgeTypeName. # noqa: E501 + + + :return: The edge_label of this EdgeTypeName. # noqa: E501 + :rtype: str + """ + return self._edge_label + + @edge_label.setter + def edge_label(self, edge_label): + """Sets the edge_label of this EdgeTypeName. + + + :param edge_label: The edge_label of this EdgeTypeName. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and edge_label is None: # noqa: E501 + raise ValueError("Invalid value for `edge_label`, must not be `None`") # noqa: E501 + + self._edge_label = edge_label + + @property + def end_vertex_type(self): + """Gets the end_vertex_type of this EdgeTypeName. # noqa: E501 + + + :return: The end_vertex_type of this EdgeTypeName. # noqa: E501 + :rtype: str + """ + return self._end_vertex_type + + @end_vertex_type.setter + def end_vertex_type(self, end_vertex_type): + """Sets the end_vertex_type of this EdgeTypeName. + + + :param end_vertex_type: The end_vertex_type of this EdgeTypeName. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and end_vertex_type is None: # noqa: E501 + raise ValueError("Invalid value for `end_vertex_type`, must not be `None`") # noqa: E501 + + self._end_vertex_type = end_vertex_type + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, EdgeTypeName): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, EdgeTypeName): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/expend_one_hop_request.py b/python/knext/knext/graph/rest/models/expend_one_hop_request.py new file mode 100644 index 000000000..15883ee18 --- /dev/null +++ b/python/knext/knext/graph/rest/models/expend_one_hop_request.py @@ -0,0 +1,211 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class ExpendOneHopRequest(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'project_id': 'int', + 'type_name': 'str', + 'biz_id': 'str', + 'edge_type_name_constraint': 'list[EdgeTypeName]' + } + + attribute_map = { + 'project_id': 'projectId', + 'type_name': 'typeName', + 'biz_id': 'bizId', + 'edge_type_name_constraint': 'edgeTypeNameConstraint' + } + + def __init__(self, project_id=None, type_name=None, biz_id=None, edge_type_name_constraint=None, local_vars_configuration=None): # noqa: E501 + """ExpendOneHopRequest - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._project_id = None + self._type_name = None + self._biz_id = None + self._edge_type_name_constraint = None + self.discriminator = None + + self.project_id = project_id + self.type_name = type_name + self.biz_id = biz_id + self.edge_type_name_constraint = edge_type_name_constraint + + @property + def project_id(self): + """Gets the project_id of this ExpendOneHopRequest. # noqa: E501 + + + :return: The project_id of this ExpendOneHopRequest. # noqa: E501 + :rtype: int + """ + return self._project_id + + @project_id.setter + def project_id(self, project_id): + """Sets the project_id of this ExpendOneHopRequest. + + + :param project_id: The project_id of this ExpendOneHopRequest. # noqa: E501 + :type: int + """ + if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 + raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + + self._project_id = project_id + + @property + def type_name(self): + """Gets the type_name of this ExpendOneHopRequest. # noqa: E501 + + + :return: The type_name of this ExpendOneHopRequest. # noqa: E501 + :rtype: str + """ + return self._type_name + + @type_name.setter + def type_name(self, type_name): + """Sets the type_name of this ExpendOneHopRequest. + + + :param type_name: The type_name of this ExpendOneHopRequest. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and type_name is None: # noqa: E501 + raise ValueError("Invalid value for `type_name`, must not be `None`") # noqa: E501 + + self._type_name = type_name + + @property + def biz_id(self): + """Gets the biz_id of this ExpendOneHopRequest. # noqa: E501 + + + :return: The biz_id of this ExpendOneHopRequest. # noqa: E501 + :rtype: str + """ + return self._biz_id + + @biz_id.setter + def biz_id(self, biz_id): + """Sets the biz_id of this ExpendOneHopRequest. + + + :param biz_id: The biz_id of this ExpendOneHopRequest. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and biz_id is None: # noqa: E501 + raise ValueError("Invalid value for `biz_id`, must not be `None`") # noqa: E501 + + self._biz_id = biz_id + + @property + def edge_type_name_constraint(self): + """Gets the edge_type_name_constraint of this ExpendOneHopRequest. # noqa: E501 + + + :return: The edge_type_name_constraint of this ExpendOneHopRequest. # noqa: E501 + :rtype: list[EdgeTypeName] + """ + return self._edge_type_name_constraint + + @edge_type_name_constraint.setter + def edge_type_name_constraint(self, edge_type_name_constraint): + """Sets the edge_type_name_constraint of this ExpendOneHopRequest. + + + :param edge_type_name_constraint: The edge_type_name_constraint of this ExpendOneHopRequest. # noqa: E501 + :type: list[EdgeTypeName] + """ + + self._edge_type_name_constraint = edge_type_name_constraint + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ExpendOneHopRequest): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, ExpendOneHopRequest): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/expend_one_hop_response.py b/python/knext/knext/graph/rest/models/expend_one_hop_response.py new file mode 100644 index 000000000..0be7a654c --- /dev/null +++ b/python/knext/knext/graph/rest/models/expend_one_hop_response.py @@ -0,0 +1,183 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class ExpendOneHopResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'vertex': 'VertexRecord', + 'edges': 'list[EdgeRecord]', + 'adjacent_vertices': 'list[VertexRecord]' + } + + attribute_map = { + 'vertex': 'vertex', + 'edges': 'edges', + 'adjacent_vertices': 'adjacentVertices' + } + + def __init__(self, vertex=None, edges=None, adjacent_vertices=None, local_vars_configuration=None): # noqa: E501 + """ExpendOneHopResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._vertex = None + self._edges = None + self._adjacent_vertices = None + self.discriminator = None + + if vertex is not None: + self.vertex = vertex + if edges is not None: + self.edges = edges + if adjacent_vertices is not None: + self.adjacent_vertices = adjacent_vertices + + @property + def vertex(self): + """Gets the vertex of this ExpendOneHopResponse. # noqa: E501 + + + :return: The vertex of this ExpendOneHopResponse. # noqa: E501 + :rtype: VertexRecord + """ + return self._vertex + + @vertex.setter + def vertex(self, vertex): + """Sets the vertex of this ExpendOneHopResponse. + + + :param vertex: The vertex of this ExpendOneHopResponse. # noqa: E501 + :type: VertexRecord + """ + + self._vertex = vertex + + @property + def edges(self): + """Gets the edges of this ExpendOneHopResponse. # noqa: E501 + + + :return: The edges of this ExpendOneHopResponse. # noqa: E501 + :rtype: list[EdgeRecord] + """ + return self._edges + + @edges.setter + def edges(self, edges): + """Sets the edges of this ExpendOneHopResponse. + + + :param edges: The edges of this ExpendOneHopResponse. # noqa: E501 + :type: list[EdgeRecord] + """ + + self._edges = edges + + @property + def adjacent_vertices(self): + """Gets the adjacent_vertices of this ExpendOneHopResponse. # noqa: E501 + + + :return: The adjacent_vertices of this ExpendOneHopResponse. # noqa: E501 + :rtype: list[VertexRecord] + """ + return self._adjacent_vertices + + @adjacent_vertices.setter + def adjacent_vertices(self, adjacent_vertices): + """Sets the adjacent_vertices of this ExpendOneHopResponse. + + + :param adjacent_vertices: The adjacent_vertices of this ExpendOneHopResponse. # noqa: E501 + :type: list[VertexRecord] + """ + + self._adjacent_vertices = adjacent_vertices + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ExpendOneHopResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, ExpendOneHopResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/lpg_property_record.py b/python/knext/knext/graph/rest/models/lpg_property_record.py new file mode 100644 index 000000000..6cfb61264 --- /dev/null +++ b/python/knext/knext/graph/rest/models/lpg_property_record.py @@ -0,0 +1,158 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class LpgPropertyRecord(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'name': 'str', + 'value': 'str' + } + + attribute_map = { + 'name': 'name', + 'value': 'value' + } + + def __init__(self, name=None, value=None, local_vars_configuration=None): # noqa: E501 + """LpgPropertyRecord - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._name = None + self._value = None + self.discriminator = None + + self.name = name + if value is not None: + self.value = value + + @property + def name(self): + """Gets the name of this LpgPropertyRecord. # noqa: E501 + + + :return: The name of this LpgPropertyRecord. # noqa: E501 + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this LpgPropertyRecord. + + + :param name: The name of this LpgPropertyRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and name is None: # noqa: E501 + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + + self._name = name + + @property + def value(self): + """Gets the value of this LpgPropertyRecord. # noqa: E501 + + + :return: The value of this LpgPropertyRecord. # noqa: E501 + :rtype: str + """ + return self._value + + @value.setter + def value(self, value): + """Sets the value of this LpgPropertyRecord. + + + :param value: The value of this LpgPropertyRecord. # noqa: E501 + :type: str + """ + + self._value = value + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, LpgPropertyRecord): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, LpgPropertyRecord): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/query_vertex_request.py b/python/knext/knext/graph/rest/models/query_vertex_request.py new file mode 100644 index 000000000..050b4160e --- /dev/null +++ b/python/knext/knext/graph/rest/models/query_vertex_request.py @@ -0,0 +1,186 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class QueryVertexRequest(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'project_id': 'int', + 'type_name': 'str', + 'biz_id': 'str' + } + + attribute_map = { + 'project_id': 'projectId', + 'type_name': 'typeName', + 'biz_id': 'bizId' + } + + def __init__(self, project_id=None, type_name=None, biz_id=None, local_vars_configuration=None): # noqa: E501 + """QueryVertexRequest - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._project_id = None + self._type_name = None + self._biz_id = None + self.discriminator = None + + self.project_id = project_id + self.type_name = type_name + self.biz_id = biz_id + + @property + def project_id(self): + """Gets the project_id of this QueryVertexRequest. # noqa: E501 + + + :return: The project_id of this QueryVertexRequest. # noqa: E501 + :rtype: int + """ + return self._project_id + + @project_id.setter + def project_id(self, project_id): + """Sets the project_id of this QueryVertexRequest. + + + :param project_id: The project_id of this QueryVertexRequest. # noqa: E501 + :type: int + """ + if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 + raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + + self._project_id = project_id + + @property + def type_name(self): + """Gets the type_name of this QueryVertexRequest. # noqa: E501 + + + :return: The type_name of this QueryVertexRequest. # noqa: E501 + :rtype: str + """ + return self._type_name + + @type_name.setter + def type_name(self, type_name): + """Sets the type_name of this QueryVertexRequest. + + + :param type_name: The type_name of this QueryVertexRequest. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and type_name is None: # noqa: E501 + raise ValueError("Invalid value for `type_name`, must not be `None`") # noqa: E501 + + self._type_name = type_name + + @property + def biz_id(self): + """Gets the biz_id of this QueryVertexRequest. # noqa: E501 + + + :return: The biz_id of this QueryVertexRequest. # noqa: E501 + :rtype: str + """ + return self._biz_id + + @biz_id.setter + def biz_id(self, biz_id): + """Sets the biz_id of this QueryVertexRequest. + + + :param biz_id: The biz_id of this QueryVertexRequest. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and biz_id is None: # noqa: E501 + raise ValueError("Invalid value for `biz_id`, must not be `None`") # noqa: E501 + + self._biz_id = biz_id + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, QueryVertexRequest): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, QueryVertexRequest): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/vertex_record.py b/python/knext/knext/graph/rest/models/vertex_record.py new file mode 100644 index 000000000..7da594cda --- /dev/null +++ b/python/knext/knext/graph/rest/models/vertex_record.py @@ -0,0 +1,213 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class VertexRecord(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'record_type': 'str', + 'vertex_type': 'str', + 'id': 'str', + 'properties': 'list[LpgPropertyRecord]' + } + + attribute_map = { + 'record_type': 'recordType', + 'vertex_type': 'vertexType', + 'id': 'id', + 'properties': 'properties' + } + + def __init__(self, record_type=None, vertex_type=None, id=None, properties=None, local_vars_configuration=None): # noqa: E501 + """VertexRecord - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._record_type = None + self._vertex_type = None + self._id = None + self._properties = None + self.discriminator = None + + self.record_type = record_type + self.vertex_type = vertex_type + self.id = id + self.properties = properties + + @property + def record_type(self): + """Gets the record_type of this VertexRecord. # noqa: E501 + + + :return: The record_type of this VertexRecord. # noqa: E501 + :rtype: str + """ + return self._record_type + + @record_type.setter + def record_type(self, record_type): + """Sets the record_type of this VertexRecord. + + + :param record_type: The record_type of this VertexRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and record_type is None: # noqa: E501 + raise ValueError("Invalid value for `record_type`, must not be `None`") # noqa: E501 + + self._record_type = record_type + + @property + def vertex_type(self): + """Gets the vertex_type of this VertexRecord. # noqa: E501 + + + :return: The vertex_type of this VertexRecord. # noqa: E501 + :rtype: str + """ + return self._vertex_type + + @vertex_type.setter + def vertex_type(self, vertex_type): + """Sets the vertex_type of this VertexRecord. + + + :param vertex_type: The vertex_type of this VertexRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and vertex_type is None: # noqa: E501 + raise ValueError("Invalid value for `vertex_type`, must not be `None`") # noqa: E501 + + self._vertex_type = vertex_type + + @property + def id(self): + """Gets the id of this VertexRecord. # noqa: E501 + + + :return: The id of this VertexRecord. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this VertexRecord. + + + :param id: The id of this VertexRecord. # noqa: E501 + :type: str + """ + if self.local_vars_configuration.client_side_validation and id is None: # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def properties(self): + """Gets the properties of this VertexRecord. # noqa: E501 + + + :return: The properties of this VertexRecord. # noqa: E501 + :rtype: list[LpgPropertyRecord] + """ + return self._properties + + @properties.setter + def properties(self, properties): + """Sets the properties of this VertexRecord. + + + :param properties: The properties of this VertexRecord. # noqa: E501 + :type: list[LpgPropertyRecord] + """ + if self.local_vars_configuration.client_side_validation and properties is None: # noqa: E501 + raise ValueError("Invalid value for `properties`, must not be `None`") # noqa: E501 + + self._properties = properties + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, VertexRecord): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, VertexRecord): + return True + + return self.to_dict() != other.to_dict() From 7985fb79a1a48d9f21e152a1b4635f102de8e3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Tue, 26 Nov 2024 13:50:45 +0800 Subject: [PATCH 04/12] feat(server-api)add graph query apis. --- builder/model/pom.xml | 4 - .../tugraph/TuGraphStoreClient.java | 12 +- .../util/ElasticSearchRecordUtils.java | 2 +- .../model/lpg/record/VertexRecord.java | 10 +- .../request/query/FullTextSearchQuery.java | 3 +- .../request/query/VectorSearchQuery.java | 11 +- common/util/pom.xml | 10 +- .../openspg/common/util/JsonUtils.java | 1 - .../openspg/common/util}/SchemaJsonUtils.java | 2 +- python/knext/knext/graph/__init__.py | 8 +- python/knext/knext/graph/client.py | 56 ++++++--- python/knext/knext/graph/rest/__init__.py | 8 +- python/knext/knext/graph/rest/graph_api.py | 104 +++++++++-------- .../knext/knext/graph/rest/models/__init__.py | 8 +- .../knext/graph/rest/models/edge_record.py | 82 ++++++++----- .../knext/graph/rest/models/edge_type_name.py | 66 +++++++---- .../rest/models/expend_one_hop_request.py | 69 +++++++---- .../rest/models/expend_one_hop_response.py | 40 ++++--- .../graph/rest/models/lpg_property_record.py | 42 +++---- .../graph/rest/models/query_vertex_request.py | 64 ++++++---- .../knext/graph/rest/models/vertex_record.py | 73 ++++++++---- python/knext/knext/search/client.py | 8 +- .../search/rest/models/text_search_request.py | 92 ++++++++++----- .../rest/models/vector_search_request.py | 110 ++++++++++++------ server/api/facade/pom.xml | 8 +- .../server/api/facade/ApiConstants.java | 5 - .../service/request/ExpendOneHopRequest.java | 22 ++++ .../service/request/QueryVertexRequest.java | 19 +++ .../service/request/TextSearchRequest.java | 1 - .../service/request/VectorSearchRequest.java | 3 +- .../response/ExpendOneHopResponse.java | 22 ++++ .../server/api/http/server/WebMvcConfig.java | 2 +- .../http/server/openapi/GraphController.java | 42 +++++++ .../server/biz/service/GraphManager.java | 6 + .../biz/service/impl/GraphManagerImpl.java | 81 ++++++++++++- .../schema/convertor/ExtConfigConvertor.java | 2 +- .../schema/convertor/OntologyConvertor.java | 2 +- .../convertor/SimplePropertyConvertor.java | 2 +- .../convertor/SimpleSubPropertyConvertor.java | 2 +- 39 files changed, 761 insertions(+), 343 deletions(-) rename {server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade => common/util/src/main/java/com/antgroup/openspg/common/util}/SchemaJsonUtils.java (99%) create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java diff --git a/builder/model/pom.xml b/builder/model/pom.xml index 3ac4c9523..d901d3a4e 100644 --- a/builder/model/pom.xml +++ b/builder/model/pom.xml @@ -43,9 +43,5 @@ commons-codec commons-codec - - com.antgroup.openspg - common-util - diff --git a/cloudext/impl/graph-store/tugraph/src/main/java/com/antgroup/openspg/cloudext/impl/graphstore/tugraph/TuGraphStoreClient.java b/cloudext/impl/graph-store/tugraph/src/main/java/com/antgroup/openspg/cloudext/impl/graphstore/tugraph/TuGraphStoreClient.java index 27528bd0c..ddcfb9bce 100644 --- a/cloudext/impl/graph-store/tugraph/src/main/java/com/antgroup/openspg/cloudext/impl/graphstore/tugraph/TuGraphStoreClient.java +++ b/cloudext/impl/graph-store/tugraph/src/main/java/com/antgroup/openspg/cloudext/impl/graphstore/tugraph/TuGraphStoreClient.java @@ -48,7 +48,6 @@ import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.operation.SchemaAtomicOperationEnum; import com.antgroup.openspg.cloudext.interfaces.graphstore.util.TypeNameUtils; import com.antgroup.openspg.core.schema.model.type.BasicTypeEnum; -import com.antgroup.openspg.server.api.facade.ApiConstants; import com.antgroup.tugraph.TuGraphDbRpcClient; import com.google.common.collect.Lists; import java.io.InputStream; @@ -78,13 +77,16 @@ public class TuGraphStoreClient extends BaseLPGGraphStoreClient { @Getter private final LPGTypeNameConvertor typeNameConvertor; @Getter private final String connUrl; + private static final String ACCESS_ID = "accessId"; + private static final String ACCESS_KEY = "accessKey"; + private static final String TIMEOUT = "timeout"; + public TuGraphStoreClient(String connUrl, LPGTypeNameConvertor typeNameConvertor) { UriComponents uriComponents = UriComponentsBuilder.fromUriString(connUrl).build(); this.connUrl = connUrl; this.graphName = uriComponents.getQueryParams().getFirst(TuGraphConstants.GRAPH_NAME); this.timeout = - Double.parseDouble( - String.valueOf(uriComponents.getQueryParams().getFirst(ApiConstants.TIMEOUT))); + Double.parseDouble(String.valueOf(uriComponents.getQueryParams().getFirst(TIMEOUT))); this.client = initTuGraphClient(uriComponents); this.internalIdGenerator = new NoChangedIdGenerator(); this.typeNameConvertor = typeNameConvertor; @@ -149,8 +151,8 @@ public void close() throws Exception { private TuGraphDbRpcClient initTuGraphClient(UriComponents uriComponents) { String host = String.format("%s:%s", uriComponents.getHost(), uriComponents.getPort()); - String accessId = uriComponents.getQueryParams().getFirst(ApiConstants.ACCESS_ID); - String accessKey = uriComponents.getQueryParams().getFirst(ApiConstants.ACCESS_KEY); + String accessId = uriComponents.getQueryParams().getFirst(ACCESS_ID); + String accessKey = uriComponents.getQueryParams().getFirst(ACCESS_KEY); TuGraphDbRpcClient client = null; try { client = new TuGraphDbRpcClient(host, accessId, accessKey); diff --git a/cloudext/impl/search-engine/elasticsearch/src/main/java/com/antgroup/openspg/cloudext/impl/searchengine/elasticsearch/util/ElasticSearchRecordUtils.java b/cloudext/impl/search-engine/elasticsearch/src/main/java/com/antgroup/openspg/cloudext/impl/searchengine/elasticsearch/util/ElasticSearchRecordUtils.java index 9f82f121a..f3ac53284 100644 --- a/cloudext/impl/search-engine/elasticsearch/src/main/java/com/antgroup/openspg/cloudext/impl/searchengine/elasticsearch/util/ElasticSearchRecordUtils.java +++ b/cloudext/impl/search-engine/elasticsearch/src/main/java/com/antgroup/openspg/cloudext/impl/searchengine/elasticsearch/util/ElasticSearchRecordUtils.java @@ -31,8 +31,8 @@ import com.antgroup.openspg.cloudext.interfaces.searchengine.model.request.query.MatchQuery; import com.antgroup.openspg.cloudext.interfaces.searchengine.model.request.query.QueryGroup; import com.antgroup.openspg.cloudext.interfaces.searchengine.model.request.query.TermQuery; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.antgroup.openspg.common.util.StringUtils; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import com.dtflys.forest.http.ForestResponse; import com.google.gson.reflect.TypeToken; import java.net.URLEncoder; diff --git a/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/record/VertexRecord.java b/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/record/VertexRecord.java index 43fe5cc0a..f351f7a5d 100644 --- a/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/record/VertexRecord.java +++ b/cloudext/interface/graph-store/src/main/java/com/antgroup/openspg/cloudext/interfaces/graphstore/model/lpg/record/VertexRecord.java @@ -14,7 +14,7 @@ package com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.VertexType; -import com.antgroup.openspg.server.api.facade.ApiConstants; +import com.google.common.collect.Lists; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,12 +35,18 @@ public class VertexRecord extends BaseLPGRecord { private final String id; + private static final long DEFAULT_VERSION = 0L; + public VertexRecord(String id, String vertexType, List properties) { super(LPGRecordTypeEnum.VERTEX, properties); this.id = id; this.vertexType = vertexType; } + public VertexRecord(String id, String vertexType) { + this(id, vertexType, Lists.newArrayList()); + } + @Override public Map toPropertyMapWithId() { Map otherProperties = toPropertyMap(); @@ -55,7 +61,7 @@ public Map> toPropertyMapWithIdAndVersion() { otherProperties.forEach( (key, value) -> { TreeMap propertyVersion = new TreeMap<>(); - propertyVersion.put(ApiConstants.DEFAULT_VERSION, value); + propertyVersion.put(DEFAULT_VERSION, value); results.put(key, propertyVersion); }); return results; diff --git a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java index 1c0540ee5..e4c629576 100644 --- a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java +++ b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/FullTextSearchQuery.java @@ -24,8 +24,7 @@ public class FullTextSearchQuery extends BaseQuery { @Getter private final String queryString; @Getter private final List labelConstraints; - @Getter @Setter - private Map params; + @Getter @Setter private Map params; public FullTextSearchQuery(@NonNull String queryString) { this(queryString, null); diff --git a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java index 055e241d9..3cc6c1a19 100644 --- a/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java +++ b/cloudext/interface/search-engine/src/main/java/com/antgroup/openspg/cloudext/interfaces/searchengine/model/request/query/VectorSearchQuery.java @@ -13,20 +13,18 @@ package com.antgroup.openspg.cloudext.interfaces.searchengine.model.request.query; +import java.util.Map; import lombok.Getter; import lombok.NonNull; import lombok.Setter; -import java.util.Map; - public class VectorSearchQuery extends BaseQuery { @Getter private final String label; @Getter private final String propertyKey; @Getter private final float[] queryVector; @Getter private final int efSearch; - @Getter @Setter - private Map params; + @Getter @Setter private Map params; public VectorSearchQuery( String label, @NonNull String propertyKey, float @NonNull [] queryVector) { @@ -34,10 +32,7 @@ public VectorSearchQuery( } public VectorSearchQuery( - String label, - @NonNull String propertyKey, - float @NonNull [] queryVector, - int efSearch) { + String label, @NonNull String propertyKey, float @NonNull [] queryVector, int efSearch) { this.label = label; this.propertyKey = propertyKey; this.queryVector = queryVector; diff --git a/common/util/pom.xml b/common/util/pom.xml index 1e0e20d17..15e7b96c7 100644 --- a/common/util/pom.xml +++ b/common/util/pom.xml @@ -25,7 +25,7 @@ com.antgroup.openspg.server - api-facade + core-schema-model commons-codec @@ -59,5 +59,13 @@ org.neo4j.driver neo4j-java-driver + + com.google.code.gson + gson + + + org.danilopianini + gson-extras + diff --git a/common/util/src/main/java/com/antgroup/openspg/common/util/JsonUtils.java b/common/util/src/main/java/com/antgroup/openspg/common/util/JsonUtils.java index ee83328bd..02f41a47a 100644 --- a/common/util/src/main/java/com/antgroup/openspg/common/util/JsonUtils.java +++ b/common/util/src/main/java/com/antgroup/openspg/common/util/JsonUtils.java @@ -13,7 +13,6 @@ package com.antgroup.openspg.common.util; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import lombok.extern.slf4j.Slf4j; @Slf4j diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/SchemaJsonUtils.java b/common/util/src/main/java/com/antgroup/openspg/common/util/SchemaJsonUtils.java similarity index 99% rename from server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/SchemaJsonUtils.java rename to common/util/src/main/java/com/antgroup/openspg/common/util/SchemaJsonUtils.java index 7f796fb20..f6a64fae4 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/SchemaJsonUtils.java +++ b/common/util/src/main/java/com/antgroup/openspg/common/util/SchemaJsonUtils.java @@ -11,7 +11,7 @@ * or implied. */ -package com.antgroup.openspg.server.api.facade; +package com.antgroup.openspg.common.util; import com.antgroup.openspg.core.schema.model.constraint.BaseConstraintItem; import com.antgroup.openspg.core.schema.model.constraint.ConstraintTypeEnum; diff --git a/python/knext/knext/graph/__init__.py b/python/knext/knext/graph/__init__.py index bd4388a5c..143f4a25d 100644 --- a/python/knext/knext/graph/__init__.py +++ b/python/knext/knext/graph/__init__.py @@ -32,8 +32,12 @@ # import models into model package -from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest -from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.get_page_rank_scores_request import ( + GetPageRankScoresRequest, +) +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import ( + GetPageRankScoresRequestStartNodes, +) from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index f777c8598..687b8bf8d 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -13,8 +13,16 @@ from knext.common.base.client import Client from knext.common.rest import ApiClient, Configuration -from knext.graph import (rest, GetPageRankScoresRequest, GetPageRankScoresRequestStartNodes, WriterGraphRequest, - QueryVertexRequest, ExpendOneHopRequest, EdgeTypeName) +from knext.graph import ( + rest, + GetPageRankScoresRequest, + GetPageRankScoresRequestStartNodes, + WriterGraphRequest, + QueryVertexRequest, + ExpendOneHopRequest, + EdgeTypeName, +) + class GraphClient(Client): """ """ @@ -64,42 +72,52 @@ def write_graph(self, sub_graph: dict, operation: str, lead_to_builder: bool): def query_vertex(self, type_name: str, biz_id: str): request = QueryVertexRequest( - project_id=self._project_id, - type_name=type_name, - biz_id=biz_id + project_id=self._project_id, type_name=type_name, biz_id=biz_id ) return self._rest_client.graph_query_vertex_post(query_vertex_request=request) - def expend_one_hop(self, type_name: str, biz_id: str, edge_type_name_constraint: List[EdgeTypeName] = None): + def expend_one_hop( + self, + type_name: str, + biz_id: str, + edge_type_name_constraint: List[EdgeTypeName] = None, + ): request = ExpendOneHopRequest( project_id=self._project_id, type_name=type_name, biz_id=biz_id, - edge_type_name_constraint=edge_type_name_constraint + edge_type_name_constraint=edge_type_name_constraint, + ) + return self._rest_client.graph_expend_one_hop_post( + expend_one_hop_request=request ) - return self._rest_client.graph_expend_one_hop_post(expend_one_hop_request=request) + if __name__ == "__main__": - ''' + """ sc = GraphClient("http://127.0.0.1:8887", 4) out = sc.calculate_pagerank_scores( "Entity", [{"name": "Anxiety_and_nervousness", "type": "Entity"}] ) for o in out: print(o) - ''' + """ - #test ant main-site + # test ant main-site client = GraphClient("https://spgservice-standard-pre.alipay.com", 644000146) v = client.query_vertex("Antwork.EntityName", "千三") - #print(v) + # print(v) - edge_name = EdgeTypeName(start_vertex_type="BCTEST.DeleteDataEntity3", - edge_label="concept", - end_vertex_type="BCTEST.TestConcept") + edge_name = EdgeTypeName( + start_vertex_type="BCTEST.DeleteDataEntity3", + edge_label="concept", + end_vertex_type="BCTEST.TestConcept", + ) client2 = GraphClient("https://spgservice-standard-pre.alipay.com", 363000133) - edge_type_name_constraint =[] + edge_type_name_constraint = [] edge_type_name_constraint.append(edge_name) - g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", edge_type_name_constraint) - #g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name]) - print(g1) \ No newline at end of file + g1 = client2.expend_one_hop( + "BCTEST.DeleteDataEntity3", "秉初测试", edge_type_name_constraint + ) + # g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name]) + print(g1) diff --git a/python/knext/knext/graph/rest/__init__.py b/python/knext/knext/graph/rest/__init__.py index bd4388a5c..143f4a25d 100644 --- a/python/knext/knext/graph/rest/__init__.py +++ b/python/knext/knext/graph/rest/__init__.py @@ -32,8 +32,12 @@ # import models into model package -from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest -from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.get_page_rank_scores_request import ( + GetPageRankScoresRequest, +) +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import ( + GetPageRankScoresRequestStartNodes, +) from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest diff --git a/python/knext/knext/graph/rest/graph_api.py b/python/knext/knext/graph/rest/graph_api.py index 15223ad96..788310519 100644 --- a/python/knext/knext/graph/rest/graph_api.py +++ b/python/knext/knext/graph/rest/graph_api.py @@ -775,7 +775,7 @@ def graph_expend_one_hop_post(self, **kwargs): # noqa: E501 If the method is called asynchronously, returns the request thread. """ - kwargs['_return_http_data_only'] = True + kwargs["_return_http_data_only"] = True return self.graph_expend_one_hop_post_with_http_info(**kwargs) # noqa: E501 def graph_expend_one_hop_post_with_http_info(self, **kwargs): # noqa: E501 @@ -804,26 +804,24 @@ def graph_expend_one_hop_post_with_http_info(self, **kwargs): # noqa: E501 local_var_params = locals() - all_params = [ - 'expend_one_hop_request' - ] + all_params = ["expend_one_hop_request"] all_params.extend( [ - 'async_req', - '_return_http_data_only', - '_preload_content', - '_request_timeout' + "async_req", + "_return_http_data_only", + "_preload_content", + "_request_timeout", ] ) - for key, val in six.iteritems(local_var_params['kwargs']): + for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method graph_expend_one_hop_post" % key ) local_var_params[key] = val - del local_var_params['kwargs'] + del local_var_params["kwargs"] collection_formats = {} @@ -837,34 +835,42 @@ def graph_expend_one_hop_post_with_http_info(self, **kwargs): # noqa: E501 local_var_files = {} body_params = None - if 'expend_one_hop_request' in local_var_params: - body_params = local_var_params['expend_one_hop_request'] + if "expend_one_hop_request" in local_var_params: + body_params = local_var_params["expend_one_hop_request"] # HTTP header `Accept` - header_params['Accept'] = self.api_client.select_header_accept( - ['application/json']) # noqa: E501 + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 # HTTP header `Content-Type` - header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json']) # noqa: E501 + header_params[ + "Content-Type" + ] = self.api_client.select_header_content_type( # noqa: E501 + ["application/json"] + ) # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 return self.api_client.call_api( - '/graph/expendOneHop', 'POST', + "/graph/expendOneHop", + "POST", path_params, query_params, header_params, body=body_params, post_params=form_params, files=local_var_files, - response_type='ExpendOneHopResponse', # noqa: E501 + response_type="ExpendOneHopResponse", # noqa: E501 auth_settings=auth_settings, - async_req=local_var_params.get('async_req'), - _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 - _preload_content=local_var_params.get('_preload_content', True), - _request_timeout=local_var_params.get('_request_timeout'), - collection_formats=collection_formats) + async_req=local_var_params.get("async_req"), + _return_http_data_only=local_var_params.get( + "_return_http_data_only" + ), # noqa: E501 + _preload_content=local_var_params.get("_preload_content", True), + _request_timeout=local_var_params.get("_request_timeout"), + collection_formats=collection_formats, + ) def graph_query_vertex_post(self, **kwargs): # noqa: E501 """query_vertex # noqa: E501 @@ -887,7 +893,7 @@ def graph_query_vertex_post(self, **kwargs): # noqa: E501 If the method is called asynchronously, returns the request thread. """ - kwargs['_return_http_data_only'] = True + kwargs["_return_http_data_only"] = True return self.graph_query_vertex_post_with_http_info(**kwargs) # noqa: E501 def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 @@ -916,26 +922,24 @@ def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 local_var_params = locals() - all_params = [ - 'query_vertex_request' - ] + all_params = ["query_vertex_request"] all_params.extend( [ - 'async_req', - '_return_http_data_only', - '_preload_content', - '_request_timeout' + "async_req", + "_return_http_data_only", + "_preload_content", + "_request_timeout", ] ) - for key, val in six.iteritems(local_var_params['kwargs']): + for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method graph_query_vertex_post" % key ) local_var_params[key] = val - del local_var_params['kwargs'] + del local_var_params["kwargs"] collection_formats = {} @@ -949,31 +953,39 @@ def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 local_var_files = {} body_params = None - if 'query_vertex_request' in local_var_params: - body_params = local_var_params['query_vertex_request'] + if "query_vertex_request" in local_var_params: + body_params = local_var_params["query_vertex_request"] # HTTP header `Accept` - header_params['Accept'] = self.api_client.select_header_accept( - ['application/json']) # noqa: E501 + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 # HTTP header `Content-Type` - header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 - ['application/json']) # noqa: E501 + header_params[ + "Content-Type" + ] = self.api_client.select_header_content_type( # noqa: E501 + ["application/json"] + ) # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 return self.api_client.call_api( - '/graph/queryVertex', 'POST', + "/graph/queryVertex", + "POST", path_params, query_params, header_params, body=body_params, post_params=form_params, files=local_var_files, - response_type='VertexRecord', # noqa: E501 + response_type="VertexRecord", # noqa: E501 auth_settings=auth_settings, - async_req=local_var_params.get('async_req'), - _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 - _preload_content=local_var_params.get('_preload_content', True), - _request_timeout=local_var_params.get('_request_timeout'), - collection_formats=collection_formats) + async_req=local_var_params.get("async_req"), + _return_http_data_only=local_var_params.get( + "_return_http_data_only" + ), # noqa: E501 + _preload_content=local_var_params.get("_preload_content", True), + _request_timeout=local_var_params.get("_request_timeout"), + collection_formats=collection_formats, + ) diff --git a/python/knext/knext/graph/rest/models/__init__.py b/python/knext/knext/graph/rest/models/__init__.py index 6114b8fc9..4a7433a51 100644 --- a/python/knext/knext/graph/rest/models/__init__.py +++ b/python/knext/knext/graph/rest/models/__init__.py @@ -16,8 +16,12 @@ from __future__ import absolute_import # import models into model package -from knext.graph.rest.models.get_page_rank_scores_request import GetPageRankScoresRequest -from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import GetPageRankScoresRequestStartNodes +from knext.graph.rest.models.get_page_rank_scores_request import ( + GetPageRankScoresRequest, +) +from knext.graph.rest.models.get_page_rank_scores_request_start_nodes import ( + GetPageRankScoresRequestStartNodes, +) from knext.graph.rest.models.page_rank_score_instance import PageRankScoreInstance from knext.graph.rest.models.delete_vertex_request import DeleteVertexRequest from knext.graph.rest.models.delete_edge_request import DeleteEdgeRequest diff --git a/python/knext/knext/graph/rest/models/edge_record.py b/python/knext/knext/graph/rest/models/edge_record.py index f94f70090..20a24611d 100644 --- a/python/knext/knext/graph/rest/models/edge_record.py +++ b/python/knext/knext/graph/rest/models/edge_record.py @@ -44,22 +44,30 @@ class EdgeRecord(object): and the value is json key in definition. """ openapi_types = { - 'record_type': 'str', - 'edge_type': 'EdgeTypeName', - 'src_id': 'str', - 'dst_id': 'str', - 'properties': 'list[LpgPropertyRecord]' + "record_type": "str", + "edge_type": "EdgeTypeName", + "src_id": "str", + "dst_id": "str", + "properties": "list[LpgPropertyRecord]", } attribute_map = { - 'record_type': 'recordType', - 'edge_type': 'edgeType', - 'src_id': 'srcId', - 'dst_id': 'dstId', - 'properties': 'properties' + "record_type": "recordType", + "edge_type": "edgeType", + "src_id": "srcId", + "dst_id": "dstId", + "properties": "properties", } - def __init__(self, record_type=None, edge_type=None, src_id=None, dst_id=None, properties=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + record_type=None, + edge_type=None, + src_id=None, + dst_id=None, + properties=None, + local_vars_configuration=None, + ): # noqa: E501 """EdgeRecord - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -97,8 +105,12 @@ def record_type(self, record_type): :param record_type: The record_type of this EdgeRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and record_type is None: # noqa: E501 - raise ValueError("Invalid value for `record_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and record_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `record_type`, must not be `None`" + ) # noqa: E501 self._record_type = record_type @@ -120,8 +132,12 @@ def edge_type(self, edge_type): :param edge_type: The edge_type of this EdgeRecord. # noqa: E501 :type: EdgeTypeName """ - if self.local_vars_configuration.client_side_validation and edge_type is None: # noqa: E501 - raise ValueError("Invalid value for `edge_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and edge_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `edge_type`, must not be `None`" + ) # noqa: E501 self._edge_type = edge_type @@ -143,8 +159,12 @@ def src_id(self, src_id): :param src_id: The src_id of this EdgeRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and src_id is None: # noqa: E501 - raise ValueError("Invalid value for `src_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and src_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `src_id`, must not be `None`" + ) # noqa: E501 self._src_id = src_id @@ -166,8 +186,12 @@ def dst_id(self, dst_id): :param dst_id: The dst_id of this EdgeRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and dst_id is None: # noqa: E501 - raise ValueError("Invalid value for `dst_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and dst_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `dst_id`, must not be `None`" + ) # noqa: E501 self._dst_id = dst_id @@ -199,18 +223,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/edge_type_name.py b/python/knext/knext/graph/rest/models/edge_type_name.py index aa4161f2b..fcdeafa0c 100644 --- a/python/knext/knext/graph/rest/models/edge_type_name.py +++ b/python/knext/knext/graph/rest/models/edge_type_name.py @@ -44,18 +44,24 @@ class EdgeTypeName(object): and the value is json key in definition. """ openapi_types = { - 'start_vertex_type': 'str', - 'edge_label': 'str', - 'end_vertex_type': 'str' + "start_vertex_type": "str", + "edge_label": "str", + "end_vertex_type": "str", } attribute_map = { - 'start_vertex_type': 'startVertexType', - 'edge_label': 'edgeLabel', - 'end_vertex_type': 'endVertexType' + "start_vertex_type": "startVertexType", + "edge_label": "edgeLabel", + "end_vertex_type": "endVertexType", } - def __init__(self, start_vertex_type=None, edge_label=None, end_vertex_type=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + start_vertex_type=None, + edge_label=None, + end_vertex_type=None, + local_vars_configuration=None, + ): # noqa: E501 """EdgeTypeName - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -88,8 +94,13 @@ def start_vertex_type(self, start_vertex_type): :param start_vertex_type: The start_vertex_type of this EdgeTypeName. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and start_vertex_type is None: # noqa: E501 - raise ValueError("Invalid value for `start_vertex_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and start_vertex_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `start_vertex_type`, must not be `None`" + ) # noqa: E501 self._start_vertex_type = start_vertex_type @@ -111,8 +122,12 @@ def edge_label(self, edge_label): :param edge_label: The edge_label of this EdgeTypeName. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and edge_label is None: # noqa: E501 - raise ValueError("Invalid value for `edge_label`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and edge_label is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `edge_label`, must not be `None`" + ) # noqa: E501 self._edge_label = edge_label @@ -134,8 +149,13 @@ def end_vertex_type(self, end_vertex_type): :param end_vertex_type: The end_vertex_type of this EdgeTypeName. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and end_vertex_type is None: # noqa: E501 - raise ValueError("Invalid value for `end_vertex_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and end_vertex_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `end_vertex_type`, must not be `None`" + ) # noqa: E501 self._end_vertex_type = end_vertex_type @@ -146,18 +166,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/expend_one_hop_request.py b/python/knext/knext/graph/rest/models/expend_one_hop_request.py index 15883ee18..94c339c54 100644 --- a/python/knext/knext/graph/rest/models/expend_one_hop_request.py +++ b/python/knext/knext/graph/rest/models/expend_one_hop_request.py @@ -44,20 +44,27 @@ class ExpendOneHopRequest(object): and the value is json key in definition. """ openapi_types = { - 'project_id': 'int', - 'type_name': 'str', - 'biz_id': 'str', - 'edge_type_name_constraint': 'list[EdgeTypeName]' + "project_id": "int", + "type_name": "str", + "biz_id": "str", + "edge_type_name_constraint": "list[EdgeTypeName]", } attribute_map = { - 'project_id': 'projectId', - 'type_name': 'typeName', - 'biz_id': 'bizId', - 'edge_type_name_constraint': 'edgeTypeNameConstraint' + "project_id": "projectId", + "type_name": "typeName", + "biz_id": "bizId", + "edge_type_name_constraint": "edgeTypeNameConstraint", } - def __init__(self, project_id=None, type_name=None, biz_id=None, edge_type_name_constraint=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + project_id=None, + type_name=None, + biz_id=None, + edge_type_name_constraint=None, + local_vars_configuration=None, + ): # noqa: E501 """ExpendOneHopRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -92,8 +99,12 @@ def project_id(self, project_id): :param project_id: The project_id of this ExpendOneHopRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 - raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and project_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project_id`, must not be `None`" + ) # noqa: E501 self._project_id = project_id @@ -115,8 +126,12 @@ def type_name(self, type_name): :param type_name: The type_name of this ExpendOneHopRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and type_name is None: # noqa: E501 - raise ValueError("Invalid value for `type_name`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and type_name is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `type_name`, must not be `None`" + ) # noqa: E501 self._type_name = type_name @@ -138,8 +153,12 @@ def biz_id(self, biz_id): :param biz_id: The biz_id of this ExpendOneHopRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and biz_id is None: # noqa: E501 - raise ValueError("Invalid value for `biz_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and biz_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `biz_id`, must not be `None`" + ) # noqa: E501 self._biz_id = biz_id @@ -171,18 +190,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/expend_one_hop_response.py b/python/knext/knext/graph/rest/models/expend_one_hop_response.py index 0be7a654c..fdc036655 100644 --- a/python/knext/knext/graph/rest/models/expend_one_hop_response.py +++ b/python/knext/knext/graph/rest/models/expend_one_hop_response.py @@ -44,18 +44,24 @@ class ExpendOneHopResponse(object): and the value is json key in definition. """ openapi_types = { - 'vertex': 'VertexRecord', - 'edges': 'list[EdgeRecord]', - 'adjacent_vertices': 'list[VertexRecord]' + "vertex": "VertexRecord", + "edges": "list[EdgeRecord]", + "adjacent_vertices": "list[VertexRecord]", } attribute_map = { - 'vertex': 'vertex', - 'edges': 'edges', - 'adjacent_vertices': 'adjacentVertices' + "vertex": "vertex", + "edges": "edges", + "adjacent_vertices": "adjacentVertices", } - def __init__(self, vertex=None, edges=None, adjacent_vertices=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + vertex=None, + edges=None, + adjacent_vertices=None, + local_vars_configuration=None, + ): # noqa: E501 """ExpendOneHopResponse - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -143,18 +149,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/lpg_property_record.py b/python/knext/knext/graph/rest/models/lpg_property_record.py index 6cfb61264..33668e0a5 100644 --- a/python/knext/knext/graph/rest/models/lpg_property_record.py +++ b/python/knext/knext/graph/rest/models/lpg_property_record.py @@ -43,17 +43,13 @@ class LpgPropertyRecord(object): attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { - 'name': 'str', - 'value': 'str' - } + openapi_types = {"name": "str", "value": "str"} - attribute_map = { - 'name': 'name', - 'value': 'value' - } + attribute_map = {"name": "name", "value": "value"} - def __init__(self, name=None, value=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, name=None, value=None, local_vars_configuration=None + ): # noqa: E501 """LpgPropertyRecord - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -85,8 +81,12 @@ def name(self, name): :param name: The name of this LpgPropertyRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and name is None: # noqa: E501 - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and name is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `name`, must not be `None`" + ) # noqa: E501 self._name = name @@ -118,18 +118,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/query_vertex_request.py b/python/knext/knext/graph/rest/models/query_vertex_request.py index 050b4160e..81ea26a6f 100644 --- a/python/knext/knext/graph/rest/models/query_vertex_request.py +++ b/python/knext/knext/graph/rest/models/query_vertex_request.py @@ -43,19 +43,21 @@ class QueryVertexRequest(object): attribute_map (dict): The key is attribute name and the value is json key in definition. """ - openapi_types = { - 'project_id': 'int', - 'type_name': 'str', - 'biz_id': 'str' - } + openapi_types = {"project_id": "int", "type_name": "str", "biz_id": "str"} attribute_map = { - 'project_id': 'projectId', - 'type_name': 'typeName', - 'biz_id': 'bizId' + "project_id": "projectId", + "type_name": "typeName", + "biz_id": "bizId", } - def __init__(self, project_id=None, type_name=None, biz_id=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + project_id=None, + type_name=None, + biz_id=None, + local_vars_configuration=None, + ): # noqa: E501 """QueryVertexRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -88,8 +90,12 @@ def project_id(self, project_id): :param project_id: The project_id of this QueryVertexRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 - raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and project_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project_id`, must not be `None`" + ) # noqa: E501 self._project_id = project_id @@ -111,8 +117,12 @@ def type_name(self, type_name): :param type_name: The type_name of this QueryVertexRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and type_name is None: # noqa: E501 - raise ValueError("Invalid value for `type_name`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and type_name is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `type_name`, must not be `None`" + ) # noqa: E501 self._type_name = type_name @@ -134,8 +144,12 @@ def biz_id(self, biz_id): :param biz_id: The biz_id of this QueryVertexRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and biz_id is None: # noqa: E501 - raise ValueError("Invalid value for `biz_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and biz_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `biz_id`, must not be `None`" + ) # noqa: E501 self._biz_id = biz_id @@ -146,18 +160,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/graph/rest/models/vertex_record.py b/python/knext/knext/graph/rest/models/vertex_record.py index 7da594cda..3a6f28bfc 100644 --- a/python/knext/knext/graph/rest/models/vertex_record.py +++ b/python/knext/knext/graph/rest/models/vertex_record.py @@ -44,20 +44,27 @@ class VertexRecord(object): and the value is json key in definition. """ openapi_types = { - 'record_type': 'str', - 'vertex_type': 'str', - 'id': 'str', - 'properties': 'list[LpgPropertyRecord]' + "record_type": "str", + "vertex_type": "str", + "id": "str", + "properties": "list[LpgPropertyRecord]", } attribute_map = { - 'record_type': 'recordType', - 'vertex_type': 'vertexType', - 'id': 'id', - 'properties': 'properties' + "record_type": "recordType", + "vertex_type": "vertexType", + "id": "id", + "properties": "properties", } - def __init__(self, record_type=None, vertex_type=None, id=None, properties=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + record_type=None, + vertex_type=None, + id=None, + properties=None, + local_vars_configuration=None, + ): # noqa: E501 """VertexRecord - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -92,8 +99,12 @@ def record_type(self, record_type): :param record_type: The record_type of this VertexRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and record_type is None: # noqa: E501 - raise ValueError("Invalid value for `record_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and record_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `record_type`, must not be `None`" + ) # noqa: E501 self._record_type = record_type @@ -115,8 +126,12 @@ def vertex_type(self, vertex_type): :param vertex_type: The vertex_type of this VertexRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and vertex_type is None: # noqa: E501 - raise ValueError("Invalid value for `vertex_type`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and vertex_type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `vertex_type`, must not be `None`" + ) # noqa: E501 self._vertex_type = vertex_type @@ -138,7 +153,9 @@ def id(self, id): :param id: The id of this VertexRecord. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and id is None: # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 self._id = id @@ -161,8 +178,12 @@ def properties(self, properties): :param properties: The properties of this VertexRecord. # noqa: E501 :type: list[LpgPropertyRecord] """ - if self.local_vars_configuration.client_side_validation and properties is None: # noqa: E501 - raise ValueError("Invalid value for `properties`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and properties is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `properties`, must not be `None`" + ) # noqa: E501 self._properties = properties @@ -173,18 +194,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/search/client.py b/python/knext/knext/search/client.py index 0a70e7f03..4b28fe134 100644 --- a/python/knext/knext/search/client.py +++ b/python/knext/knext/search/client.py @@ -29,11 +29,15 @@ def __init__(self, host_addr: str = None, project_id: int = None): ) def search_text(self, query_string, label_constraints=None, topk=10, params=None): - req = TextSearchRequest(self._project_id, query_string, label_constraints, topk, params) + req = TextSearchRequest( + self._project_id, query_string, label_constraints, topk, params + ) records = self._rest_client.search_text_post(text_search_request=req) return [idx_record_to_dict(record) for record in records] - def search_vector(self, label, property_key, query_vector, topk=10, ef_search=None, params=None): + def search_vector( + self, label, property_key, query_vector, topk=10, ef_search=None, params=None + ): req = VectorSearchRequest( self._project_id, label, property_key, query_vector, ef_search, topk, params ) diff --git a/python/knext/knext/search/rest/models/text_search_request.py b/python/knext/knext/search/rest/models/text_search_request.py index e578599e6..deb0ac00e 100644 --- a/python/knext/knext/search/rest/models/text_search_request.py +++ b/python/knext/knext/search/rest/models/text_search_request.py @@ -43,22 +43,30 @@ class TextSearchRequest(object): and the value is json key in definition. """ openapi_types = { - 'project_id': 'int', - 'query_string': 'str', - 'label_constraints': 'list[str]', - 'topk': 'int', - 'params': 'object' + "project_id": "int", + "query_string": "str", + "label_constraints": "list[str]", + "topk": "int", + "params": "object", } attribute_map = { - 'project_id': 'projectId', - 'query_string': 'queryString', - 'label_constraints': 'labelConstraints', - 'topk': 'topk', - 'params': 'params' + "project_id": "projectId", + "query_string": "queryString", + "label_constraints": "labelConstraints", + "topk": "topk", + "params": "params", } - def __init__(self, project_id=None, query_string=None, label_constraints=None, topk=None, params=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + project_id=None, + query_string=None, + label_constraints=None, + topk=None, + params=None, + local_vars_configuration=None, + ): # noqa: E501 """TextSearchRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -95,8 +103,12 @@ def project_id(self, project_id): :param project_id: The project_id of this TextSearchRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 - raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and project_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project_id`, must not be `None`" + ) # noqa: E501 self._project_id = project_id @@ -118,8 +130,13 @@ def query_string(self, query_string): :param query_string: The query_string of this TextSearchRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and query_string is None: # noqa: E501 - raise ValueError("Invalid value for `query_string`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and query_string is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `query_string`, must not be `None`" + ) # noqa: E501 self._query_string = query_string @@ -141,8 +158,13 @@ def label_constraints(self, label_constraints): :param label_constraints: The label_constraints of this TextSearchRequest. # noqa: E501 :type: list[str] """ - if self.local_vars_configuration.client_side_validation and label_constraints is None: # noqa: E501 - raise ValueError("Invalid value for `label_constraints`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and label_constraints is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `label_constraints`, must not be `None`" + ) # noqa: E501 self._label_constraints = label_constraints @@ -164,8 +186,12 @@ def topk(self, topk): :param topk: The topk of this TextSearchRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and topk is None: # noqa: E501 - raise ValueError("Invalid value for `topk`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and topk is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `topk`, must not be `None`" + ) # noqa: E501 self._topk = topk @@ -187,8 +213,12 @@ def params(self, params): :param params: The params of this TextSearchRequest. # noqa: E501 :type: object """ - if self.local_vars_configuration.client_side_validation and params is None: # noqa: E501 - raise ValueError("Invalid value for `params`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and params is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `params`, must not be `None`" + ) # noqa: E501 self._params = params @@ -199,18 +229,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/python/knext/knext/search/rest/models/vector_search_request.py b/python/knext/knext/search/rest/models/vector_search_request.py index b6d12a851..6e67e0459 100644 --- a/python/knext/knext/search/rest/models/vector_search_request.py +++ b/python/knext/knext/search/rest/models/vector_search_request.py @@ -43,26 +43,36 @@ class VectorSearchRequest(object): and the value is json key in definition. """ openapi_types = { - 'project_id': 'int', - 'label': 'str', - 'property_key': 'str', - 'query_vector': 'list[float]', - 'ef_search': 'int', - 'topk': 'int', - 'params': 'object' + "project_id": "int", + "label": "str", + "property_key": "str", + "query_vector": "list[float]", + "ef_search": "int", + "topk": "int", + "params": "object", } attribute_map = { - 'project_id': 'projectId', - 'label': 'label', - 'property_key': 'propertyKey', - 'query_vector': 'queryVector', - 'ef_search': 'efSearch', - 'topk': 'topk', - 'params': 'params' + "project_id": "projectId", + "label": "label", + "property_key": "propertyKey", + "query_vector": "queryVector", + "ef_search": "efSearch", + "topk": "topk", + "params": "params", } - def __init__(self, project_id=None, label=None, property_key=None, query_vector=None, ef_search=None, topk=None, params=None, local_vars_configuration=None): # noqa: E501 + def __init__( + self, + project_id=None, + label=None, + property_key=None, + query_vector=None, + ef_search=None, + topk=None, + params=None, + local_vars_configuration=None, + ): # noqa: E501 """VectorSearchRequest - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() @@ -104,8 +114,12 @@ def project_id(self, project_id): :param project_id: The project_id of this VectorSearchRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and project_id is None: # noqa: E501 - raise ValueError("Invalid value for `project_id`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and project_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project_id`, must not be `None`" + ) # noqa: E501 self._project_id = project_id @@ -127,8 +141,12 @@ def label(self, label): :param label: The label of this VectorSearchRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and label is None: # noqa: E501 - raise ValueError("Invalid value for `label`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and label is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `label`, must not be `None`" + ) # noqa: E501 self._label = label @@ -150,8 +168,13 @@ def property_key(self, property_key): :param property_key: The property_key of this VectorSearchRequest. # noqa: E501 :type: str """ - if self.local_vars_configuration.client_side_validation and property_key is None: # noqa: E501 - raise ValueError("Invalid value for `property_key`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and property_key is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `property_key`, must not be `None`" + ) # noqa: E501 self._property_key = property_key @@ -173,8 +196,13 @@ def query_vector(self, query_vector): :param query_vector: The query_vector of this VectorSearchRequest. # noqa: E501 :type: list[float] """ - if self.local_vars_configuration.client_side_validation and query_vector is None: # noqa: E501 - raise ValueError("Invalid value for `query_vector`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and query_vector is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `query_vector`, must not be `None`" + ) # noqa: E501 self._query_vector = query_vector @@ -217,8 +245,12 @@ def topk(self, topk): :param topk: The topk of this VectorSearchRequest. # noqa: E501 :type: int """ - if self.local_vars_configuration.client_side_validation and topk is None: # noqa: E501 - raise ValueError("Invalid value for `topk`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and topk is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `topk`, must not be `None`" + ) # noqa: E501 self._topk = topk @@ -240,8 +272,12 @@ def params(self, params): :param params: The params of this VectorSearchRequest. # noqa: E501 :type: object """ - if self.local_vars_configuration.client_side_validation and params is None: # noqa: E501 - raise ValueError("Invalid value for `params`, must not be `None`") # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation and params is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `params`, must not be `None`" + ) # noqa: E501 self._params = params @@ -252,18 +288,20 @@ def to_dict(self): for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) else: result[attr] = value diff --git a/server/api/facade/pom.xml b/server/api/facade/pom.xml index 633d159dd..3b884f5bb 100644 --- a/server/api/facade/pom.xml +++ b/server/api/facade/pom.xml @@ -29,12 +29,8 @@ core-schema-model - com.google.code.gson - gson - - - org.danilopianini - gson-extras + com.antgroup.openspg.cloudext + cloudext-interface-graph-store diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java index 42db1bd76..2b0e5ab65 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java @@ -21,12 +21,7 @@ public class ApiConstants { public static final String TOKEN = "token"; public static final String ENV = "env"; - public static final String ACCESS_ID = "accessId"; - public static final String ACCESS_KEY = "accessKey"; public static final String HOST = "host"; - public static final String TIMEOUT = "timeout"; public static final String PORT = "port"; public static final String SCHEME = "scheme"; - - public static final Long DEFAULT_VERSION = 0L; } diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java new file mode 100644 index 000000000..aa2a5420c --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java @@ -0,0 +1,22 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.request; + +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.EdgeTypeName; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ExpendOneHopRequest { + + private Long projectId; + private String typeName; + private String bizId; + private List edgeTypeNameConstraint; +} diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java new file mode 100644 index 000000000..bc15551db --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java @@ -0,0 +1,19 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.request; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QueryVertexRequest { + + private Long projectId; + private String typeName; + private String bizId; +} diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java index 388524fc3..2686e1e37 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/TextSearchRequest.java @@ -15,7 +15,6 @@ import java.util.Map; import java.util.Set; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java index 58d2065c8..b3e22802e 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/VectorSearchRequest.java @@ -13,12 +13,11 @@ package com.antgroup.openspg.server.api.facade.dto.service.request; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Map; - @Data @NoArgsConstructor @AllArgsConstructor diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java new file mode 100644 index 000000000..3701128f7 --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java @@ -0,0 +1,22 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.response; + +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.EdgeRecord; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ExpendOneHopResponse { + + private VertexRecord vertex; + private List edges; + private List adjacentVertices; +} diff --git a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/WebMvcConfig.java b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/WebMvcConfig.java index 8c4eb11b2..e8584840b 100644 --- a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/WebMvcConfig.java +++ b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/WebMvcConfig.java @@ -13,7 +13,7 @@ package com.antgroup.openspg.server.api.http.server; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import java.util.Collections; import java.util.List; import org.springframework.context.annotation.Configuration; diff --git a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java index ffe5681dc..a2cf367d8 100644 --- a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java +++ b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java @@ -24,11 +24,13 @@ import com.antgroup.openspg.builder.model.record.SubGraphRecord; import com.antgroup.openspg.builder.runner.local.physical.sink.impl.GraphStoreSinkWriter; import com.antgroup.openspg.builder.runner.local.physical.sink.impl.Neo4jSinkWriter; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; import com.antgroup.openspg.core.schema.model.identifier.SPGTypeIdentifier; import com.antgroup.openspg.core.schema.model.type.BaseSPGType; import com.antgroup.openspg.core.schema.model.type.ConceptList; import com.antgroup.openspg.core.schema.model.type.ProjectSchema; import com.antgroup.openspg.server.api.facade.dto.service.request.*; +import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; import com.antgroup.openspg.server.api.http.server.HttpBizCallback; @@ -234,4 +236,44 @@ private Map getConceptLists( } return results; } + + @RequestMapping(value = "/expendOneHop", method = RequestMethod.POST) + @ResponseBody + public HttpResult expendOneHop(@RequestBody ExpendOneHopRequest request) { + return HttpBizTemplate.execute2( + new HttpBizCallback() { + @Override + public void check() { + AssertUtils.assertParamObjectIsNotNull("request", request); + AssertUtils.assertParamObjectIsNotNull("projectId", request.getProjectId()); + AssertUtils.assertParamObjectIsNotNull("typeName", request.getTypeName()); + AssertUtils.assertParamObjectIsNotNull("bizId", request.getBizId()); + } + + @Override + public ExpendOneHopResponse action() { + return graphManager.expendOneHop(request); + } + }); + } + + @RequestMapping(value = "/queryVertex", method = RequestMethod.POST) + @ResponseBody + public HttpResult queryVertex(@RequestBody QueryVertexRequest request) { + return HttpBizTemplate.execute2( + new HttpBizCallback() { + @Override + public void check() { + AssertUtils.assertParamObjectIsNotNull("request", request); + AssertUtils.assertParamObjectIsNotNull("projectId", request.getProjectId()); + AssertUtils.assertParamObjectIsNotNull("typeName", request.getTypeName()); + AssertUtils.assertParamObjectIsNotNull("bizId", request.getBizId()); + } + + @Override + public VertexRecord action() { + return graphManager.queryVertex(request); + } + }); + } } diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java index 3d32b24b2..e7c86088c 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java @@ -13,7 +13,9 @@ package com.antgroup.openspg.server.biz.service; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; import com.antgroup.openspg.server.api.facade.dto.service.request.*; +import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; import java.util.List; @@ -31,4 +33,8 @@ public interface GraphManager { ManipulateDataResponse deleteEdgeRequest(DeleteEdgeRequest request); List getPageRankScores(GetPageRankScoresRequest request); + + VertexRecord queryVertex(QueryVertexRequest request); + + ExpendOneHopResponse expendOneHop(ExpendOneHopRequest request); } diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java index 2777d2476..4fa03c5c0 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java @@ -15,17 +15,24 @@ import com.antgroup.openspg.cloudext.interfaces.graphstore.BaseLPGGraphStoreClient; import com.antgroup.openspg.cloudext.interfaces.graphstore.GraphStoreClientDriverManager; +import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.OneHopLPGRecordQuery; import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.PageRankCompete; +import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.VertexLPGRecordQuery; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.ComputeResultRow; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.Direction; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.EdgeRecord; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.struct.GraphLPGRecordStruct; +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.EdgeTypeName; import com.antgroup.openspg.server.api.facade.dto.service.request.*; +import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; import com.antgroup.openspg.server.biz.common.ProjectManager; import com.antgroup.openspg.server.biz.service.GraphManager; import com.antgroup.openspg.server.biz.service.convertor.InstanceConvertor; -import java.util.List; +import com.google.common.collect.Lists; +import java.util.*; import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -164,4 +171,76 @@ public List getPageRankScores(GetPageRankScoresRequest re row.getNode().getVertexType(), row.getNode().getId(), row.getScore())) .collect(Collectors.toList()); } + + @Override + public ExpendOneHopResponse expendOneHop(ExpendOneHopRequest request) { + String graphStoreUrl = projectManager.getGraphStoreUrl(request.getProjectId()); + BaseLPGGraphStoreClient lpgGraphStoreClient = + (BaseLPGGraphStoreClient) GraphStoreClientDriverManager.getClient(graphStoreUrl); + + Set edgeTypeNameSet = + request.getEdgeTypeNameConstraint() == null + ? null + : new HashSet<>(request.getEdgeTypeNameConstraint()); + OneHopLPGRecordQuery query = + new OneHopLPGRecordQuery( + request.getBizId(), request.getTypeName(), edgeTypeNameSet, Direction.BOTH); + GraphLPGRecordStruct struct = (GraphLPGRecordStruct) lpgGraphStoreClient.queryRecord(query); + return convert2ExpendOneHopResponse(request.getTypeName(), request.getBizId(), struct); + } + + private ExpendOneHopResponse convert2ExpendOneHopResponse( + String type, String id, GraphLPGRecordStruct graphLPGRecordStruct) { + if (graphLPGRecordStruct == null) { + return null; + } + ExpendOneHopResponse response = new ExpendOneHopResponse(); + if (CollectionUtils.isEmpty(graphLPGRecordStruct.getVertices()) + && CollectionUtils.isEmpty(graphLPGRecordStruct.getEdges())) { + return response; + } + + Map vertexRecordMap = new HashMap<>(); + for (VertexRecord vertexRecord : graphLPGRecordStruct.getVertices()) { + vertexRecordMap.put(vertexRecord.generateUniqueString(), vertexRecord); + } + + String sourceVertexUniqueString = new VertexRecord(id, type, null).generateUniqueString(); + response.setVertex(vertexRecordMap.get(sourceVertexUniqueString)); + + response.setEdges(graphLPGRecordStruct.getEdges()); + + List adjacentVertices = Lists.newArrayList(); + for (EdgeRecord edgeRecord : graphLPGRecordStruct.getEdges()) { + String startVertexUniqueString = + new VertexRecord(edgeRecord.getSrcId(), edgeRecord.getEdgeType().getStartVertexType()) + .generateUniqueString(); + if (sourceVertexUniqueString.equals(startVertexUniqueString)) { + String endVertexUniqueString = + new VertexRecord(edgeRecord.getDstId(), edgeRecord.getEdgeType().getEndVertexType()) + .generateUniqueString(); + adjacentVertices.add(vertexRecordMap.get(endVertexUniqueString)); + } else { + adjacentVertices.add(vertexRecordMap.get(startVertexUniqueString)); + } + } + response.setAdjacentVertices(adjacentVertices); + + return response; + } + + @Override + public VertexRecord queryVertex(QueryVertexRequest request) { + String graphStoreUrl = projectManager.getGraphStoreUrl(request.getProjectId()); + BaseLPGGraphStoreClient lpgGraphStoreClient = + (BaseLPGGraphStoreClient) GraphStoreClientDriverManager.getClient(graphStoreUrl); + + VertexLPGRecordQuery query = + new VertexLPGRecordQuery(request.getBizId(), request.getTypeName()); + GraphLPGRecordStruct struct = (GraphLPGRecordStruct) lpgGraphStoreClient.queryRecord(query); + if (struct == null || struct.getVertices().isEmpty()) { + return null; + } + return struct.getVertices().get(0); + } } diff --git a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/ExtConfigConvertor.java b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/ExtConfigConvertor.java index d4a5c0c89..901dfb56f 100644 --- a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/ExtConfigConvertor.java +++ b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/ExtConfigConvertor.java @@ -13,9 +13,9 @@ package com.antgroup.openspg.server.infra.dao.repository.schema.convertor; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.antgroup.openspg.core.schema.model.SchemaConstants; import com.antgroup.openspg.core.schema.model.SchemaExtInfo; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import com.antgroup.openspg.server.core.schema.service.predicate.model.SimpleProperty; import com.antgroup.openspg.server.core.schema.service.type.model.SimpleSPGType; import java.util.stream.Collectors; diff --git a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/OntologyConvertor.java b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/OntologyConvertor.java index ba99eb185..7b7dfefa9 100644 --- a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/OntologyConvertor.java +++ b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/OntologyConvertor.java @@ -13,6 +13,7 @@ package com.antgroup.openspg.server.infra.dao.repository.schema.convertor; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.antgroup.openspg.common.util.StringUtils; import com.antgroup.openspg.core.schema.model.BasicInfo; import com.antgroup.openspg.core.schema.model.OntologyId; @@ -27,7 +28,6 @@ import com.antgroup.openspg.core.schema.model.type.ParentTypeInfo; import com.antgroup.openspg.core.schema.model.type.SPGTypeEnum; import com.antgroup.openspg.core.schema.model.type.VisibleScopeEnum; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import com.antgroup.openspg.server.core.schema.service.type.model.OperatorConfig; import com.antgroup.openspg.server.core.schema.service.type.model.ProjectOntologyRel; import com.antgroup.openspg.server.core.schema.service.type.model.SimpleSPGType; diff --git a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimplePropertyConvertor.java b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimplePropertyConvertor.java index 3f23b282f..4dca4e807 100644 --- a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimplePropertyConvertor.java +++ b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimplePropertyConvertor.java @@ -13,6 +13,7 @@ package com.antgroup.openspg.server.infra.dao.repository.schema.convertor; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.antgroup.openspg.common.util.StringUtils; import com.antgroup.openspg.core.schema.model.BasicInfo; import com.antgroup.openspg.core.schema.model.OntologyId; @@ -28,7 +29,6 @@ import com.antgroup.openspg.core.schema.model.semantic.SPGOntologyEnum; import com.antgroup.openspg.core.schema.model.type.MultiVersionConfig; import com.antgroup.openspg.core.schema.model.type.SPGTypeEnum; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import com.antgroup.openspg.server.core.schema.service.predicate.model.SimpleProperty; import com.antgroup.openspg.server.infra.dao.dataobject.OntologyPropertyDO; import com.antgroup.openspg.server.infra.dao.repository.schema.enums.MapTypeEnum; diff --git a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimpleSubPropertyConvertor.java b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimpleSubPropertyConvertor.java index 3335ee745..9f514978a 100644 --- a/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimpleSubPropertyConvertor.java +++ b/server/infra/dao/src/main/java/com/antgroup/openspg/server/infra/dao/repository/schema/convertor/SimpleSubPropertyConvertor.java @@ -14,6 +14,7 @@ package com.antgroup.openspg.server.infra.dao.repository.schema.convertor; import com.alibaba.fastjson.JSON; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.antgroup.openspg.common.util.StringUtils; import com.antgroup.openspg.core.schema.model.BasicInfo; import com.antgroup.openspg.core.schema.model.OntologyId; @@ -23,7 +24,6 @@ import com.antgroup.openspg.core.schema.model.identifier.PredicateIdentifier; import com.antgroup.openspg.core.schema.model.predicate.EncryptTypeEnum; import com.antgroup.openspg.core.schema.model.type.MultiVersionConfig; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; import com.antgroup.openspg.server.core.schema.service.predicate.model.SimpleSubProperty; import com.antgroup.openspg.server.infra.dao.dataobject.OntologyPropertyDO; import com.antgroup.openspg.server.infra.dao.repository.schema.enums.MapTypeEnum; From 958f72a947859ee983efc530614a8becabe33b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Tue, 26 Nov 2024 14:08:58 +0800 Subject: [PATCH 05/12] roll back upload_dev.sh --- python/knext/upload_dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/knext/upload_dev.sh b/python/knext/upload_dev.sh index d1278ea94..57b43dbb7 100644 --- a/python/knext/upload_dev.sh +++ b/python/knext/upload_dev.sh @@ -13,6 +13,6 @@ rm -rf build rm -rf dist -python3 setup.py sdist bdist_wheel +python setup.py sdist bdist_wheel twine upload dist/* \ No newline at end of file From d72e0afe3ae8068156cc616618dfb1192735ead4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Tue, 26 Nov 2024 14:24:29 +0800 Subject: [PATCH 06/12] buf fix --- .../openspg/server/api/http/client/forest/GsonConvertor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/api/http-client/src/main/java/com/antgroup/openspg/server/api/http/client/forest/GsonConvertor.java b/server/api/http-client/src/main/java/com/antgroup/openspg/server/api/http/client/forest/GsonConvertor.java index f6d3ceb7f..aa0d57096 100644 --- a/server/api/http-client/src/main/java/com/antgroup/openspg/server/api/http/client/forest/GsonConvertor.java +++ b/server/api/http-client/src/main/java/com/antgroup/openspg/server/api/http/client/forest/GsonConvertor.java @@ -13,7 +13,7 @@ package com.antgroup.openspg.server.api.http.client.forest; -import com.antgroup.openspg.server.api.facade.SchemaJsonUtils; +import com.antgroup.openspg.common.util.SchemaJsonUtils; import com.dtflys.forest.converter.ConvertOptions; import com.dtflys.forest.converter.json.ForestJsonConverter; import com.dtflys.forest.http.ForestRequest; From 193ecf8ac8a74ee566a0315e2c018cb41f8a3b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Tue, 26 Nov 2024 15:27:43 +0800 Subject: [PATCH 07/12] roll back ApiConstants --- .../com/antgroup/openspg/server/api/facade/ApiConstants.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java index 2b0e5ab65..7ebcc73e1 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/ApiConstants.java @@ -24,4 +24,6 @@ public class ApiConstants { public static final String HOST = "host"; public static final String PORT = "port"; public static final String SCHEME = "scheme"; + + public static final Long DEFAULT_VERSION = 0L; } From f0673fa5bdebda7ec4b0a518f56b078159e32ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Wed, 27 Nov 2024 18:10:48 +0800 Subject: [PATCH 08/12] fix(knext&server)query vertex if return null --- python/knext/KNEXT_VERSION | 2 +- python/knext/knext/__init__.py | 2 +- python/knext/knext/graph/__init__.py | 1 + python/knext/knext/graph/client.py | 8 +- python/knext/knext/graph/rest/__init__.py | 1 + python/knext/knext/graph/rest/graph_api.py | 6 +- .../knext/knext/graph/rest/models/__init__.py | 1 + .../knext/graph/rest/models/edge_record.py | 36 ++--- .../rest/models/query_vertex_response.py | 129 ++++++++++++++++++ .../knext/graph/rest/models/vertex_record.py | 34 ++--- .../service/response/QueryVertexResponse.java | 18 +++ .../http/server/openapi/GraphController.java | 8 +- .../server/biz/service/GraphManager.java | 4 +- .../biz/service/impl/GraphManagerImpl.java | 10 +- 14 files changed, 188 insertions(+), 72 deletions(-) create mode 100644 python/knext/knext/graph/rest/models/query_vertex_response.py create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java diff --git a/python/knext/KNEXT_VERSION b/python/knext/KNEXT_VERSION index 461d83ed9..d1363a983 100644 --- a/python/knext/KNEXT_VERSION +++ b/python/knext/KNEXT_VERSION @@ -1 +1 @@ -0.6.0.20241125.1 +0.6.0.20241127.1 diff --git a/python/knext/knext/__init__.py b/python/knext/knext/__init__.py index ee80cff59..74976673b 100644 --- a/python/knext/knext/__init__.py +++ b/python/knext/knext/__init__.py @@ -11,7 +11,7 @@ __package_name__ = "openspg-knext" -__version__ = "0.6.0.20241125.1" +__version__ = "0.6.0.20241127.1" from knext.common.env import init_env diff --git a/python/knext/knext/graph/__init__.py b/python/knext/knext/graph/__init__.py index 143f4a25d..ab4806941 100644 --- a/python/knext/knext/graph/__init__.py +++ b/python/knext/knext/graph/__init__.py @@ -51,5 +51,6 @@ from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.query_vertex_response import QueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index 687b8bf8d..0f0ebf58f 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -106,7 +106,7 @@ def expend_one_hop( # test ant main-site client = GraphClient("https://spgservice-standard-pre.alipay.com", 644000146) v = client.query_vertex("Antwork.EntityName", "千三") - # print(v) + print(v) edge_name = EdgeTypeName( start_vertex_type="BCTEST.DeleteDataEntity3", @@ -115,9 +115,9 @@ def expend_one_hop( ) client2 = GraphClient("https://spgservice-standard-pre.alipay.com", 363000133) edge_type_name_constraint = [] - edge_type_name_constraint.append(edge_name) + # edge_type_name_constraint.append(edge_name) g1 = client2.expend_one_hop( - "BCTEST.DeleteDataEntity3", "秉初测试", edge_type_name_constraint + "BCTEST.DeleteDataEntity3", "秉初测试321", edge_type_name_constraint ) # g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name]) - print(g1) + # print(g1) diff --git a/python/knext/knext/graph/rest/__init__.py b/python/knext/knext/graph/rest/__init__.py index 143f4a25d..ab4806941 100644 --- a/python/knext/knext/graph/rest/__init__.py +++ b/python/knext/knext/graph/rest/__init__.py @@ -51,5 +51,6 @@ from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.query_vertex_response import QueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/rest/graph_api.py b/python/knext/knext/graph/rest/graph_api.py index 788310519..4e7f0c221 100644 --- a/python/knext/knext/graph/rest/graph_api.py +++ b/python/knext/knext/graph/rest/graph_api.py @@ -889,7 +889,7 @@ def graph_query_vertex_post(self, **kwargs): # noqa: E501 number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. - :return: VertexRecord + :return: QueryVertexResponse If the method is called asynchronously, returns the request thread. """ @@ -915,7 +915,7 @@ def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. - :return: tuple(VertexRecord, status_code(int), headers(HTTPHeaderDict)) + :return: tuple(QueryVertexResponse, status_code(int), headers(HTTPHeaderDict)) If the method is called asynchronously, returns the request thread. """ @@ -979,7 +979,7 @@ def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type="VertexRecord", # noqa: E501 + response_type="QueryVertexResponse", # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get("async_req"), _return_http_data_only=local_var_params.get( diff --git a/python/knext/knext/graph/rest/models/__init__.py b/python/knext/knext/graph/rest/models/__init__.py index 4a7433a51..6bfdb6617 100644 --- a/python/knext/knext/graph/rest/models/__init__.py +++ b/python/knext/knext/graph/rest/models/__init__.py @@ -35,5 +35,6 @@ from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest +from knext.graph.rest.models.query_vertex_response import QueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/rest/models/edge_record.py b/python/knext/knext/graph/rest/models/edge_record.py index 20a24611d..12414040f 100644 --- a/python/knext/knext/graph/rest/models/edge_record.py +++ b/python/knext/knext/graph/rest/models/edge_record.py @@ -80,10 +80,14 @@ def __init__( self._properties = None self.discriminator = None - self.record_type = record_type - self.edge_type = edge_type - self.src_id = src_id - self.dst_id = dst_id + if record_type is not None: + self.record_type = record_type + if edge_type is not None: + self.edge_type = edge_type + if src_id is not None: + self.src_id = src_id + if dst_id is not None: + self.dst_id = dst_id if properties is not None: self.properties = properties @@ -105,12 +109,6 @@ def record_type(self, record_type): :param record_type: The record_type of this EdgeRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and record_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `record_type`, must not be `None`" - ) # noqa: E501 self._record_type = record_type @@ -132,12 +130,6 @@ def edge_type(self, edge_type): :param edge_type: The edge_type of this EdgeRecord. # noqa: E501 :type: EdgeTypeName """ - if ( - self.local_vars_configuration.client_side_validation and edge_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `edge_type`, must not be `None`" - ) # noqa: E501 self._edge_type = edge_type @@ -159,12 +151,6 @@ def src_id(self, src_id): :param src_id: The src_id of this EdgeRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and src_id is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `src_id`, must not be `None`" - ) # noqa: E501 self._src_id = src_id @@ -186,12 +172,6 @@ def dst_id(self, dst_id): :param dst_id: The dst_id of this EdgeRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and dst_id is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `dst_id`, must not be `None`" - ) # noqa: E501 self._dst_id = dst_id diff --git a/python/knext/knext/graph/rest/models/query_vertex_response.py b/python/knext/knext/graph/rest/models/query_vertex_response.py new file mode 100644 index 000000000..eb48a99d6 --- /dev/null +++ b/python/knext/knext/graph/rest/models/query_vertex_response.py @@ -0,0 +1,129 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class QueryVertexResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"vertex": "VertexRecord"} + + attribute_map = {"vertex": "vertex"} + + def __init__(self, vertex=None, local_vars_configuration=None): # noqa: E501 + """QueryVertexResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._vertex = None + self.discriminator = None + + if vertex is not None: + self.vertex = vertex + + @property + def vertex(self): + """Gets the vertex of this QueryVertexResponse. # noqa: E501 + + + :return: The vertex of this QueryVertexResponse. # noqa: E501 + :rtype: VertexRecord + """ + return self._vertex + + @vertex.setter + def vertex(self, vertex): + """Sets the vertex of this QueryVertexResponse. + + + :param vertex: The vertex of this QueryVertexResponse. # noqa: E501 + :type: VertexRecord + """ + + self._vertex = vertex + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, QueryVertexResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, QueryVertexResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/vertex_record.py b/python/knext/knext/graph/rest/models/vertex_record.py index 3a6f28bfc..9ed57e280 100644 --- a/python/knext/knext/graph/rest/models/vertex_record.py +++ b/python/knext/knext/graph/rest/models/vertex_record.py @@ -76,10 +76,14 @@ def __init__( self._properties = None self.discriminator = None - self.record_type = record_type - self.vertex_type = vertex_type - self.id = id - self.properties = properties + if record_type is not None: + self.record_type = record_type + if vertex_type is not None: + self.vertex_type = vertex_type + if id is not None: + self.id = id + if properties is not None: + self.properties = properties @property def record_type(self): @@ -99,12 +103,6 @@ def record_type(self, record_type): :param record_type: The record_type of this VertexRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and record_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `record_type`, must not be `None`" - ) # noqa: E501 self._record_type = record_type @@ -126,12 +124,6 @@ def vertex_type(self, vertex_type): :param vertex_type: The vertex_type of this VertexRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and vertex_type is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `vertex_type`, must not be `None`" - ) # noqa: E501 self._vertex_type = vertex_type @@ -153,10 +145,6 @@ def id(self, id): :param id: The id of this VertexRecord. # noqa: E501 :type: str """ - if ( - self.local_vars_configuration.client_side_validation and id is None - ): # noqa: E501 - raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 self._id = id @@ -178,12 +166,6 @@ def properties(self, properties): :param properties: The properties of this VertexRecord. # noqa: E501 :type: list[LpgPropertyRecord] """ - if ( - self.local_vars_configuration.client_side_validation and properties is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `properties`, must not be `None`" - ) # noqa: E501 self._properties = properties diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java new file mode 100644 index 000000000..d38daea4c --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java @@ -0,0 +1,18 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.response; + +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QueryVertexResponse { + + private VertexRecord vertex; +} diff --git a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java index a2cf367d8..a4a6ae630 100644 --- a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java +++ b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java @@ -24,7 +24,6 @@ import com.antgroup.openspg.builder.model.record.SubGraphRecord; import com.antgroup.openspg.builder.runner.local.physical.sink.impl.GraphStoreSinkWriter; import com.antgroup.openspg.builder.runner.local.physical.sink.impl.Neo4jSinkWriter; -import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; import com.antgroup.openspg.core.schema.model.identifier.SPGTypeIdentifier; import com.antgroup.openspg.core.schema.model.type.BaseSPGType; import com.antgroup.openspg.core.schema.model.type.ConceptList; @@ -33,6 +32,7 @@ import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; +import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; import com.antgroup.openspg.server.api.http.server.HttpBizCallback; import com.antgroup.openspg.server.api.http.server.HttpBizTemplate; import com.antgroup.openspg.server.api.http.server.HttpResult; @@ -259,9 +259,9 @@ public ExpendOneHopResponse action() { @RequestMapping(value = "/queryVertex", method = RequestMethod.POST) @ResponseBody - public HttpResult queryVertex(@RequestBody QueryVertexRequest request) { + public HttpResult queryVertex(@RequestBody QueryVertexRequest request) { return HttpBizTemplate.execute2( - new HttpBizCallback() { + new HttpBizCallback() { @Override public void check() { AssertUtils.assertParamObjectIsNotNull("request", request); @@ -271,7 +271,7 @@ public void check() { } @Override - public VertexRecord action() { + public QueryVertexResponse action() { return graphManager.queryVertex(request); } }); diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java index e7c86088c..b90ac10c8 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java @@ -13,11 +13,11 @@ package com.antgroup.openspg.server.biz.service; -import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; import com.antgroup.openspg.server.api.facade.dto.service.request.*; import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; +import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; import java.util.List; public interface GraphManager { @@ -34,7 +34,7 @@ public interface GraphManager { List getPageRankScores(GetPageRankScoresRequest request); - VertexRecord queryVertex(QueryVertexRequest request); + QueryVertexResponse queryVertex(QueryVertexRequest request); ExpendOneHopResponse expendOneHop(ExpendOneHopRequest request); } diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java index 4fa03c5c0..3a93c208a 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java @@ -28,6 +28,7 @@ import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; +import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; import com.antgroup.openspg.server.biz.common.ProjectManager; import com.antgroup.openspg.server.biz.service.GraphManager; import com.antgroup.openspg.server.biz.service.convertor.InstanceConvertor; @@ -230,7 +231,7 @@ private ExpendOneHopResponse convert2ExpendOneHopResponse( } @Override - public VertexRecord queryVertex(QueryVertexRequest request) { + public QueryVertexResponse queryVertex(QueryVertexRequest request) { String graphStoreUrl = projectManager.getGraphStoreUrl(request.getProjectId()); BaseLPGGraphStoreClient lpgGraphStoreClient = (BaseLPGGraphStoreClient) GraphStoreClientDriverManager.getClient(graphStoreUrl); @@ -238,9 +239,12 @@ public VertexRecord queryVertex(QueryVertexRequest request) { VertexLPGRecordQuery query = new VertexLPGRecordQuery(request.getBizId(), request.getTypeName()); GraphLPGRecordStruct struct = (GraphLPGRecordStruct) lpgGraphStoreClient.queryRecord(query); + + QueryVertexResponse response = new QueryVertexResponse(); if (struct == null || struct.getVertices().isEmpty()) { - return null; + return response; } - return struct.getVertices().get(0); + response.setVertex(struct.getVertices().get(0)); + return response; } } From 316fd8d85620bf3fb46dc4a0c1e9ad594e1a538b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Thu, 28 Nov 2024 14:32:24 +0800 Subject: [PATCH 09/12] rollback test script for graph_client --- python/knext/knext/graph/client.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index 0f0ebf58f..00c42b26e 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -94,30 +94,9 @@ def expend_one_hop( if __name__ == "__main__": - """ sc = GraphClient("http://127.0.0.1:8887", 4) out = sc.calculate_pagerank_scores( "Entity", [{"name": "Anxiety_and_nervousness", "type": "Entity"}] ) for o in out: - print(o) - """ - - # test ant main-site - client = GraphClient("https://spgservice-standard-pre.alipay.com", 644000146) - v = client.query_vertex("Antwork.EntityName", "千三") - print(v) - - edge_name = EdgeTypeName( - start_vertex_type="BCTEST.DeleteDataEntity3", - edge_label="concept", - end_vertex_type="BCTEST.TestConcept", - ) - client2 = GraphClient("https://spgservice-standard-pre.alipay.com", 363000133) - edge_type_name_constraint = [] - # edge_type_name_constraint.append(edge_name) - g1 = client2.expend_one_hop( - "BCTEST.DeleteDataEntity3", "秉初测试321", edge_type_name_constraint - ) - # g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name]) - # print(g1) + print(o) \ No newline at end of file From c00fd998eb1610e707bf765f1093b40384642757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Mon, 9 Dec 2024 20:19:41 +0800 Subject: [PATCH 10/12] (knext)bugfix --- python/knext/knext/graph/client.py | 2 +- .../search/rest/models/text_search_request.py | 19 ++++--------------- .../rest/models/vector_search_request.py | 9 ++------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index 00c42b26e..08ba7fbcb 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -99,4 +99,4 @@ def expend_one_hop( "Entity", [{"name": "Anxiety_and_nervousness", "type": "Entity"}] ) for o in out: - print(o) \ No newline at end of file + print(o) diff --git a/python/knext/knext/search/rest/models/text_search_request.py b/python/knext/knext/search/rest/models/text_search_request.py index deb0ac00e..046301ee0 100644 --- a/python/knext/knext/search/rest/models/text_search_request.py +++ b/python/knext/knext/search/rest/models/text_search_request.py @@ -81,9 +81,11 @@ def __init__( self.project_id = project_id self.query_string = query_string - self.label_constraints = label_constraints + if label_constraints is not None: + self.label_constraints = label_constraints self.topk = topk - self.params = params + if params is not None: + self.params = params @property def project_id(self): @@ -158,13 +160,6 @@ def label_constraints(self, label_constraints): :param label_constraints: The label_constraints of this TextSearchRequest. # noqa: E501 :type: list[str] """ - if ( - self.local_vars_configuration.client_side_validation - and label_constraints is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `label_constraints`, must not be `None`" - ) # noqa: E501 self._label_constraints = label_constraints @@ -213,12 +208,6 @@ def params(self, params): :param params: The params of this TextSearchRequest. # noqa: E501 :type: object """ - if ( - self.local_vars_configuration.client_side_validation and params is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `params`, must not be `None`" - ) # noqa: E501 self._params = params diff --git a/python/knext/knext/search/rest/models/vector_search_request.py b/python/knext/knext/search/rest/models/vector_search_request.py index 6e67e0459..9475adbaf 100644 --- a/python/knext/knext/search/rest/models/vector_search_request.py +++ b/python/knext/knext/search/rest/models/vector_search_request.py @@ -94,7 +94,8 @@ def __init__( if ef_search is not None: self.ef_search = ef_search self.topk = topk - self.params = params + if params is not None: + self.params = params @property def project_id(self): @@ -272,12 +273,6 @@ def params(self, params): :param params: The params of this VectorSearchRequest. # noqa: E501 :type: object """ - if ( - self.local_vars_configuration.client_side_validation and params is None - ): # noqa: E501 - raise ValueError( - "Invalid value for `params`, must not be `None`" - ) # noqa: E501 self._params = params From 43ef0148d4cac29b80efd1356261f8a944ec63b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Wed, 18 Dec 2024 14:54:04 +0800 Subject: [PATCH 11/12] feat(knext&server)add api for vertex batch query --- python/knext/knext/graph/__init__.py | 2 + python/knext/knext/graph/client.py | 9 + python/knext/knext/graph/rest/__init__.py | 2 + python/knext/knext/graph/rest/graph_api.py | 118 ++++++++++ .../knext/knext/graph/rest/models/__init__.py | 2 + .../rest/models/batch_query_vertex_request.py | 202 ++++++++++++++++++ .../models/batch_query_vertex_response.py | 134 ++++++++++++ .../request/BatchQueryVertexRequest.java | 20 ++ .../response/BatchQueryVertexResponse.java | 19 ++ .../http/server/openapi/GraphController.java | 26 ++- .../server/biz/service/GraphManager.java | 7 +- .../biz/service/impl/GraphManagerImpl.java | 30 ++- 12 files changed, 559 insertions(+), 12 deletions(-) create mode 100644 python/knext/knext/graph/rest/models/batch_query_vertex_request.py create mode 100644 python/knext/knext/graph/rest/models/batch_query_vertex_response.py create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java create mode 100644 server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java diff --git a/python/knext/knext/graph/__init__.py b/python/knext/knext/graph/__init__.py index ab4806941..09c5daee3 100644 --- a/python/knext/knext/graph/__init__.py +++ b/python/knext/knext/graph/__init__.py @@ -52,5 +52,7 @@ from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest from knext.graph.rest.models.query_vertex_response import QueryVertexResponse +from knext.graph.rest.models.batch_query_vertex_request import BatchQueryVertexRequest +from knext.graph.rest.models.batch_query_vertex_response import BatchQueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/client.py b/python/knext/knext/graph/client.py index 08ba7fbcb..baa13517e 100644 --- a/python/knext/knext/graph/client.py +++ b/python/knext/knext/graph/client.py @@ -19,6 +19,7 @@ GetPageRankScoresRequestStartNodes, WriterGraphRequest, QueryVertexRequest, + BatchQueryVertexRequest, ExpendOneHopRequest, EdgeTypeName, ) @@ -76,6 +77,14 @@ def query_vertex(self, type_name: str, biz_id: str): ) return self._rest_client.graph_query_vertex_post(query_vertex_request=request) + def batch_query_vertex(self, type_name: str, biz_ids: List[str]): + request = BatchQueryVertexRequest( + project_id=self._project_id, type_name=type_name, biz_ids=biz_ids + ) + return self._rest_client.graph_batch_query_vertex_post( + batch_query_vertex_request=request + ) + def expend_one_hop( self, type_name: str, diff --git a/python/knext/knext/graph/rest/__init__.py b/python/knext/knext/graph/rest/__init__.py index ab4806941..09c5daee3 100644 --- a/python/knext/knext/graph/rest/__init__.py +++ b/python/knext/knext/graph/rest/__init__.py @@ -52,5 +52,7 @@ from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest from knext.graph.rest.models.query_vertex_response import QueryVertexResponse +from knext.graph.rest.models.batch_query_vertex_request import BatchQueryVertexRequest +from knext.graph.rest.models.batch_query_vertex_response import BatchQueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/rest/graph_api.py b/python/knext/knext/graph/rest/graph_api.py index 4e7f0c221..887a7926a 100644 --- a/python/knext/knext/graph/rest/graph_api.py +++ b/python/knext/knext/graph/rest/graph_api.py @@ -989,3 +989,121 @@ def graph_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get("_request_timeout"), collection_formats=collection_formats, ) + + def graph_batch_query_vertex_post(self, **kwargs): # noqa: E501 + """batch_query_vertex # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_batch_query_vertex_post(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param BatchQueryVertexRequest batch_query_vertex_request: + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: BatchQueryVertexResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.graph_batch_query_vertex_post_with_http_info(**kwargs) # noqa: E501 + + def graph_batch_query_vertex_post_with_http_info(self, **kwargs): # noqa: E501 + """batch_query_vertex # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.graph_batch_query_vertex_post_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param BatchQueryVertexRequest batch_query_vertex_request: + :param _return_http_data_only: response data without head status code + and headers + :param _preload_content: if False, the urllib3.HTTPResponse object will + be returned without reading/decoding response + data. Default is True. + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: tuple(BatchQueryVertexResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["batch_query_vertex_request"] + all_params.extend( + [ + "async_req", + "_return_http_data_only", + "_preload_content", + "_request_timeout", + ] + ) + + for key, val in six.iteritems(local_var_params["kwargs"]): + if key not in all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method graph_batch_query_vertex_post" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + + collection_formats = {} + + path_params = {} + + query_params = [] + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if "batch_query_vertex_request" in local_var_params: + body_params = local_var_params["batch_query_vertex_request"] + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # HTTP header `Content-Type` + header_params[ + "Content-Type" + ] = self.api_client.select_header_content_type( # noqa: E501 + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + "/graph/batchQueryVertex", + "POST", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="BatchQueryVertexResponse", # noqa: E501 + auth_settings=auth_settings, + async_req=local_var_params.get("async_req"), + _return_http_data_only=local_var_params.get( + "_return_http_data_only" + ), # noqa: E501 + _preload_content=local_var_params.get("_preload_content", True), + _request_timeout=local_var_params.get("_request_timeout"), + collection_formats=collection_formats, + ) diff --git a/python/knext/knext/graph/rest/models/__init__.py b/python/knext/knext/graph/rest/models/__init__.py index 6bfdb6617..3a808f782 100644 --- a/python/knext/knext/graph/rest/models/__init__.py +++ b/python/knext/knext/graph/rest/models/__init__.py @@ -36,5 +36,7 @@ from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord from knext.graph.rest.models.query_vertex_request import QueryVertexRequest from knext.graph.rest.models.query_vertex_response import QueryVertexResponse +from knext.graph.rest.models.batch_query_vertex_request import BatchQueryVertexRequest +from knext.graph.rest.models.batch_query_vertex_response import BatchQueryVertexResponse from knext.graph.rest.models.vertex_record import VertexRecord from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse diff --git a/python/knext/knext/graph/rest/models/batch_query_vertex_request.py b/python/knext/knext/graph/rest/models/batch_query_vertex_request.py new file mode 100644 index 000000000..e120eabae --- /dev/null +++ b/python/knext/knext/graph/rest/models/batch_query_vertex_request.py @@ -0,0 +1,202 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class BatchQueryVertexRequest(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"project_id": "int", "type_name": "str", "biz_ids": "list[str]"} + + attribute_map = { + "project_id": "projectId", + "type_name": "typeName", + "biz_ids": "bizIds", + } + + def __init__( + self, + project_id=None, + type_name=None, + biz_ids=None, + local_vars_configuration=None, + ): # noqa: E501 + """BatchQueryVertexRequest - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._project_id = None + self._type_name = None + self._biz_ids = None + self.discriminator = None + + self.project_id = project_id + self.type_name = type_name + self.biz_ids = biz_ids + + @property + def project_id(self): + """Gets the project_id of this BatchQueryVertexRequest. # noqa: E501 + + + :return: The project_id of this BatchQueryVertexRequest. # noqa: E501 + :rtype: int + """ + return self._project_id + + @project_id.setter + def project_id(self, project_id): + """Sets the project_id of this BatchQueryVertexRequest. + + + :param project_id: The project_id of this BatchQueryVertexRequest. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation and project_id is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project_id`, must not be `None`" + ) # noqa: E501 + + self._project_id = project_id + + @property + def type_name(self): + """Gets the type_name of this BatchQueryVertexRequest. # noqa: E501 + + + :return: The type_name of this BatchQueryVertexRequest. # noqa: E501 + :rtype: str + """ + return self._type_name + + @type_name.setter + def type_name(self, type_name): + """Sets the type_name of this BatchQueryVertexRequest. + + + :param type_name: The type_name of this BatchQueryVertexRequest. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and type_name is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `type_name`, must not be `None`" + ) # noqa: E501 + + self._type_name = type_name + + @property + def biz_ids(self): + """Gets the biz_ids of this BatchQueryVertexRequest. # noqa: E501 + + + :return: The biz_ids of this BatchQueryVertexRequest. # noqa: E501 + :rtype: list[str] + """ + return self._biz_ids + + @biz_ids.setter + def biz_ids(self, biz_ids): + """Sets the biz_ids of this BatchQueryVertexRequest. + + + :param biz_ids: The biz_ids of this BatchQueryVertexRequest. # noqa: E501 + :type: list[str] + """ + if ( + self.local_vars_configuration.client_side_validation and biz_ids is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `biz_ids`, must not be `None`" + ) # noqa: E501 + + self._biz_ids = biz_ids + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, BatchQueryVertexRequest): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, BatchQueryVertexRequest): + return True + + return self.to_dict() != other.to_dict() diff --git a/python/knext/knext/graph/rest/models/batch_query_vertex_response.py b/python/knext/knext/graph/rest/models/batch_query_vertex_response.py new file mode 100644 index 000000000..28466d9f5 --- /dev/null +++ b/python/knext/knext/graph/rest/models/batch_query_vertex_response.py @@ -0,0 +1,134 @@ +# coding: utf-8 +# Copyright 2023 OpenSPG Authors +# +# Licensed 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. + + +""" + knext + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from knext.common.rest.configuration import Configuration + + +class BatchQueryVertexResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"vertices": "list[VertexRecord]"} + + attribute_map = {"vertices": "vertices"} + + def __init__(self, vertices=None, local_vars_configuration=None): # noqa: E501 + """BatchQueryVertexResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._vertices = None + self.discriminator = None + + self.vertices = vertices + + @property + def vertices(self): + """Gets the vertices of this BatchQueryVertexResponse. # noqa: E501 + + + :return: The vertices of this BatchQueryVertexResponse. # noqa: E501 + :rtype: list[VertexRecord] + """ + return self._vertices + + @vertices.setter + def vertices(self, vertices): + """Sets the vertices of this BatchQueryVertexResponse. + + + :param vertices: The vertices of this BatchQueryVertexResponse. # noqa: E501 + :type: list[VertexRecord] + """ + if ( + self.local_vars_configuration.client_side_validation and vertices is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `vertices`, must not be `None`" + ) # noqa: E501 + + self._vertices = vertices + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, BatchQueryVertexResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, BatchQueryVertexResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java new file mode 100644 index 000000000..f1ead1390 --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java @@ -0,0 +1,20 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.request; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class BatchQueryVertexRequest { + + private Long projectId; + private String typeName; + private List bizIds; +} diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java new file mode 100644 index 000000000..fd2b03599 --- /dev/null +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java @@ -0,0 +1,19 @@ +/* + * Ant Group + * Copyright (c) 2004-2024 All Rights Reserved. + */ +package com.antgroup.openspg.server.api.facade.dto.service.response; + +import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class BatchQueryVertexResponse { + + private List vertices; +} diff --git a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java index a4a6ae630..62c2122c2 100644 --- a/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java +++ b/server/api/http-server/src/main/java/com/antgroup/openspg/server/api/http/server/openapi/GraphController.java @@ -29,10 +29,7 @@ import com.antgroup.openspg.core.schema.model.type.ConceptList; import com.antgroup.openspg.core.schema.model.type.ProjectSchema; import com.antgroup.openspg.server.api.facade.dto.service.request.*; -import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; -import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; +import com.antgroup.openspg.server.api.facade.dto.service.response.*; import com.antgroup.openspg.server.api.http.server.HttpBizCallback; import com.antgroup.openspg.server.api.http.server.HttpBizTemplate; import com.antgroup.openspg.server.api.http.server.HttpResult; @@ -276,4 +273,25 @@ public QueryVertexResponse action() { } }); } + + @RequestMapping(value = "/batchQueryVertex", method = RequestMethod.POST) + @ResponseBody + public HttpResult batchQueryVertex( + @RequestBody BatchQueryVertexRequest request) { + return HttpBizTemplate.execute2( + new HttpBizCallback() { + @Override + public void check() { + AssertUtils.assertParamObjectIsNotNull("request", request); + AssertUtils.assertParamObjectIsNotNull("projectId", request.getProjectId()); + AssertUtils.assertParamObjectIsNotNull("typeName", request.getTypeName()); + AssertUtils.assertParamObjectIsNotNull("bizIds", request.getBizIds()); + } + + @Override + public BatchQueryVertexResponse action() { + return graphManager.batchQueryVertex(request); + } + }); + } } diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java index b90ac10c8..882cfb82e 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/GraphManager.java @@ -14,10 +14,7 @@ package com.antgroup.openspg.server.biz.service; import com.antgroup.openspg.server.api.facade.dto.service.request.*; -import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; -import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; +import com.antgroup.openspg.server.api.facade.dto.service.response.*; import java.util.List; public interface GraphManager { @@ -36,5 +33,7 @@ public interface GraphManager { QueryVertexResponse queryVertex(QueryVertexRequest request); + BatchQueryVertexResponse batchQueryVertex(BatchQueryVertexRequest request); + ExpendOneHopResponse expendOneHop(ExpendOneHopRequest request); } diff --git a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java index 3a93c208a..c43f0e6f0 100644 --- a/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java +++ b/server/biz/service/src/main/java/com/antgroup/openspg/server/biz/service/impl/GraphManagerImpl.java @@ -15,6 +15,7 @@ import com.antgroup.openspg.cloudext.interfaces.graphstore.BaseLPGGraphStoreClient; import com.antgroup.openspg.cloudext.interfaces.graphstore.GraphStoreClientDriverManager; +import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.BatchVertexLPGRecordQuery; import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.OneHopLPGRecordQuery; import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.PageRankCompete; import com.antgroup.openspg.cloudext.interfaces.graphstore.cmd.VertexLPGRecordQuery; @@ -25,10 +26,7 @@ import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.struct.GraphLPGRecordStruct; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.EdgeTypeName; import com.antgroup.openspg.server.api.facade.dto.service.request.*; -import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse; -import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance; -import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse; +import com.antgroup.openspg.server.api.facade.dto.service.response.*; import com.antgroup.openspg.server.biz.common.ProjectManager; import com.antgroup.openspg.server.biz.service.GraphManager; import com.antgroup.openspg.server.biz.service.convertor.InstanceConvertor; @@ -247,4 +245,28 @@ public QueryVertexResponse queryVertex(QueryVertexRequest request) { response.setVertex(struct.getVertices().get(0)); return response; } + + @Override + public BatchQueryVertexResponse batchQueryVertex(BatchQueryVertexRequest request) { + String graphStoreUrl = projectManager.getGraphStoreUrl(request.getProjectId()); + BaseLPGGraphStoreClient lpgGraphStoreClient = + (BaseLPGGraphStoreClient) GraphStoreClientDriverManager.getClient(graphStoreUrl); + + BatchQueryVertexResponse response = new BatchQueryVertexResponse(); + response.setVertices(Lists.newArrayList()); + + if (CollectionUtils.isEmpty(request.getBizIds())) { + return response; + } + + Set idSet = new HashSet<>(request.getBizIds()); + + BatchVertexLPGRecordQuery query = new BatchVertexLPGRecordQuery(idSet, request.getTypeName()); + GraphLPGRecordStruct struct = (GraphLPGRecordStruct) lpgGraphStoreClient.queryRecord(query); + + if (struct != null && !struct.getVertices().isEmpty()) { + response.setVertices(struct.getVertices()); + } + return response; + } } From 717067486e74a6eef414ac6cfb6194ef5ad6f88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=89=E5=88=9D?= Date: Thu, 26 Dec 2024 16:35:42 +0800 Subject: [PATCH 12/12] fix problems of CI --- .../service/request/BatchQueryVertexRequest.java | 13 +++++++++++-- .../dto/service/request/ExpendOneHopRequest.java | 13 +++++++++++-- .../dto/service/request/QueryVertexRequest.java | 13 +++++++++++-- .../service/response/BatchQueryVertexResponse.java | 13 +++++++++++-- .../dto/service/response/ExpendOneHopResponse.java | 13 +++++++++++-- .../dto/service/response/QueryVertexResponse.java | 13 +++++++++++-- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java index f1ead1390..23a88763a 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/BatchQueryVertexRequest.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.request; import java.util.List; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java index aa2a5420c..2b8885364 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/ExpendOneHopRequest.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.request; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.schema.EdgeTypeName; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java index bc15551db..987eb554b 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/request/QueryVertexRequest.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.request; import lombok.AllArgsConstructor; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java index fd2b03599..efd8020b3 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/BatchQueryVertexResponse.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.response; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java index 3701128f7..dd0063be7 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/ExpendOneHopResponse.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.response; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.EdgeRecord; diff --git a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java index d38daea4c..fc857bdc0 100644 --- a/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java +++ b/server/api/facade/src/main/java/com/antgroup/openspg/server/api/facade/dto/service/response/QueryVertexResponse.java @@ -1,7 +1,16 @@ /* - * Ant Group - * Copyright (c) 2004-2024 All Rights Reserved. + * Copyright 2023 OpenSPG Authors + * + * Licensed 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. */ + package com.antgroup.openspg.server.api.facade.dto.service.response; import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord;