我通常在我的应用程序中做的是使用工厂方法创建我所有的服务/dao/repo/clients
class Service:
def init(self, db):
self._db = db
@classmethod
def from_env(cls):
return cls(db=PostgresDatabase.from_env())
Run Code Online (Sandbox Code Playgroud)
当我创建应用程序时
service = Service.from_env()
Run Code Online (Sandbox Code Playgroud)
什么创建了所有依赖项
在我不想使用真实数据库的测试中,我只做 DI
service = Service(db=InMemoryDatabse())
Run Code Online (Sandbox Code Playgroud)
我想这与干净/十六进制架构相去甚远,因为 Service 知道如何创建数据库并知道它创建的数据库类型(也可能是 InMemoryDatabse 或 MongoDatabase)
我想在干净/十六进制架构中我会有
class DatabaseInterface(ABC):
@abstractmethod
def get_user(self, user_id: int) -> User:
pass
import inject
class Service:
@inject.autoparams()
def __init__(self, db: DatabaseInterface):
self._db = db
Run Code Online (Sandbox Code Playgroud)
我会设置注入器框架来做
# in app
inject.clear_and_configure(lambda binder: binder
.bind(DatabaseInterface, PostgresDatabase()))
# in test
inject.clear_and_configure(lambda binder: binder
.bind(DatabaseInterface, InMemoryDatabse()))
Run Code Online (Sandbox Code Playgroud)
我的问题是:
python architecture dependency-injection hexagonal-architecture clean-architecture
是否有任何 NLP python 库可以拆分句子或将单词连接成相关的单词对?例如:
那不是坏例子->“那个”“是”“不错”“例子”
“不错”的意思是一样的好,所以在机器学习中把它当作“不”和“坏”来处理是没有用的。我什至不知道如何称呼这些相关的词对。(术语提取?阶段提取?)或者甚至更好地拆分为带名词的形容词,例如:
与减税有关的不诚实媒体 -> “不诚实媒体”、“相关”、“关于”、“减税”
我找到了 toopia.termextract 但它不适用于 python3。