通过AWS Comprehend在SQLite数据库中运行数据的工具
项目描述
sqlite-comprehend
通过AWS Comprehend在SQLite数据库中运行数据的工具
有关此项目的背景信息,请参阅sqlite-comprehend: run AWS entity extraction against content in a SQLite database。
安装
使用pip
安装此工具
pip install sqlite-comprehend
演示
您可以在以下位置查看使用此命令生成的表示例
- comprehend_entities - 按类型分类的提取实体
- blog_entry_comprehend_entities - 将实体与它们出现的条目关联的表
- comprehend_entity_types - 实体类型的小查找表
配置
您将需要具有comprehend:BatchDetectEntities
IAM权限的AWS凭据。
您可以使用这些说明配置凭据。您还可以将它们保存到JSON或INI配置文件中,并使用-a credentials.ini
将它们传递给命令,或者使用--access-key
和--secret-key
选项进行传递。
实体提取
sqlite-comprehend entities
命令将对指定表中每一行运行实体提取,并将结果保存到您的数据库中。
指定数据库、表以及包含文本的一个或多个列。以下操作针对的是 sfms.db
SQLite数据库中pages
表的text
列。
sqlite-comprehend sfms.db pages text
结果将写入到pages_comprehend_entities
表中。可以通过传递-o other_table_name
来更改输出表名。
可以通过添加--where
子句来针对行子集运行。
sqlite-comprehend sfms.db pages text --where 'id < 10'
您也可以在--where
子句中使用命名参数。
sqlite-comprehend sfms.db pages text --where 'id < :maxid' -p maxid 10
每行只考虑前5000个字符。请务必查阅Comprehend的定价 - 起价为每百个字符0.0001美元。
如果您的上下文包含HTML标签,可以在提取实体之前通过添加--strip-tags
将其删除。
sqlite-comprehend sfms.db pages text --strip-tags
已处理的行记录在pages_comprehend_entities_done
表中。如果多次运行命令,它将只处理新添加的行。
可以删除该_done
表中的记录以再次运行它们。
sqlite-comprehend entities --help
Usage: sqlite-comprehend entities [OPTIONS] DATABASE TABLE COLUMNS...
Detect entities in columns in a table
To extract entities from columns text1 and text2 in mytable:
sqlite-comprehend entities my.db mytable text1 text2
To run against just a subset of the rows in the table, add:
--where "id < :max_id" -p max_id 50
Results will be written to a table called mytable_comprehend_entities
To specify a different output table, use -o custom_table_name
Options:
--where TEXT WHERE clause to filter table
-p, --param <TEXT TEXT>... Named :parameters for SQL query
-o, --output TEXT Custom output table
-r, --reset Start from scratch, deleting previous results
--strip-tags Strip HTML tags before extracting entities
--access-key TEXT AWS access key ID
--secret-key TEXT AWS secret access key
--session-token TEXT AWS session token
--endpoint-url TEXT Custom endpoint URL
-a, --auth FILENAME Path to JSON/INI file containing credentials
--help Show this message and exit.
架构
假设有一个名为pages
的输入表,此工具创建的表将具有以下架构
CREATE TABLE [pages] (
[id] INTEGER PRIMARY KEY,
[text] TEXT
);
CREATE TABLE [comprehend_entity_types] (
[id] INTEGER PRIMARY KEY,
[value] TEXT
);
CREATE TABLE [comprehend_entities] (
[id] INTEGER PRIMARY KEY,
[name] TEXT,
[type] INTEGER REFERENCES [comprehend_entity_types]([id])
);
CREATE TABLE [pages_comprehend_entities] (
[id] INTEGER REFERENCES [pages]([id]),
[score] FLOAT,
[entity] INTEGER REFERENCES [comprehend_entities]([id]),
[begin_offset] INTEGER,
[end_offset] INTEGER
);
CREATE UNIQUE INDEX [idx_comprehend_entity_types_value]
ON [comprehend_entity_types] ([value]);
CREATE UNIQUE INDEX [idx_comprehend_entities_type_name]
ON [comprehend_entities] ([type], [name]);
CREATE TABLE [pages_comprehend_entities_done] (
[id] INTEGER PRIMARY KEY REFERENCES [pages]([id])
);
开发
要为此工具做出贡献,首先检出代码。然后创建一个新的虚拟环境
cd sqlite-comprehend
python -m venv venv
source venv/bin/activate
现在安装依赖项并测试依赖项
pip install -e '.[test]'
要运行测试
pytest
项目详情
下载文件
下载适合您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
sqlite-comprehend-0.2.2.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | b105152a178091ea24aaaafc362574c9e1206f2fda3bc14407f862f5e6c4b730 |
|
MD5 | 0846f3fa3806d342616f7a1483d078aa |
|
BLAKE2b-256 | 95faa80fcf8d8f99d92e9978bd99fb490173f45f94b13981ce0ff30fbd1c58c8 |
sqlite_comprehend-0.2.2-py3-none-any.whl的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | ee81985dd9f09b1075fce1309ab80d9ceb928ee5b6e304430790a8cc403c2420 |
|
MD5 | 4242c9095a8272595f01f45629c26330 |
|
BLAKE2b-256 | 796307f32b6ada2eac0c1d6f67156f567488b43c78b6e577c0bb7c58957bfc65 |