Skip to content

Commit

Permalink
demodata now is dict by default for now
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Feb 17, 2020
1 parent 7df6fb3 commit e7f78f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 727 deletions.
25 changes: 6 additions & 19 deletions flashgeotext/extractor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from typing import Union

from flashtext import KeywordProcessor

Expand All @@ -12,30 +11,18 @@ class Alphabets(object):


class DemoData(object):
cities: Union[list, dict] = []
countries: Union[list, dict] = []
cities: dict = {}
countries: dict = {}

def __init__(self, with_synonyms: bool = True):
self.load_demo_data(with_synonyms=with_synonyms)
def load(self) -> None:

def load_demo_data(self, with_synonyms: bool = True) -> None:
self.cities = self._load_data_dict(file=DEMODATA_CITIES)
self.countries = self._load_data_dict(file=DEMODATA_COUNTRIES)

if with_synonyms:
self.cities = self._load_data_dict(file=DEMODATA_CITIES)
self.countries = self._load_data_dict(file=DEMODATA_COUNTRIES)

else:
self.cities = self._load_data_list(file=DEMODATA_CITIES)
self.countries = self._load_data_list(file=DEMODATA_COUNTRIES)

def _load_data_dict(self, file: str = "") -> dict:
def _load_data_dict(self, file: str) -> dict:
with open(file, "r", encoding="utf-8") as f:
return json.loads(f.read())

def _load_data_list(self, file: str = "") -> list:
with open(file, "r", encoding="utf-8") as f:
return list(json.loads(f.read()).keys())


class Extractor:
cities: KeywordProcessor = KeywordProcessor(case_sensitive=True)
Expand Down

0 comments on commit e7f78f3

Please sign in to comment.