Simplify the usage of dict (#2681)

### What problem does this PR solve?
Simplify the usage of dictionaries

### Type of change

- [x] Refactoring

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
yqkcn 2024-09-30 16:54:25 +08:00 committed by GitHub
parent 9945988e44
commit ae5a877ed4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import itertools
import logging import logging
import re import re
import traceback import traceback
@ -93,16 +93,12 @@ class EntityResolution:
node_clusters[graph.nodes[node]['entity_type']].append(node) node_clusters[graph.nodes[node]['entity_type']].append(node)
candidate_resolution = {entity_type: [] for entity_type in entity_types} candidate_resolution = {entity_type: [] for entity_type in entity_types}
for node_cluster in node_clusters.items(): for k, v in node_clusters.items():
candidate_resolution_tmp = [] candidate_resolution_tmp = []
for a in node_cluster[1]: for a, b in itertools.permutations(v, 2):
for b in node_cluster[1]:
if a == b:
continue
if self.is_similarity(a, b) and (b, a) not in candidate_resolution_tmp: if self.is_similarity(a, b) and (b, a) not in candidate_resolution_tmp:
candidate_resolution_tmp.append((a, b)) candidate_resolution_tmp.append((a, b))
if candidate_resolution_tmp: candidate_resolution[k] = candidate_resolution_tmp
candidate_resolution[node_cluster[0]] = candidate_resolution_tmp
gen_conf = {"temperature": 0.5} gen_conf = {"temperature": 0.5}
resolution_result = set() resolution_result = set()