Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying proxy pattern #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions covid_nlp/language/ms_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import pandas as pd

import json
from typing import Dict


class MSTranslator():
def __init__(self, key = None, endpoint = None, lang = None):
Expand All @@ -19,6 +22,43 @@ def __init__(self, key = None, endpoint = None, lang = None):
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}
t__(self, shared_state: str) -> None:
self._shared_state = shared_state

def operation(self, unique_state: str) -> None:
s = json.dumps(self._shared_state)
u = json.dumps(unique_state)


class MSTranslatorFactory():


_MSTranslators: Dict[str, MSTranslator] = {}

def __init__(self, initial_MSTranslators: Dict) -> None:
for state in initial_MSTranslators:
self._MSTranslators[self.get_key(state)] = MSTranslator(state)

def get_key(self, state: Dict) -> str:


return "_".join(sorted(state))

def get_MSTranslator(self, shared_state: Dict) -> MSTranslator:

key = self.get_key(shared_state)

if not self._MSTranslators.get(key):
print("MSTranslatorFactory: Can't find a MSTranslator, creating new one.")
self._MSTranslators[key] = MSTranslator(shared_state)
else:
print("MSTranslatorFactory: Reusing existing MSTranslator.")

return self._MSTranslators[key]

def list_MSTranslators(self) -> None:
count = len(self._MSTranslators)


def translate(self, text):
body = [{'text': text.strip()}]
Expand Down
14 changes: 13 additions & 1 deletion datasources/META_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
MISSED = []


class Pipeline(object):
class Singleton(object):

_instances = {}

def getInstance (*args,**kwargs, theClass):

if theClass not in theClass.instances:

instance = super().getInstance(*args,**kwargs)
theClass._instances[theClass] = instance

return theClass._instances[theClass]

questionsOnly = True

def filter(self, item, index):
Expand Down