从带有参数的条目表创建范例。
pyradigms的Python项目详细描述
吡咯烷酮
从带有参数的条目表创建范例。在
入门
pip install pyradigms
使用
有两种不同的方法;read_file
从一个带有参数的表单列表的.csv
文件创建一个三维字典,print_paradigms
从这样的字典中创建人类可读的范例,也是.csv
格式。
您可以先读取文件,然后打印所需的范例,也可以直接从三维散列中打印范例。在
read_file
为了指定应该投影到哪个维度上的参数,必须传递参数x
、y
和{.csv
文件中的列名。
z
表示输出中垂直或多个文件中列出的多个范例表。
y
表示单个范例表的行。
x
表示单个范例表的列。
这些维度必须都是字符串的列表,如果一个列表包含多个字符串,那么这些参数将在结果范例中组合。
范例单元格中打印的是Form
列中的值;如果您的.csv
文件使用不同的标签,请使用read_file(target_string=<label>)
指定它
示意用法:
import pyradigms
pd = pyradigms.Pyradigms()
pd.read_file(
"input.csv",
x = ["X1", "X2"],
y = ["Y"],
z = ["Z"],
)
pd.print_paradigms()
以下是所附示例的说明:
文件examples/latin_verbs.csv
包含Form Person Number Tense Verb Mood
列:
Form | Person | Number | Tense | Verb | Mood |
---|---|---|---|---|---|
portoː | 1 | SG | PRS | portaːre | IND |
portaːs | 2 | SG | PRS | portaːre | IND |
portat | 3 | SG | PRS | portaːre | IND |
portaːmus | 1 | PL | PRS | portaːre | IND |
portaːtis | 2 | PL | PRS | portaːre | IND |
portant | 3 | PL | PRS | portaːre | IND |
terːeoː | 1 | SG | PRS | terːeːre | IND |
… | … | … | … | … | … |
例如,人们可能想把人和数字,以及时态和情绪结合起来。 每个动词都应该有一个单独的范例。 实现方法如下:
^{pr2}$这导致了以下范例列表(在“拉丁语动词_范例.csv“):
^{tb2}$terːeːre | 1SG | 2SG | 3SG | 1PL | 2PL | 3PL |
---|---|---|---|---|---|---|
PRS:IND | terːeoː | terːeːs | terːet | terːeːmus | terːeːtis | terːent |
PST.IPFV:IND | terːeːbam | terːeːbaːs | terːeːbat | terːeːbaːmus | terːeːbaːtis | terːeːbant |
FUT:IND | terːeːboː | terːeːbis | terːeːbit | terːeːbimus | terːeːbitis | terːeːbunt |
PRS:SUBJ | terːream | terːeaːs | terːeat | terːeaːmus | terːeaːtis | terːeant |
PST.IPFV:SUBJ | terːeːrem | terːeːres | terːeret | terːeːreːmus | terːeːreːtis | terːeːrent |
petere | 1SG | 2SG | 3SG | 1PL | 2PL | 3PL |
---|---|---|---|---|---|---|
PRS:IND | petoː | petis | petit | petimus | petitis | petunt |
PST.IPFV:IND | peteːbam | peteːbas | peteːbat | peteːbaːmus | peteːbaːtis | peteːbant |
FUT:IND | petam | peteːs | petet | peteːmus | peteːtis | petent |
PRS:SUBJ | petam | petaːs | petat | petaːmus | petaːtis | petant |
PST.IPFV:SUBJ | peteːbar | peteːbaːris; peteːbaːre | peteːbaːtur | peteːbaːmus | peteːbaːminiː | peteːbaːtur |
您可以根据需要排列和组合参数。
如果要过滤某个参数,可以添加任意数量的filtered_parameters
,然后过滤特定的值。
如果一个参数没有出现在这三个轴上,而且不在filtered_parameters
列表中,它将被完全忽略,pyradigms
将只采用满足所有条件的第一个形式!(目前)
read_file()
的其他选项:
- 选项
multiple_files=True
将输出分配到多个文件中,这些文件表示z
轴。在 - 选项
display=True
在命令行输出中打印一个漂亮的表。在 - 选项
x_sort_order
和y_sort_order
列出了将用于沿该轴对输出进行排序的列表。在
例如:下面的代码在x
轴上组合了person和mood,并对该轴使用了非常特殊的排序顺序。
数字在y
轴上,动词在z
轴上;只考虑现在时形式。
输出在终端中打印得很好;z
轴分布在三个文件中。在
pd.read_file(
"latin_verbs.csv",
x = ["Person", "Mood"],
y = ["Number"],
z = ["Verb"],
filtered_parameters = {"Tense": "PRS"}
)
pd.print_paradigms(
name="example_output",
display=True,
single_file=False,
x_sort_order=["1IND", "2IND", "3IND", "3SUBJ", "2SUBJ", "1SUBJ"]
)
portaːre | 1IND | 2IND | 3IND | 3SUBJ | 2SUBJ | 1SUBJ |
---|---|---|---|---|---|---|
SG | portoː | portaːs | portat | portet | porteːs | portem |
PL | portaːmus | portaːtis | portant | portent | porteːtis | porteːmus |
terːeːre | 1IND | 2IND | 3IND | 3SUBJ | 2SUBJ | 1SUBJ |
---|---|---|---|---|---|---|
SG | terːeoː | terːeːs | terːet | terːeat | terːeaːs | terːream |
PL | terːeːmus | terːeːtis | terːent | terːeant | terːeaːtis | terːeaːmus |
petere | 1IND | 2IND | 3IND | 3SUBJ | 2SUBJ | 1SUBJ |
---|---|---|---|---|---|---|
SG | petoː | petis | petit | petat | petaːs | petam |
PL | petimus | petitis | petunt | petant | petaːtis | petaːmus |
print_paradigms
如果您在自己的应用程序中使用pyradigms
,那么您可能已经准备好了一个三维字典,而不是用pyradigms
来构造它。
在这种情况下,可以将参数tables
传递给print_paradigms()
;其余的工作原理相同。
如果没有传递tables
参数,则使用read_file()
创建的字典。
以下面的伯尔尼德语动词形式词典为例。
它有三个维度,第一个维度是动词的意义,第二个维度是数字,第三个维度是人。在
bernese_verbs = {"to go": {
"SG": {"1": "kɑː",
"2": "kɛjʃ",
"3": "kɛjtː"},
"PL": {"1": "kœː",
"2":"kœːtː",
"3":"kœː"}
}, "to say": {
"SG": {"1": "sækə",
"2": "sɛjʃ",
"3": "sɛjtː"},
"PL": {"1": "sækə",
"2":"sækətː",
"3":"sækə"}
}
}
使用print_paradigms(bernese_verbs)
,生成一个包含以下内容的.csv
文件:
to go | 1 | 2 | 3 |
---|---|---|---|
SG | kɑː | kɛjʃ | kɛjtː |
PL | kœː | kœːtː | kœː |
to say | 1 | 2 | 3 |
---|---|---|---|
SG | sækə | sɛjʃ | sɛjtː |
PL | sækə | sækətː | sækə |
在.csv
文件中,三维散列的第一层用z
维表示,即垂直堆叠的范式表,第二层用单个表的y
轴表示,第三层用x
轴表示。在
- 项目
标签: