Unverified Commit f4daa679 authored by Tao Feng's avatar Tao Feng Committed by GitHub

Fix encoding issue for publisher (#260)

* Fix encoding issue for publisher

* per pr feedback
parent 2018cc66
import copy import copy
import csv import csv
import ctypes import ctypes
from io import open
import logging import logging
import time import time
from os import listdir from os import listdir
...@@ -222,7 +223,7 @@ class Neo4jCsvPublisher(Publisher): ...@@ -222,7 +223,7 @@ class Neo4jCsvPublisher(Publisher):
# type: (str) -> None # type: (str) -> None
LOGGER.info('Creating indices. (Existing indices will be ignored)') LOGGER.info('Creating indices. (Existing indices will be ignored)')
with open(node_file, 'r') as node_csv: with open(node_file, 'r', encoding='utf8') as node_csv:
for node_record in csv.DictReader(node_csv): for node_record in csv.DictReader(node_csv):
label = node_record[NODE_LABEL_KEY] label = node_record[NODE_LABEL_KEY]
if label not in self.labels: if label not in self.labels:
...@@ -250,7 +251,7 @@ class Neo4jCsvPublisher(Publisher): ...@@ -250,7 +251,7 @@ class Neo4jCsvPublisher(Publisher):
:return: :return:
""" """
with open(node_file, 'r') as node_csv: with open(node_file, 'r', encoding='utf8') as node_csv:
for count, node_record in enumerate(csv.DictReader(node_csv)): for count, node_record in enumerate(csv.DictReader(node_csv)):
stmt = self.create_node_merge_statement(node_record=node_record) stmt = self.create_node_merge_statement(node_record=node_record)
tx = self._execute_statement(stmt, tx) tx = self._execute_statement(stmt, tx)
...@@ -306,7 +307,7 @@ class Neo4jCsvPublisher(Publisher): ...@@ -306,7 +307,7 @@ class Neo4jCsvPublisher(Publisher):
LOGGER.info('Pre-processing relation with {}'.format(self._relation_preprocessor)) LOGGER.info('Pre-processing relation with {}'.format(self._relation_preprocessor))
count = 0 count = 0
with open(relation_file, 'r') as relation_csv: with open(relation_file, 'r', encoding='utf8') as relation_csv:
for rel_record in csv.DictReader(relation_csv): for rel_record in csv.DictReader(relation_csv):
stmt, params = self._relation_preprocessor.preprocess_cypher( stmt, params = self._relation_preprocessor.preprocess_cypher(
start_label=rel_record[RELATION_START_LABEL], start_label=rel_record[RELATION_START_LABEL],
...@@ -322,7 +323,7 @@ class Neo4jCsvPublisher(Publisher): ...@@ -322,7 +323,7 @@ class Neo4jCsvPublisher(Publisher):
LOGGER.info('Executed pre-processing Cypher statement {} times'.format(count)) LOGGER.info('Executed pre-processing Cypher statement {} times'.format(count))
with open(relation_file, 'r') as relation_csv: with open(relation_file, 'r', encoding='utf8') as relation_csv:
for count, rel_record in enumerate(csv.DictReader(relation_csv)): for count, rel_record in enumerate(csv.DictReader(relation_csv)):
stmt = self.create_relationship_merge_statement(rel_record=rel_record) stmt = self.create_relationship_merge_statement(rel_record=rel_record)
tx = self._execute_statement(stmt, tx, tx = self._execute_statement(stmt, tx,
......
...@@ -2,7 +2,7 @@ import os ...@@ -2,7 +2,7 @@ import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
__version__ = '2.5.12' __version__ = '2.5.13'
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt') requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file: with open(requirements_path) as requirements_file:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment