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

Added state pattern to Query class #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions backend/controller/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from haystack.reader.farm import FARMReader
from haystack.retriever.elasticsearch import ElasticsearchRetriever
from pydantic import BaseModel
from abc import ABC, abstractmethod

from covid_nlp.language.detect_language import LanguageDetector

Expand Down Expand Up @@ -95,6 +96,31 @@
#############################################
# Basic data schema for request & response
#############################################

class Context:
_state = None
def __init__(self, state: State) -> None:
self.transition_to(state)

def transition_to(self, state: State):
self._state = state
self._state.context = self

def get_filtered(self):
self._state.get_filtered()
class State(ABC):
@property
def context(self) -> Context:
return self._context

@context.setter
def context(self, context: Context) -> None:
self._context = context

@abstractmethod
def get_filtered(self) -> None:
pass

class Query(BaseModel):
questions: List[str]
filters: Dict[str, Optional[str]] = None
Expand Down