simon824 commented on code in PR #7:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/7#discussion_r1364807873


##########
hugegraph-llm/src/operators/build_kg/disambiguate_data.py:
##########
@@ -0,0 +1,239 @@
+# 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.
+import json
+import re
+from itertools import groupby
+
+from src.operators.build_kg.unstructured_data_utils import (
+    nodes_text_to_list_of_dict,
+    relationships_text_to_list_of_dict,
+    relationships_schemas_text_to_list_of_dict,
+    nodes_schemas_text_to_list_of_dict,
+)
+
+
+def generate_system_message_for_nodes() -> str:
+    return """
+Your task is to identify if there are duplicated nodes and if so merge them 
into one nod. Only merge the nodes that refer to the same entity.
+You will be given different datasets of nodes and some of these nodes may be 
duplicated or refer to the same entity. 
+The datasets contains nodes in the form [ENTITY_ID, TYPE, PROPERTIES]. When 
you have completed your task please give me the 
+resulting nodes in the same format. Only return the nodes and relationships no 
other text. If there is no duplicated nodes return the original nodes.
+
+Here is an example
+The input you will be given:
+["Alice", "Person", {"age" : 25, "occupation": "lawyer", "name":"Alice"}], 
["Bob", "Person", {"occupation": "journalist", "name": "Bob"}], ["alice.com", 
"Webpage", {"url": "www.alice.com"}], ["bob.com", "Webpage", {"url": 
"www.bob.com"}], ["Bob", "Person", {"occupation": "journalist", "name": "Bob"}]
+The output you need to provide:
+["Alice", "Person", {"age" : 25, "occupation": "lawyer", "name":"Alice"}], 
["Bob", "Person", {"occupation": "journalist", "name": "Bob"}], ["alice.com", 
"Webpage", {"url": "www.alice.com"}], ["bob.com", "Webpage", {"url": 
"www.bob.com"}]
+"""
+
+
+def generate_system_message_for_relationships() -> str:
+    return """
+Your task is to identify if a set of relationships make sense.
+If they do not make sense please remove them from the dataset.
+Some relationships may be duplicated or refer to the same entity. 
+Please merge relationships that refer to the same entity.
+The datasets contains relationships in the form [{"ENTITY_TYPE_1": 
"ENTITY_ID_1"}, RELATIONSHIP, {"ENTITY_TYPE_2": "ENTITY_ID_2"}, PROPERTIES].
+You will also be given a set of ENTITY_IDs that are valid.
+Some relationships may use ENTITY_IDs that are not in the valid set but refer 
to a entity in the valid set.
+If a relationships refer to a ENTITY_ID in the valid set please change the ID 
so it matches the valid ID.
+When you have completed your task please give me the valid relationships in 
the same format. Only return the relationships no other text.
+
+Here is an example
+The input you will be given:
+[{"Person": "Alice"}, "roommate", {"Person": "bob"}, {"start": 2021}], 
[{"Person": "Alice"}, "owns", {"Webpage": "alice.com"}, {}], [{"Person": 
"Bob"}, "owns", {"Webpage": "bob.com"}, {}], [{"Person": "Alice"}, "owns", 
{"Webpage": "alice.com"}, {}]
+The output you need to provide:
+[{"Person": "Alice"}, "roommate", {"Person": "bob"}, {"start": 2021}], 
[{"Person": "Alice"}, "owns", {"Webpage": "alice.com"}, {}], [{"Person": 
"Bob"}, "owns", {"Webpage": "bob.com"}, {}]
+"""
+
+
+def generate_system_message_for_nodes_schemas() -> str:
+    return """
+Your task is to identify if there are duplicated nodes schemas and if so merge 
them into one nod. Only merge the nodes schemas that refer to the same 
entty_types.
+You will be given different node schemas, some of which may duplicate or 
reference the same entty_types. Note: For node schemas with the same 
entty_types, you need to merge them while merging all properties of the 
entty_types. 
+The datasets contains nodes schemas in the form [ENTITY_TYPE, PRIMARY KEY, 
PROPERTIES]. When you have completed your task please give me the 
+resulting nodes schemas in the same format. Only return the nodes schemas no 
other text. If there is no duplicated nodes return the original nodes schemas.
+
+Here is an example
+The input you will be given:
+["Person", "name",  {"age": "int", "name": "text", "occupation": "text"}],  
["Webpage", "url", {url: "text"}],  ["Webpage", "url", {url: "text"}]
+The output you need to provide:
+["Person", "name",  {"age": "int", "name": "text", "occupation": "text"}],  
["Webpage", "url", {url: "text"}]
+"""
+
+
+def generate_system_message_for_relationships_schemas() -> str:

Review Comment:
   ditto



-- 
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]

Reply via email to