javeme commented on code in PR #5:
URL:
https://github.com/apache/incubator-hugegraph-ai/pull/5#discussion_r1354368109
##########
hugegraph-python/example/test_hugegraph.py:
##########
@@ -0,0 +1,31 @@
+class HugeGraph:
+ """HugeGraph wrapper for graph operations"""
+
+ def __init__(
+ self,
+ username: str = "default",
+ password: str = "default",
+ address: str = "127.0.0.1",
+ port: int = 8081,
+ graph: str = "hugegraph"
+ ) -> None:
+ """Create a new HugeGraph wrapper instance."""
+ try:
+ from src.connection import PyHugeClient
+ except ImportError:
+ raise ValueError(
+ "Please install HugeGraph Python client first: "
+ "`pip3 install hugegraph-python-client`"
+ )
+
+ self.username = username
+ self.password = password
+ self.address = address
+ self.port = port
+ self.graph = graph
+ self.client = PyHugeClient(address, port, user=username, pwd=password,
graph=graph)
+ self.schema = ""
+
+ def exec(self, query) -> str:
+ """Returns the schema of the HugeGraph database"""
+ return self.client.gremlin().exec(query)
Review Comment:
expect a blank line
##########
hugegraph-python/example/test_connection.py:
##########
@@ -0,0 +1,23 @@
+import unittest
+from typing import Any
+from unittest.mock import MagicMock, patch
+
+from example.test_hugegraph import HugeGraph
+
+class TestHugeGraph(unittest.TestCase):
+ def setUp(self) -> None:
+ self.username = "test_user"
+ self.password = "test_password"
+ self.address = "test_address"
+ self.graph = "test_hugegraph"
+ self.port = 1234
+ self.session_pool_size = 10
+
+ @patch("src.connection.PyHugeGraph")
+ def test_init(self, a: Any) -> None:
+ a.return_value = MagicMock()
+ client = HugeGraph( self.username, self.password,self.address,
self.port, self.graph)
Review Comment:
a space in "( self"
##########
hugegraph-python/src/connection.py:
##########
@@ -0,0 +1,57 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from src.api.common import HugeParamsBase
+from src.api.graph import GraphManager
+from src.api.graphs import GraphsManager
+from src.api.gremlin import GremlinManager
+from src.api.schema import SchemaManager
+from src.structure.graph_instance import GraphInstance
+
+
+class PyHugeClient(HugeParamsBase):
Review Comment:
can we rename the file to client.py?
##########
hugegraph-python/example/test_connection.py:
##########
@@ -0,0 +1,23 @@
+import unittest
+from typing import Any
+from unittest.mock import MagicMock, patch
+
+from example.test_hugegraph import HugeGraph
+
+class TestHugeGraph(unittest.TestCase):
Review Comment:
prefer HugeGraphTest
##########
hugegraph-python/example/test.py:
##########
@@ -0,0 +1,51 @@
+from src.connection import PyHugeClient
+
+if __name__ == '__main__':
+ client = PyHugeClient("10.22.32.25", "8080", user="admin", pwd="pe@2023",
graph="physical_examination_test")
+
+ """schema"""
+ schema = client.schema()
+ schema.propertyKey("name").asText().ifNotExist().create()
+ schema.propertyKey("birthDate").asText().ifNotExist().create()
+ schema.vertexLabel("Person").properties("name",
"birthDate").usePrimaryKeyId().primaryKeys(
+ "name").ifNotExist().create()
+
schema.vertexLabel("Movie").properties("name").usePrimaryKeyId().primaryKeys("name").ifNotExist().create()
+
schema.edgeLabel("ActedIn").sourceLabel("Person").targetLabel("Movie").ifNotExist().create()
+
+ print(schema.getVertexLabels())
+ print(schema.getEdgeLabels())
+ print(schema.getRelations())
+
+ """graph"""
+ g = client.graph()
+ # 增加点
+ p1 = g.addVertex("Person", {"name": "Al Pacino", "birthDate":
"1940-04-25"})
+ p2 = g.addVertex("Person", {"name": "Robert De Niro", "birthDate":
"1943-08-17"})
+ m1 = g.addVertex("Movie", {"name": "The Godfather"})
+ m2 = g.addVertex("Movie", {"name": "The Godfather Part II"})
+ m3 = g.addVertex("Movie", {"name": "The Godfather Coda The Death of
Michael Corleone"})
+
+ # 增加边
Review Comment:
translate them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]