{
"cells": [
{
"cell_type": "markdown",
"id": "31212105-ce5d-4387-a366-d922d77ab77b",
"metadata": {},
"source": [
"# Qualifications\n",
"\n",
"Qualifications are used to modify and hence create new standard names:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "46e2b224-c2ba-41d7-9702-de765997aef0",
"metadata": {},
"outputs": [],
"source": [
"import ssnolib"
]
},
{
"cell_type": "markdown",
"id": "d40f3763-3066-4b12-9789-725af18294d5",
"metadata": {},
"source": [
"There are two type of Qualification classes:\n",
"- Qualification: Normal qualification adding a phrase to the standard name\n",
"- VectorQualification: Adding a phrase to a standard name which must be a vector!"
]
},
{
"cell_type": "markdown",
"id": "6799cc75-f13a-46c6-b28c-a0e8a2bd2032",
"metadata": {},
"source": [
"Let's start with a \"normal\" Qualification, like adding an information about the medium to a variable.\n",
"\n",
"Assume the scalar standard name \"density\". We would like to allow adding \"air\" or \"water\" to standard names but no other:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b1fc7155-afd6-46fd-aadd-8dc9873cc254",
"metadata": {},
"outputs": [],
"source": [
"medium = ssnolib.Qualification(\n",
" name=\"medium\",\n",
" description=[\"medium of a quantity@en\", \"Medium der Größe@en\"],\n",
" hasValidValues=[\"air\", \"water\"],\n",
" before=ssnolib.SSNO.AnyStandardName\n",
")"
]
},
{
"cell_type": "markdown",
"id": "8baf85be-8582-43b9-bbe1-dc91814473ce",
"metadata": {},
"source": [
"Add this qualification to the standard name table:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "20081058-7359-4276-8152-703c1e0b5edf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'[medium] standard_name'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt = ssnolib.StandardNameTable(standard_names=[ssnolib.ScalarStandardName(standard_name=\"density\", description=\"\", unit=\"kg/m^3\")])\n",
"snt.hasModifier = [medium,]\n",
"snt.get_qualification_rule_as_string()"
]
},
{
"cell_type": "markdown",
"id": "e681db5a-f9f6-4bf5-982f-47fb276ccbe2",
"metadata": {},
"source": [
"Let's **verify** the obvious case:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "10dfda68-5769-4a06-b4f1-91c4cb0d55c0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"density\")"
]
},
{
"cell_type": "markdown",
"id": "4c855299-d7f7-415e-b93d-a47fc6f4be65",
"metadata": {},
"source": [
"The prefix \"air\" should be possible, too:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "32ce1672-14e8-49e1-baa2-6cd8d0342748",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"air_density\")"
]
},
{
"cell_type": "markdown",
"id": "9753c9e3-8bfd-4633-b4ac-821aed380ac0",
"metadata": {},
"source": [
"\"oil\" is an invalid medium:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ada19da4-24f9-4b6f-b817-e6a2c2004df9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"oil_density\")"
]
},
{
"cell_type": "markdown",
"id": "3d857681-4909-459a-90f3-1cbbb2d22888",
"metadata": {},
"source": [
"Now towards vector qualifications: Let's add \"velocity\" as a vector quantity to the core list of standard names:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0ed74f10-8e2a-4267-b516-fda9369057b8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"VectorStandardName(id=_:N8cb1dab23cce46b7adaebd549dce2cca, standardName=velocity, unit=http://qudt.org/vocab/unit/M-PER-SEC, description=A velocity vector quantity)"
],
"text/plain": [
"VectorStandardName(id=_:N8cb1dab23cce46b7adaebd549dce2cca, standardName=velocity, unit=http://qudt.org/vocab/unit/M-PER-SEC, description=A velocity vector quantity)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.add_new_standard_name(\n",
" ssnolib.VectorStandardName(\n",
" standard_name=\"velocity\",\n",
" description=\"A velocity vector quantity\",\n",
" unit=\"m/s\"\n",
" ),\n",
" verify=False\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "4df777fc-2902-48a4-824d-e8c66b7c8465",
"metadata": {},
"outputs": [],
"source": [
"component = ssnolib.VectorQualification(name=\"component\", description=\"component of a vector@en\", hasValidValues=[\"x\", \"y\", \"z\"],\n",
" before=ssnolib.SSNO.AnyStandardName)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "1cc4c17f-98fd-4246-aca3-0953aa0f4d33",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'[component] standard_name'"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.hasModifier = [component,]\n",
"snt.get_qualification_rule_as_string()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "48ce9f00-3e6b-46da-bcd9-56a32cbe48de",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"x_velocity\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "13b7bd60-6948-44ec-9655-a0e8b6be27df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"u_velocity\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "fdaa266d-d15e-4fa8-b62f-0d73e622344e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"snt.verify_name(\"velocity\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c089dc90-24cd-4e41-abd1-020062d96b4b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"@prefix dcterms: .\n",
"@prefix m4i: .\n",
"@prefix schema: .\n",
"@prefix ssno: .\n",
"\n",
"[] a ssno:VectorQualification ;\n",
" dcterms:description \"component of a vector\"@en ;\n",
" ssno:before ssno:AnyStandardName ;\n",
" ssno:hasValidValues [ a m4i:TextVariable ;\n",
" m4i:hasStringValue \"y\" ;\n",
" m4i:hasVariableDescription \"No description available.\" ],\n",
" [ a m4i:TextVariable ;\n",
" m4i:hasStringValue \"z\" ;\n",
" m4i:hasVariableDescription \"No description available.\" ],\n",
" [ a m4i:TextVariable ;\n",
" m4i:hasStringValue \"x\" ;\n",
" m4i:hasVariableDescription \"No description available.\" ] ;\n",
" schema:name \"component\" .\n",
"\n",
"\n"
]
}
],
"source": [
"print(component.serialize(\"ttl\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d611d9f5-2121-4ed2-8fe5-c36c92a4c1c2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}