-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added geotext class that upon init loads demo data by default. added …
…tests. updated extractor.py
- Loading branch information
Showing
6 changed files
with
49 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,3 @@ | ||
import json | ||
|
||
from flashtext import KeywordProcessor | ||
|
||
from flashgeotext.settings import DEMODATA_CITIES | ||
from flashgeotext.settings import DEMODATA_COUNTRIES | ||
|
||
|
||
class Alphabets(object): | ||
pass | ||
|
||
|
||
class Extractor(object): | ||
_cities_processor: KeywordProcessor = KeywordProcessor(case_sensitive=True) | ||
_countries_processor: KeywordProcessor = KeywordProcessor(case_sensitive=True) | ||
|
||
def extract(self, input_text: str, span_info: bool = True): | ||
pass | ||
|
||
|
||
class GeoText(Extractor): | ||
cities: dict = {} | ||
countries: dict = {} | ||
|
||
def __init__(self, use_demo_data: bool = True): | ||
self._flush_processor() | ||
|
||
if use_demo_data: | ||
self.cities = load_data_from_file(file=DEMODATA_CITIES) | ||
self.countries = load_data_from_file(file=DEMODATA_COUNTRIES) | ||
self.build_cities_processor() | ||
self.build_countries_processor() | ||
|
||
def build(self) -> None: | ||
self._flush_processor() | ||
self.build_cities_processor() | ||
self.build_countries_processor() | ||
|
||
def build_cities_processor(self) -> None: | ||
if self.cities: | ||
self._cities_processor.add_keywords_from_dict(self.cities) | ||
|
||
def build_countries_processor(self) -> None: | ||
if self.countries: | ||
self._countries_processor.add_keywords_from_dict(self.countries) | ||
|
||
def _flush_processor(self) -> None: | ||
self._cities_processor.keyword_trie_dict = dict() | ||
self._cities_processor._terms_in_trie = 0 | ||
self._countries_processor.keyword_trie_dict = dict() | ||
self._countries_processor._terms_in_trie = 0 | ||
|
||
|
||
def load_data_from_file(file: str) -> dict: | ||
with open(file, "r", encoding="utf-8") as f: | ||
return json.loads(f.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from flashgeotext.extractor import Extractor | ||
from flashgeotext.lookup import LookupDataPool | ||
|
||
|
||
class GeoText(LookupDataPool, Extractor): | ||
def __init__(self, use_demo_data: bool = True) -> None: | ||
self.pool: dict = {} | ||
|
||
if use_demo_data: | ||
self._add_demo_data() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.